標籤:receiving 設定檔 master 密碼 local
十二、Redis主從配置
tail /usr/local/redis/var/redis.log
3966] 18 Feb 15:02:58.330 * MASTER <-> SLAVE sync: receiving 192 bytes from master
[3966] 18 Feb 15:02:58.330 * MASTER <-> SLAVE sync: Flushing old data
[3966] 18 Feb 15:02:58.330 * MASTER <-> SLAVE sync: Loading DB in memory
[3966] 18 Feb 15:02:58.330 * MASTER <-> SLAVE sync: Finished with success
[3966] 18 Feb 15:03:03.344 - DB 0: 7 keys (0 volatile) in 8 slots HT.
[3966] 18 Feb 15:03:03.344 - 1 clients connected (0 slaves), 466840 bytes in use
[3966] 18 Feb 15:03:08.396 - DB 0: 7 keys (0 volatile) in 8 slots HT.
[3966] 18 Feb 15:03:08.397 - 1 clients connected (0 slaves), 466848 bytes in use
測試:
/usr/local/redis/bin/redis-cli -a szk 主
127.0.0.1:6379> set key1 szk
OK
127.0.0.1:6379> get key1
"szk"
/usr/local/redis/bin/redis-cli 從
127.0.0.1:6379> get key1
"szk"
OK
十三、Redis主從其他相關配置
slave-read-only yes #讓從唯讀
repl-ping-slave-period 10 #設定slave向master發起ping的頻率,每10s發起一次
repl-timeout 60 #設定slave ping不同master多少s後就逾時
repl-disable-tcp-nodelay no #是否開啟tcp_nodeay,開啟後將會使用更少的頻寬,但會有延遲,所以建議關閉
repl-backlog-size 1mb #同步隊列的長度,backuplog是master的一個緩衝區,主從斷開後,master會先把資料寫到緩衝區,slave再次串連會從緩衝區中同步資料
repl-backlog-ttl 3600 #主從斷開後,緩衝區的有效期間,預設1小時
slave-priority 100 #多個slave是可以設定優先權的,數值越小優先順序越高,應用於叢集中,支援slave切換為mster,優先順序最高的才會切換
min-slave-to-write 3 #和下面的一起使用,它的意思是master發現有超過3個slave的延遲高於10s,那麼master就會暫時停止寫操作。這兩個數值任何一個為0,則關閉該功能,預設第一數值是0
min-slaves-max-log 10
Redis主從配置