在slave上執(zhí)行slaveof到master上,遲遲未成功。
檢查master的redis進(jìn)程日志輸出如下:
-
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文件,確認(rèn)bgsave成功。
報錯也顯示為transfer error,大致判定為rdb文件在transfer到slave的時候報錯。
google了一下發(fā)現(xiàn)應(yīng)該是client-output-buffer-limit設(shè)置過小。
〇 client-output-buffer-limit 在文檔中指出,該參數(shù)用于限制client緩沖區(qū)的限制。
redis的client被分為三種類型:
normal、slave、pubsub。normal:正常的客戶端并包括MONITOR客戶端
slave:slave客戶端
pubsub:pub/sub客戶端
其設(shè)置方式為:
client-output-buffer-limit[class] [hard limit] [soft limit] [soft seconds]
[class]為client的類型。
[hard limit]為硬限制,即超過[hard limit]值的緩沖區(qū)客戶端會被強制中斷。
[soft limit] [soft seconds]為軟限制,即持續(xù)[soft seconds]時間內(nèi),超過[soft limit]的緩沖區(qū)客戶端會被強制中斷。
當(dāng)然,默認(rèn)情況下普通client不受限制(設(shè)置為0),因為如果以推送的方式(不詢問),在請求之后才接收到數(shù)據(jù),那么只有異步客戶端可能會創(chuàng)建一個請求數(shù)據(jù)的速度超過其讀取速度的情況。
而slave和pubsub client有一個默認(rèn)限制,因為他們以推送的方式接收數(shù)據(jù)。
此處將slave的hard limit設(shè)置為32G。
config set client-output-buffer-limit "normal 0 0 0 slave 34359738368 268435456 600 pubsub 33554432 8388608 60" 重新slaveof后,觀察info replication和主庫redis進(jìn)程日志,創(chuàng)建復(fù)制成功:
-
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
復(fù)制建立好后,將client-output-buffer-limit改為默認(rèn)值。
作者微信公眾號:
新聞標(biāo)題:【Redis】slaveof報錯Backgroundtransfererror
當(dāng)前地址:
http://weahome.cn/article/poscsp.html