【安裝redis單實(shí)例實(shí)戰(zhàn)】
目前創(chuàng)新互聯(lián)公司已為近1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管、服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、定南網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
yum -y install gcc gcc-c++ #安裝編譯工具 cd /opt wget -c http://download.redis.io/releases/redis-3.0.5.tar.gz #下載包 tar xf redis-3.0.5.tar.gz #解壓 cd redis-3.0.5 make MALLOC=libc #編譯 make PREFIX=/usr/local/redis install #安裝 echo 'PATH=/usr/local/redis/bin:$PATH' >> /etc/profile #配置環(huán)境變量 source /etc/profile #或 . /etc/profile mkdir /usr/local/redis/conf #創(chuàng)建目錄 cp /opt/redis-3.0.5/redis.conf /usr/local/redis/conf/ #拷貝配置文件 sed -i "46s#/var/run/redis.pid#/usr/local/redis/conf/redis.pid#" /usr/local/redis/conf/redis.conf sed -i "192s#./#/usr/local/redis/conf/#" /usr/local/redis/conf/redis.conf sed -i 509s/no/yes/ /usr/local/redis/conf/redis.conf nohup redis-server /usr/local/redis/conf/redis.conf &> /dev/null & echo vm.overcommit_memory = 1 >> /etc/sysctl.conf sysctl -p lsof -i:6379 #查看端口有沒有起來 #redis-cli shutdown
【redis多實(shí)例實(shí)戰(zhàn)】
mkdir -p /usr/local/redis/6380/conf cp /usr/local/redis/conf/redis.conf /usr/local/redis/6380/conf/ sed -i 50s/6379/6380/ /usr/local/redis/6380/conf/redis.conf sed -i "46s#/var/run/redis.pid#/usr/local/redis/6380/conf/redis.pid#" /usr/local/redis/6380/conf/redis.conf sed -i "192s#./#/usr/local/redis/6380/conf/#" /usr/local/redis/6380/conf/redis.conf sed -i 509s/no/yes/ /usr/local/redis/6380/conf/redis.conf redis-server /usr/local/redis/6380/conf/redis.conf & mkdir -p /usr/local/redis/6381/conf cp /usr/local/redis/conf/redis.conf /usr/local/redis/6381/conf/ sed -i 50s/6379/6381/ /usr/local/redis/6381/conf/redis.conf sed -i "46s#/var/run/redis.pid#/usr/local/redis/6381/conf/redis.pid#" /usr/local/redis/6381/conf/redis.conf sed -i "192s#./#/usr/local/redis/6381/conf/#" /usr/local/redis/6381/conf/redis.conf #更改rdb文件存放目錄 sed -i 509s/no/yes/ /usr/local/redis/6381/conf/redis.conf #開啟aof日志文件 redis-server /usr/local/redis/6380/conf/redis.conf & # redis-cli -p 6381 > set a b > save > quit # ls /usr/local/redis/6381/conf #查看生成的dump.rdb文件 # redis-cli -p 6381 shutdown #關(guān)閉服務(wù)
【主從同步實(shí)戰(zhàn)】(主跟從可以在相同服務(wù)器,同服務(wù)器的時(shí)候必須至少要有兩個(gè)實(shí)例)
主:6379 從:6380 -》同一臺(tái)服務(wù)器,不同實(shí)例
1)從修改配置文件
sed -i "210a slaveof 192.168.1.103 6379" /usr/local/redis/6380/conf/redis.conf #此處不寫主的IP寫主的域名也可以 sed -i "217a masterauth wsyht" /usr/local/redis/6380/conf/redis.conf #master沒密碼可以不做這一步 redis-cli -p 6380 shutdown redis-server /usr/local/redis/6380/conf/redis.conf &
2)建庫驗(yàn)證查看,主操作
[root@localhost conf]# redis-cli -p 6379 -a wsyht 127.0.0.1:6379> set name wsyht OK 127.0.0.1:6379> get name "wsyht" 127.0.0.1:6379> select 1 OK 127.0.0.1:6379[1]> set name peter OK 127.0.0.1:6379[1]>info #查看所有信息包括同步 127.0.0.1:6380>info replication #只查看他的同步信息
3)從查看庫和狀態(tài)信息,monitor監(jiān)控每十秒拼一次
[root@localhost ~]# redis-cli -p 6380 127.0.0.1:6380> monitor OK 1446980247.929617 [0 192.168.1.103:6379] "PING" 1446980257.981266 [0 192.168.1.103:6379] "PING" 1446980268.034426 [0 192.168.1.103:6379] "PING" 1446980273.602672 [0 192.168.1.103:6379] "SELECT" "0" 1446980273.602687 [0 192.168.1.103:6379] "set" "name" "wsyht" 1446980278.089068 [0 192.168.1.103:6379] "PING" 1446980288.140236 [0 192.168.1.103:6379] "PING" 1446980294.722701 [0 192.168.1.103:6379] "SELECT" "1" 1446980294.722721 [1 192.168.1.103:6379] "set" "name" "peter" 1446980298.190898 [1 192.168.1.103:6379] "PING" ^C [root@localhost ~]# redis-cli -p 6380 127.0.0.1:6380> get name #查看同步過來的庫 "wsyht" 127.0.0.1:6380>info #查看所有信息包括同步 127.0.0.1:6380>info replication #只查看他的同步信息