現(xiàn)有個(gè)需求是redis-cluster到redis-cluster的快速遷移,并且遷移過(guò)后兩套redis-cluster都要獨(dú)立使用無(wú)依賴
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到諸暨網(wǎng)站設(shè)計(jì)與諸暨網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)制作、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、主機(jī)域名、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋諸暨地區(qū)。
方法一:使用前面redis遷移中的在線遷移工具
redis-migration(劣勢(shì):不支持redis4.0) redis-migration-tools(劣勢(shì):不支持redis4.0) redis-sync-manage:redis-port封裝版本((劣勢(shì):不支持密碼模式)) 等工具
剛好線上是redis4.0,有的無(wú)的因?yàn)楦鞣N原因無(wú)法使用上面的各種工具
方法二:
參考:【Redis】redis遷移數(shù)據(jù)到redis-cluster 劣勢(shì):步驟相對(duì)麻煩,檔redis rdb文件過(guò)大時(shí),遷移時(shí)間過(guò)長(zhǎng)
方法三:本文需要詳細(xì)說(shuō)的一種辦法(假設(shè)集群是三個(gè)節(jié)點(diǎn))
1.新的集群(75,74,72)當(dāng)作slave加入原集群中,等待同步數(shù)據(jù) 2.等待數(shù)據(jù)同步完畢將其剔除集群 3.關(guān)閉同步完的三臺(tái)節(jié)點(diǎn) 4.編輯nodes.conf文件 原nodes.conf應(yīng)該是這樣 4ce6e03ba48336569efcc7bbaab6edb538cb1a90 172.23.3.74:6379@16379 slave a7f923aaee624acf672f8704ffb4b27b48a56352 0 1536238939051 19 connected aa8cf0b64f91c77846862909f9cec0c20ea54c1e 172.23.3.72:6379@16379 slave f2d9ac982c1d621850638a474ed4b8ffc5063d28 0 1536238941056 18 connected 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 master - 0 1536238940000 17 connected 0-502 1753-5930 12175-12671 f2d9ac982c1d621850638a474ed4b8ffc5063d28 172.31.47.95:6379@16379 master - 0 1536238939000 18 connected 503-1752 5931-6380 10925-11274 12672-16383 4dd59a9480a669f308a6819a3538e3340ed855cf 172.23.3.75:6379@16379 myself,slave 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 0 1536238940000 0 connected c4c7df1e21399984d909761441be80b178ef62a5 172.31.47.95:6380@16380 slave a7f923aaee624acf672f8704ffb4b27b48a56352 0 1536238941000 19 connected 9a6307f16ea34354e701c4dbe04ecb5c77021938 172.31.37.24:6380@16380 slave f2d9ac982c1d621850638a474ed4b8ffc5063d28 0 1536238942381 18 connected a7f923aaee624acf672f8704ffb4b27b48a56352 172.31.37.24:6379@16379 master - 0 1536238942061 19 connected 6381-10924 11275-12174 5dcc47b5477628895ce98e4c06f8e228a9c4fe5f 172.31.36.20:6380@16380 slave 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 0 1536238941373 17 connected vars currentEpoch 19 lastVoteEpoch 0 修改nodes.conf為 4ce6e03ba48336569efcc7bbaab6edb538cb1a90 172.23.3.74:6379@16379 master - 0 1536238942061 19 connected 6381-10924 11275-12174 aa8cf0b64f91c77846862909f9cec0c20ea54c1e 172.23.3.72:6379@16379 master - 0 1536238939000 18 connected 503-1752 5931-6380 10925-11274 12672-16383 4dd59a9480a669f308a6819a3538e3340ed855cf 172.23.3.75:6379@16379 myself,master - 0 1536238940000 17 connected 0-502 1753-5930 12175-12671 vars currentEpoch 19 lastVoteEpoch 0 以74為例,修改思路: 找到74的主37.24,替換74的slot信息為37.24的slot信息master - 0 1536238942061 19 connected 6381-10924 11275-12174 每臺(tái)機(jī)器的master前面分別加上myself信息 5.重啟75,74,72三臺(tái)的redis集群并校驗(yàn) 可將2-5步寫(xiě)成腳本自動(dòng)化完成,分鐘級(jí)就可以復(fù)制出一套集群!
補(bǔ)充:還有可能是機(jī)房遷移,那樣只需要一套集群可用就好了,這個(gè)需求更簡(jiǎn)單!
直接關(guān)掉原機(jī)房的redis服務(wù),新機(jī)房的redis提升為master,修改域名解析就好了,切換過(guò)程如下
6379 down機(jī)后,6380會(huì)被提升為master,6379重啟后會(huì)變成slave 加入到6380下 cluster info變化流程如下: 正常情況下 [root@ip-172-31-36-20 ~]# /usr/local/redis/bin/redis-cli -a XSX7sOfvFeLEyXod -h 127.0.0.1 -p 6379 -c cluster nodes f2d9ac982c1d621850638a474ed4b8ffc5063d28 172.31.47.95:6379@16379 master - 0 1536302125000 18 connected 804-1752 5931-6380 10925-11274 12672-16383 95c8168dab83f7156c1b0ba34686917972259517 172.31.36.20:6380@16380 slave 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 0 1536302126000 20 connected a7f923aaee624acf672f8704ffb4b27b48a56352 172.31.37.24:6379@16379 master - 0 1536302126573 21 connected 787-803 6381-10924 11275-12174 596012a79c3699692651fe47bc1a5a982762676a 172.31.47.95:6380@16380 slave f2d9ac982c1d621850638a474ed4b8ffc5063d28 0 1536302124569 21 connected dd4d8dbe8aee4ef0e31b8908297ca64092302bfd 172.31.37.24:6380@16380 slave a7f923aaee624acf672f8704ffb4b27b48a56352 0 1536302125000 21 connected 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 myself,master - 1536291530036 1536291530036 20 connected 0-786 1753-5930 12175-12671 down掉master 6379后 [root@ip-172-31-36-20 ~]# /usr/local/redis/bin/redis-cli -a XSX7sOfvFeLEyXod -h 172.31.37.24 -p 6379 -c cluster nodes|grep -i 36 a7f923aaee624acf672f8704ffb4b27b48a56352 172.31.37.24:6379@16379 myself,master - 1536291532036 1536291532036 21 connected 787-803 6381-10924 11275-12174 95c8168dab83f7156c1b0ba34686917972259517 172.31.36.20:6380@16380 slave 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 0 1536302197019 20 connected f2d9ac982c1d621850638a474ed4b8ffc5063d28 172.31.47.95:6379@16379 master - 0 1536302196019 18 connected 804-1752 5931-6380 10925-11274 12672-16383 596012a79c3699692651fe47bc1a5a982762676a 172.31.47.95:6380@16380 slave f2d9ac982c1d621850638a474ed4b8ffc5063d28 0 1536302198019 18 connected dd4d8dbe8aee4ef0e31b8908297ca64092302bfd 172.31.37.24:6380@16380 slave a7f923aaee624acf672f8704ffb4b27b48a56352 0 1536302195000 21 connected 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 master,fail - 1536302172919 1536302169019 20 disconnected 0-786 1753-5930 12175-12671 幾秒后選舉成功,6380提升 [root@ip-172-31-36-20 ~]# /usr/local/redis/bin/redis-cli -a XSX7sOfvFeLEyXod -h 172.31.37.24 -p 6379 -c cluster nodes|grep -i 36.20 95c8168dab83f7156c1b0ba34686917972259517 172.31.36.20:6380@16380 master - 0 1536302200019 22 connected 0-786 1753-5930 12175-12671 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 master,fail - 1536302172919 1536302169019 20 disconnected 重啟6379幾秒后重新加入集群 [root@ip-172-31-36-20 ~]# /usr/local/redis/bin/redis-cli -a XSX7sOfvFeLEyXod -h 172.31.37.24 -p 6379 -c cluster nodes|grep -i 36.20 95c8168dab83f7156c1b0ba34686917972259517 172.31.36.20:6380@16380 master - 0 1536302275023 22 connected 0-786 1753-5930 12175-12671 2d21ca5d5504b6e8bf283d4a3d0f390ab0258b90 172.31.36.20:6379@16379 slave 95c8168dab83f7156c1b0ba34686917972259517 0 1536302273023 22 connected