1、repl-timeout
前兩篇[1]關于redis主從復制的文章解釋了一些因為slave replication buffer或者replication backlog參數的錯誤配置(或者默認參數值)導致主從復制中斷的現象。redis里面的repl-timeout參數值也太小也將會導致復制不成功。top redis headaches for devops – replication timeout詳細解釋了因為復制超時導致復制中斷的現象。
redis配置文件中對repl-timeout的參數解釋如下:
# 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).
三種情況認為復制超時:
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發起重新建立主從連接的請求。
對于內存數據集比較大的系統,可以增大repl-timeout參數。
2、slave ping period
另外,需要注意,redis slave會定期從master發送ping命令,時間間隔repl-ping-slave-period指定。
因而,設置參數時, 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.
原創文章,作者:s19930811,如若轉載,請注明出處:http://www.www58058.com/2482