【Redis】slaveof报错Backgroundtransfererror
在slave上执行slaveof到master上,迟迟未成功。
检查master的redis进程日志输出如下:
-
427:S 03 May 20:32:07.320 * Slave 10.9.95.71:6379 asks for synchronization
-
427:S 03 May 20:32:07.320 * Unable to partial resync with slave $slaveip:6379 for lack of backlog (Slave request was: 5974421660).
-
427:S 03 May 20:32:07.320 * Delay next BGSAVE for SYNC
-
427:S 03 May 20:32:13.350 * Starting BGSAVE for SYNC with target: slaves sockets
-
427:S 03 May 20:32:14.333 * Background RDB transfer started by pid 478
-
427:S 03 May 20:35:04.136 # Connection with slave $slaveip lost.
-
427:S 03 May 20:35:04.912 # Background transfer error
手动通过stat检查了一下rdb文件,确认bgsave成功。
报错也显示为transfer error,大致判定为rdb文件在transfer到slave的时候报错。
google了一下发现应该是client-output-buffer-limit设置过小。
〇 client-output-buffer-limit 在文档中指出,该参数用于限制client缓冲区的限制。
redis的client被分为三种类型:
normal、slave、pubsub。normal:正常的客户端并包括MONITOR客户端
slave:slave客户端
pubsub:pub/sub客户端
其设置方式为:
client-output-buffer-limit[class] [hard limit] [soft limit] [soft seconds]
[class]为client的类型。
[hard limit]为硬限制,即超过[hard limit]值的缓冲区客户端会被强制中断。
[soft limit] [soft seconds]为软限制,即持续[soft seconds]时间内,超过[soft limit]的缓冲区客户端会被强制中断。
当然,默认情况下普通client不受限制(设置为0),因为如果以推送的方式(不询问),在请求之后才接收到数据,那么只有异步客户端可能会创建一个请求数据的速度超过其读取速度的情况。
而slave和pubsub client有一个默认限制,因为他们以推送的方式接收数据。
此处将slave的hard limit设置为32G。
config set client-output-buffer-limit "normal 0 0 0 slave 34359738368 268435456 600 pubsub 33554432 8388608 60" 重新slaveof后,观察info replication和主库redis进程日志,创建复制成功:
-
427:S 03 May 21:41:16.962 * Slave $slaveip:6379 asks for synchronization
-
427:S 03 May 21:41:16.984 * Full resync requested by slave $slaveip:6379
-
427:S 03 May 21:41:16.984 * Delay next BGSAVE for SYNC
-
427:S 03 May 21:41:22.712 * Starting BGSAVE for SYNC with target: slaves sockets
-
427:S 03 May 21:41:23.679 * Background RDB transfer started by pid 568
-
568:C 03 May 21:51:14.107 * RDB: xxxxx MB of memory used by copy-on-write
-
427:S 03 May 21:51:15.012 * Background RDB transfer terminated with success
-
427:S 03 May 21:51:15.012 # Slave $slaveip:6379 correctly received the streamed RDB file.
-
427:S 03 May 21:51:15.012 * Streamed RDB transfer with slave $slaveip:6379 succeeded (socket). Waiting for REPLCONF ACK from slave to enable streaming
复制建立好后,将client-output-buffer-limit改为默认值。
作者微信公众号:
文章名称:【Redis】slaveof报错Backgroundtransfererror
本文路径:
http://dzwzjz.com/article/poscsp.html