redis主从同步错误处理

背景:  

       之前resis只有一台服务器(redis  master),现需要为其增加一台slave服务器(slave),做成一主一从

要求,不影响 master的正常情况下完成 .

1、配置slave:

      在slave的配置文件中,指定master即可

slaveof <masterip> 6379

2、启动slave后,查看slave和mater日志

salve:

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:

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修改内核变量

vi /etc/sysctl.conf
  vm.overcommit_memory=1
systctl -p

重启slave后,开始同步数据。

 master:

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:

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
原文地址:https://www.cnblogs.com/xzlive/p/11433909.html