當網絡抖動時Redis 會發生主從全量同步,若是數據量大的話,加上傳輸時間,Reload時間會讓業務長時間異常,能夠從如下參數上進行調整,有效防止網絡閃斷帶來的風險。redis
1.repl-timeout服務器
redis裏面的repl-timeout參數值過小也將會致使複製不成功.網絡
redis配置文件中對repl-timeout的參數解釋以下:this
# The following option sets the replication timeout for:
#
# 1) Bulk transfer I/O during SYNC, from the point of view of slave.
# 2) Master timeout from the point of view of slaves (data, pings).
# 3) Slave timeout from the point of view of masters (REPLCONF ACK pings).
三種狀況認爲複製超時:spa
1)slave角度,若是在repl-timeout時間內沒有收到master SYNC傳輸的rdb snapshot數據,
2)slave角度,在repl-timeout沒有收到master發送的數據包或者ping。
3)master角度,在repl-timeout時間沒有收到REPCONF ACK確認信息。
當redis檢測到repl-timeout超時(默認值60s),將會關閉主從之間的鏈接,redis slave發起從新創建主從鏈接的請求。code
對於內存數據集比較大的系統,能夠增大repl-timeout參數。server
2.slave ping period內存
redis slave會按期從master發送ping命令,時間間隔repl-ping-slave-period指定。ci
於是,設置參數時, repl-timeout > repl-ping-slave-period。同步
# Slaves send PINGs to server in a predefined interval. The default value is 10 seconds.
# repl-ping-slave-period 10
# It is important to make sure that this value is greater than the values pecified for repl-ping-slave-period otherwise a timeout will be detected every time there is low traffic between the master and the slave.
3.repl-backlog-size
當主服務器進行命令傳播的時候,maser不只將全部的數據更新命令發送到全部slave的replication buffer,還會寫入replication backlog。當斷開的slave從新鏈接上master的時候,slave將會發送psync命令(包含複製的偏移量offset),請求partial resync。若是請求的offset不存在,那麼執行全量的sync操做,至關於從新創建主從複製。
爲了不網絡不穩定形成的全量同步.
修改參數以下:
config set repl-timeout 240config set repl-backlog-size 524288000