通过info可以查看当前服务器是slave. 然后通过info命令查看master_link_status,如果为up,表示同步完成.(在同步过程中,执行查询的时候还是会提示”Redis is loading the dataset in memory”,这属于正常情况.把数据从磁盘文件加载到内存中可能会消耗很长的一段时间.)
最后断开主从关系,在redis-cli命令行下执行slaveof no one提示OK,再通过info查看,该新服务器已经自己变成master了. 确保旧的服务器的服务已经停止服务. 上面没有配合说明业务代码对服务器的请求切换,但是我们在切换完服务之后肯定需要转移业务代码的请求吧.那么如何确定服务已经完全转移走了呢? 在旧服务器上通过netstat命令查看是否还有请求过来.
tcpdump -i em2 -vv -nn host 192.168.1.100 and port 6379
注意排除监控系统对该redis实例的请求. 如何判断 redis 已经同步完毕呢? 在命令行查看:
1
info master_link_status:up
则表示同步完成了. 日志文件也可以看:
1 2 3 4 5 6 7 8 9 10 11 12 13
[48864] 12 Jun 11:24:03.549 * The server is now ready to accept connections on port 6310 [48864] 12 Jun 11:31:52.936 * SLAVE OF 192.168.50.17:8004 enabled (user request) [48864] 12 Jun 11:31:53.467 * Connecting to MASTER 192.168.50.17:8004 [48864] 12 Jun 11:31:53.467 * MASTER SLAVE sync started [48864] 12 Jun 11:31:53.470 * Non blocking connect for SYNC fired the event. [48864] 12 Jun 11:31:53.470 * Master replied to PING, replication can continue... [48864] 12 Jun 11:31:53.470 * Partial resynchronization not possible (no cached master) [48864] 12 Jun 11:31:53.470 * Master does not support PSYNC or is in error state (reply: -ERR unknown command 'PSYNC') [48864] 12 Jun 11:31:53.470 * Retrying with SYNC... [48864] 12 Jun 11:32:13.085 * MASTER SLAVE sync: receiving 484322714 bytes from master [48864] 12 Jun 11:32:18.498 * MASTER SLAVE sync: Flushing old data [48864] 12 Jun 11:32:18.498 * MASTER SLAVE sync: Loading DB in memory [48864] 12 Jun 11:32:32.349 * MASTER SLAVE sync: Finished with succes