redis主从同步错误处理
背景:
之前resis只有一台服务器(redis master),现需要为其增加一台slave服务器(slave),做成一主一从
要求,不影响 master的正常情况下完成 .
1、配置slave:
在slave的配置文件中,指定master即可
1 | slaveof <masterip> 6379 |
2、启动slave后,查看slave和mater日志
salve:
1 2 3 4 5 6 7 8 9 10 | 4724:S 30 Aug 10:49:14.687 # Server started, Redis version 3.2.6 4724:S 30 Aug 10:49:14.690 * DB loaded from append only file: 0.002 seconds 4724:S 30 Aug 10:49:14.690 * The server is now ready to accept connections on port 6379 4724:S 30 Aug 10:49:14.690 * The server is now ready to accept connections at /tmp/redis_6379.sock 4724:S 30 Aug 10:49:14.690 * Connecting to MASTER 192.168.1.82:6379 4724:S 30 Aug 10:49:14.690 * MASTER <-> SLAVE sync started 4724:S 30 Aug 10:49:14.691 * Non blocking connect for SYNC fired the event . 4724:S 30 Aug 10:49:14.691 * Master replied to PING, replication can continue ... 4724:S 30 Aug 10:49:14.692 * Partial resynchronization not possible (no cached master) 4724:S 30 Aug 10:49:20.601 * Full resync from master: 471f183e04fda3047a7c4e03bf68ec03a31203c1:4198265 |
master:
1 2 3 4 5 6 | 1698:M 30 Aug 10:49:14.669 * Slave 192.100.10.88:6379 asks for synchronization 1698:M 30 Aug 10:49:14.669 * Full resync requested by slave 192.100.10.88:6379 1698:M 30 Aug 10:49:14.669 * Delay next BGSAVE for diskless SYNC 1698:M 30 Aug 10:49:20.576 * Starting BGSAVE for SYNC with target: slaves sockets 1698:M 30 Aug 10:49:20.577 # Can't save in background: fork: Cannot allocate memory 1698:M 30 Aug 10:49:20.577 # BGSAVE for replication failed |
数据未能同步到slave上。
master、slave修改内核变量
1 2 3 | vi /etc/sysctl.conf vm.overcommit_memory=1 systctl -p |
重启slave后,开始同步数据。
master:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 1698:M 30 Aug 10:50:43.525 * Slave 192.168.1.88:6379 asks for synchronization 1698:M 30 Aug 10:50:43.525 * Full resync requested by slave 192.100.10.88:6379 1698:M 30 Aug 10:50:43.525 * Delay next BGSAVE for diskless SYNC 1698:M 30 Aug 10:50:49.788 * Starting BGSAVE for SYNC with target: slaves sockets 1698:M 30 Aug 10:50:49.819 * Background RDB transfer started by pid 18925 18925:C 30 Aug 10:50:49.970 * RDB: 1 MB of memory used by copy- on -write 1698:M 30 Aug 10:50:50.020 * Background RDB transfer terminated with success 1698:M 30 Aug 10:50:50.020 # Slave 192.168.1.88:6379 correctly received the streamed RDB file. 1698:M 30 Aug 10:50:50.020 * Streamed RDB transfer with slave 192.100.10.88:6379 succeeded (socket). Waiting for REPLCONF ACK from slave to enabl e streaming 1698:M 30 Aug 10:50:50.557 * Synchronization with slave 192.100.10.88:6379 succeeded 1698:M 30 Aug 11:01:19.481 * Background append only file rewriting started by pid 31942 1698:M 30 Aug 11:01:19.581 * AOF rewrite child asks to stop sending diffs. 31942:C 30 Aug 11:01:19.581 * Parent agreed to stop sending diffs. Finalizing AOF... 31942:C 30 Aug 11:01:19.581 * Concatenating 0.00 MB of AOF diff received from parent. 31942:C 30 Aug 11:01:19.592 * SYNC append only file rewrite performed 31942:C 30 Aug 11:01:19.598 * AOF rewrite: 0 MB of memory used by copy- on -write 1698:M 30 Aug 11:01:19.688 * Background AOF rewrite terminated with success 1698:M 30 Aug 11:01:19.688 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB) 1698:M 30 Aug 11:01:19.688 * Background AOF rewrite finished successfully |
slave:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 4849:S 30 Aug 10:50:43.536 # Server started, Redis version 3.2.6 4849:S 30 Aug 10:50:43.537 * DB loaded from append only file: 0.000 seconds 4849:S 30 Aug 10:50:43.537 * The server is now ready to accept connections on port 6379 4849:S 30 Aug 10:50:43.537 * The server is now ready to accept connections at /tmp/redis_6379.sock 4849:S 30 Aug 10:50:43.537 * Connecting to MASTER 192.168.1.82:6379 4849:S 30 Aug 10:50:43.538 * MASTER <-> SLAVE sync started 4849:S 30 Aug 10:50:43.538 * Non blocking connect for SYNC fired the event . 4849:S 30 Aug 10:50:43.539 * Master replied to PING, replication can continue ... 4849:S 30 Aug 10:50:43.540 * Partial resynchronization not possible (no cached master) 4849:S 30 Aug 10:50:49.801 * Full resync from master: 471f183e04fda3047a7c4e03bf68ec03a31203c1:4349163 4849:S 30 Aug 10:50:49.845 * MASTER <-> SLAVE sync: receiving streamed RDB from master 4849:S 30 Aug 10:50:49.977 * MASTER <-> SLAVE sync: Flushing old data 4849:S 30 Aug 10:50:49.977 * MASTER <-> SLAVE sync: Loading DB in memory 4849:S 30 Aug 10:50:50.056 * MASTER <-> SLAVE sync: Finished with success 4849:S 30 Aug 10:50:50.062 * Background append only file rewriting started by pid 4900 4849:S 30 Aug 10:50:50.247 * AOF rewrite child asks to stop sending diffs. 4900:C 30 Aug 10:50:50.247 * Parent agreed to stop sending diffs. Finalizing AOF... 4900:C 30 Aug 10:50:50.247 * Concatenating 0.00 MB of AOF diff received from parent. 4900:C 30 Aug 10:50:50.248 * SYNC append only file rewrite performed 4900:C 30 Aug 10:50:50.250 * AOF rewrite: 0 MB of memory used by copy- on -write 4849:S 30 Aug 10:50:50.268 * Background AOF rewrite terminated with success 4849:S 30 Aug 10:50:50.268 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB) 4849:S 30 Aug 10:50:50.268 * Background AOF rewrite finished successfully |
分类:
redis相关
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端