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.178linux.com/2482