您好,登錄后才能下訂單哦!
由于之前的redis cluster物理硬件性能不足。決定升級到更好的服務器上。
考慮到redis是核心生產數據庫,決定在線遷移,遷移過程,不中斷服務。
下面是測試環境的完成遷移步驟:
1. 原環境(測試環境,沒有創建slave)
10.21.14.251:7000 10.21.14.251:7001 10.21.14.251:7002
2. 在新主機上,啟動三個redis實例
10.21.10.120:7000 10.21.10.120:7001 10.21.10.120:7002
3. 將三個redis,都添加到集群中. 命令格式redis-trib.rb add-node <新增節點名> < 原集群節點名>
./redis-trib.rb add-node 10.21.10.120:7000 10.21.14.251:7000 ./redis-trib.rb add-node 10.21.10.120:7001 10.21.14.251:7000 ./redis-trib.rb add-node 10.21.10.120:7002 10.21.14.251:7000
4. 確認添加成功之后,開始reshard slot
./redis-trib.rb reshard 10.21.10.120:7000
5. 遇到點問題,由于網絡超時等原因,導致resharding中斷。然后出現兩邊都有slot的情況,需要通過fix的方式來修復
[redis@ip-10-21-14-251 redis]$ ./redis-trib.rb reshard 10.21.10.120:7000 >>> Performing Cluster Check (using node 10.21.10.120:7000) M: 4422ab38377fa8828e0f7884570b3b482a66496b 10.21.10.120:7000 slots:5026-5460 (435 slots) master 0 additional replica(s) M: 5b38e63a1091baa3a871a52275489a2aa1d28bfb 10.21.10.120:7002 slots:894-3397 (2504 slots) master 0 additional replica(s) M: bb1572074d41254e5b4d5aae5c52e54f5129d6d5 10.21.14.251:7001 slots:3398-4999,5461-15922 (12064 slots) master 0 additional replica(s) M: 396a7fbd2ec61752f9e848a1d8cc7b405aef0356 10.21.14.251:7000 slots: (0 slots) master 0 additional replica(s) M: 9f215e7e4b511f3d2bbf5d734731899b71a62a3b 10.21.10.120:7001 slots:0-893,5000-5025,15923-15948 (946 slots) master 0 additional replica(s) M: 0c9b383f65ae4fefc5e02617fb76a845d7510a53 10.21.14.251:7002 slots:15949-16383 (435 slots) master 0 additional replica(s) [OK] All nodes agree about slots configuration. >>> Check for open slots... [WARNING] Node 10.21.10.120:7002 has slots in importing state (3398). [WARNING] Node 10.21.14.251:7001 has slots in migrating state (3398). [WARNING] The following slots are open: 3398 >>> Check slots coverage... [OK] All 16384 slots covered. *** Please fix your cluster problems before resharding <<<<<<<<<<<<<<<<<<<<<
6. 可以使用下面命令進行集群檢查
./redis-trib.rb check 10.21.10.120:7000
7. 執行下面命令進行修復,然后就可以繼續reshard slot了
./redis-trib.rb fix 10.21.10.120:7000
8. 全部slot遷移完成
$ ./redis-trib.rb check 10.21.10.120:7000 >>> Performing Cluster Check (using node 10.21.10.120:7000) M: 4422ab38377fa8828e0f7884570b3b482a66496b 10.21.10.120:7000 slots:3399-4999,5026-7332 (3908 slots) master 0 additional replica(s) M: 5b38e63a1091baa3a871a52275489a2aa1d28bfb 10.21.10.120:7002 slots:894-3398,7333-15332,15949-16383 (10940 slots) master 0 additional replica(s) M: bb1572074d41254e5b4d5aae5c52e54f5129d6d5 10.21.14.251:7001 slots: (0 slots) master 0 additional replica(s) M: 396a7fbd2ec61752f9e848a1d8cc7b405aef0356 10.21.14.251:7000 slots: (0 slots) master 0 additional replica(s) M: 9f215e7e4b511f3d2bbf5d734731899b71a62a3b 10.21.10.120:7001 slots:0-893,5000-5025,15333-15948 (1536 slots) master 0 additional replica(s) M: 0c9b383f65ae4fefc5e02617fb76a845d7510a53 10.21.14.251:7002 slots: (0 slots) master 0 additional replica(s) [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
確認一下狀態
[redis@ip-10-21-14-251 redis]$ ./redis-cli -p 7000 cluster nodes bb1572074d41254e5b4d5aae5c52e54f5129d6d5 10.21.14.251:7001 master - 0 1509611814919 6 connected 9f215e7e4b511f3d2bbf5d734731899b71a62a3b 10.21.10.120:7001 master - 0 1509611811917 14 connected 0-893 5000-5025 15333-15948 5b38e63a1091baa3a871a52275489a2aa1d28bfb 10.21.10.120:7002 master - 0 1509611815923 13 connected 894-3398 7333-15332 15949-16383 396a7fbd2ec61752f9e848a1d8cc7b405aef0356 10.21.14.251:7000 myself,master - 0 0 1 connected 4422ab38377fa8828e0f7884570b3b482a66496b 10.21.10.120:7000 master - 0 1509611813919 12 connected 3399-4999 5026-7332 0c9b383f65ae4fefc5e02617fb76a845d7510a53 10.21.14.251:7002 master - 0 1509611812917 3 connected
9. 確認狀態OK的話,開始刪除節點
./redis-trib.rb del-node 10.21.14.251:7000 396a7fbd2ec61752f9e848a1d8cc7b405aef0356 ./redis-trib.rb del-node 10.21.14.251:7001 bb1572074d41254e5b4d5aae5c52e54f5129d6d5 ./redis-trib.rb del-node 10.21.14.251:7002 0c9b383f65ae4fefc5e02617fb76a845d7510a53
10. 干掉10.21.14.251:7002成功,
[redis@ip-10-21-14-251 redis]$ ./redis-trib.rb del-node 10.21.14.251:7002 0c9b383f65ae4fefc5e02617fb76a845d7510a53 >>> Removing node 0c9b383f65ae4fefc5e02617fb76a845d7510a53 from cluster 10.21.14.251:7002 >>> Sending CLUSTER FORGET messages to the cluster... >>> SHUTDOWN the node. [envuser@ip-10-21-14-251 redis]$ ./redis-trib.rb check 10.21.10.120:7000 >>> Performing Cluster Check (using node 10.21.10.120:7000) M: 4422ab38377fa8828e0f7884570b3b482a66496b 10.21.10.120:7000 slots:3399-4999,5026-7332 (3908 slots) master 0 additional replica(s) M: 5b38e63a1091baa3a871a52275489a2aa1d28bfb 10.21.10.120:7002 slots:894-3398,7333-15332,15949-16383 (10940 slots) master 0 additional replica(s) M: bb1572074d41254e5b4d5aae5c52e54f5129d6d5 10.21.14.251:7001 slots: (0 slots) master 0 additional replica(s) M: 396a7fbd2ec61752f9e848a1d8cc7b405aef0356 10.21.14.251:7000 slots: (0 slots) master 0 additional replica(s) M: 9f215e7e4b511f3d2bbf5d734731899b71a62a3b 10.21.10.120:7001 slots:0-893,5000-5025,15333-15948 (1536 slots) master 0 additional replica(s) [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
狀態檢查
[redis@ip-10-21-14-251 redis]$ ./redis-cli -p 7000 cluster nodes bb1572074d41254e5b4d5aae5c52e54f5129d6d5 10.21.14.251:7001 master - 0 1509611900094 6 connected 9f215e7e4b511f3d2bbf5d734731899b71a62a3b 10.21.10.120:7001 master - 0 1509611902100 14 connected 0-893 5000-5025 15333-15948 5b38e63a1091baa3a871a52275489a2aa1d28bfb 10.21.10.120:7002 master - 0 1509611901098 13 connected 894-3398 7333-15332 15949-16383 396a7fbd2ec61752f9e848a1d8cc7b405aef0356 10.21.14.251:7000 myself,master - 0 0 1 connected 4422ab38377fa8828e0f7884570b3b482a66496b 10.21.10.120:7000 master - 0 1509611899093 12 connected 3399-4999 5026-7332
根據上面步驟,刪除剩余節點即可。
經過測試,應用在遷移過程中,沒有受到任何影響。但是應用連接池的IP需要找機會增加10.21.10.120。
更多鏈接,請參考:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。