環(huán)境: master:192.168.11.31
公司主營(yíng)業(yè)務(wù):網(wǎng)站設(shè)計(jì)、做網(wǎng)站、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)推出云溪免費(fèi)做網(wǎng)站回饋大家。
slave : 192.168.11.20:6379 與 6380
模擬兩臺(tái)slave同時(shí)對(duì)一臺(tái)master進(jìn)行復(fù)制。
mater 配置:
daemonize yes
pidfile /var/run/redis.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
databases 16
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
requirepass Passw0rd
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
slave的配置,在slave上開(kāi)啟rdb與aof
slave 6379的配置:
daemonize yes
pidfile /var/run/redis_6379.pid
port 6379
dbfilename redis.db
dir /home/redis/6379
save 900 1
save 300 10
save 60 3000
rdbcompression yes
rdbchecksum yes
stop-writes-on-bgsave-error yes
appendonly yes
appendfilename appendonly.aof
#slave settings
slave-read-only yes
slaveof 192.168.11.31 6379
slave 6380配置:
daemonize yes
pidfile /var/run/redis_6380.pid
port 6380
dbfilename redis6380.db
dir /home/redis/6380
save 900 1
save 300 10
save 60 3000
rdbcompression yes
rdbchecksum yes
stop-writes-on-bgsave-error yes
appendonly yes
appendfilename appendonly6380.aof
#slave settings
slave-read-only yes
slaveof 192.168.11.31 6379
啟動(dòng)master:
[root@localhost redis]# redis-server redis.conf
啟動(dòng)slave:
[root@hdtest20 redis]# redis-server /etc/redis/6380.conf
[root@hdtest20 redis]# redis-server /etc/redis/6339.conf
登錄mater后輸入下面命令:
127.0.0.1:6379> auth Passw0rd
OK
127.0.0.1:6379> INFO replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.11.20,port=6380,state=online,offset=71,lag=1
slave1:ip=192.168.11.20,port=6379,state=online,offset=71,lag=1
master_repl_offset:71
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:70
上面基本上可以看出復(fù)制已經(jīng)完成,輸入兩個(gè)key測(cè)試一下:
127.0.0.1:6379> set testsite test.com
OK
登錄slave 6380端口的:
127.0.0.1:6380> keys *
1) "testsite"
127.0.0.1:6380> get testsite
"test.com"
注意:由于master沒(méi)有開(kāi)啟rdb跟aof,所以在master失效修復(fù)后不能馬上開(kāi)啟master,否則兩臺(tái)slave均失去所有數(shù)據(jù)。所以應(yīng)該把redis master的aof跟rdb也開(kāi)啟,并同時(shí)把repl-diskless-sync設(shè)置為yes