解決Redis/Codis Connection with master lost(複製超時)問題

Federico發表於2017-10-15

今天線上上環境中遇到了codis-server報警,按照常規處理流程進行處理,報錯步驟如下:

  1. 首先將codis-slave的rdb檔案移除,並重啟codis-slave
  2. 在codis-dashbord中將codis-slave移除問題codis group
  3. 將codis-slave重新加入codis group,並測試在codis-master中寫入資料,檢視codis-slave中能否正常讀取資料

沒想到在新加入codis group同步資料時發生以下報錯:

[13029] 15 Oct 13:56:29.063 # Client id=8443510 addr=10.24.193.69:30377 fd=6 name= age=187 idle=187 flags=S db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=16365 oll=3917 omem=100541448 events=rw cmd=psync scheduled to be closed ASAP for overcoming of output buffer limits. 
  [13029] 15 Oct 13:56:29.160 # Connection with slave 10.24.193.69:6379 lost. 
  [13029] 15 Oct 13:56:30.607 * Slave 10.24.193.69:6379 asks for synchronization 
  [13029] 15 Oct 13:56:30.607 * Full resync requested by slave 10.24.193.69:6379 
  [13029] 15 Oct 13:56:30.607 * Starting BGSAVE for SYNC with target: disk 
  [13029] 15 Oct 13:56:30.856 * Background saving started by pid 17765 
  [17765] 15 Oct 13:58:26.910 * DB saved on disk 
  [17765] 15 Oct 13:58:27.093 * RDB: 969 MB of memory used by copy-on-write 
  [13029] 15 Oct 13:58:27.492 * Background saving terminated with success

出現以上報錯的原因是codis/redis預設配置中repl-timeout的時間為60s,當複製資料的時間超過60s時,codis/redis master就會認為連線超時主動斷開連線,也就是Connection with master lost報錯。當然簡單的理解,複製的過程中肯定有兩個引數,一個是複製時長,另一個就是每秒/每分鐘複製資料佔用伺服器資源的大小client-output-buffer-limit引數就決定了客戶端輸出緩衝區記憶體使用量,所以我們可以通過調整這兩個引數來解決此次問題。

解決Redis/Codis同步超時問題

我們的codis部分配置檔案如下:

repl-timeout 60
client-output-buffer-limit slave 256mb 64mb 60

上面是master上的slave客戶端,預設緩衝區大小限制:當緩衝區使用超過256mb,master會盡快殺掉它;當緩衝區使用大於64mb,且小於256mb的soft limit值時,並持續時間達60秒,也會被Master儘快殺掉。

綜上所述

解決超時問題有兩種方式:

  • 修改超時時間長短repl-timeout 60
  • 修改緩衝區佔用內容大小限制client-output-buffer-limit

當資料同步完成後最好將配置修改為原配置,避免佔用伺服器資源過高引起其他問題

相關文章