【Redis】redis-cluster到redis-cluster的快速複製
現有個需求是redis-cluster到redis-cluster的快速遷移,並且遷移過後兩套redis-cluster都要獨立使用無依賴
方法一:使用前面redis遷移中的線上遷移工具
redis-migration(劣勢:不支援redis4.0) redis-migration-tools(劣勢:不支援redis4.0) redis-sync-manage:redis-port封裝版本((劣勢:不支援密碼模式)) 等工具
剛好線上是redis4.0,有的無的因為各種原因無法使用上面的各種工具
方法二:
參考:【Redis】redis遷移資料到redis-cluster 劣勢:步驟相對麻煩,檔redis rdb檔案過大時,遷移時間過長
方法三:本文需要詳細說的一種辦法(假設叢集是三個節點)
1.新的叢集(75,74,72)當作slave加入原叢集中,等待同步資料 2.等待資料同步完畢將其剔除叢集 3.關閉同步完的三臺節點 4.編輯nodes.conf檔案 原nodes.conf應該是這樣 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 每臺機器的master前面分別加上myself資訊 5.重啟75,74,72三臺的redis叢集並校驗 可將2-5步寫成指令碼自動化完成,分鐘級就可以複製出一套叢集!
補充:還有可能是機房遷移,那樣只需要一套叢集可用就好了,這個需求更簡單!
直接關掉原機房的redis服務,新機房的redis提升為master,修改域名解析就好了,切換過程如下
6379 down機後,6380會被提升為master,6379重啟後會變成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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2213770/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- redis-cluster主從搭建Redis
- 【Redis】 redis-cluster刪除指定的keyRedis
- 【Redis】redis遷移資料到redis-clusterRedis
- 【Redis】redis-cluster 安裝遇到的問題Redis
- SpringBoot 2.0 如何使用Redis-ClusterSpring BootRedis
- 【Redis】redis-cluster需要注意的幾個地方Redis
- Redis-cluster叢集搭建部署Redis
- kubernetes生產實踐之redis-clusterRedis
- redis-cluster叢集安裝(基於redis-3.2.10)Redis
- 在滴滴雲上搭建 Redis-Cluster 叢集Redis
- 比Redis-cluster還好的redis分散式叢集(twemproxy代理)Redis分散式
- Redis 架構演變與 Redis-cluster 群集讀寫方案Redis架構
- Kubernetes(k8s)部署redis-cluster叢集K8SRedis
- Redis-cluster命令 cluster info 引數資訊解釋Redis
- 知道 Redis-Cluster 麼?說說其中可能不可用的情況Redis
- Redis系列(四):Redis的複製機制(主從複製)Redis
- redis系列--主從複製以及redis複製演進Redis
- Redis的資料複製Redis
- redis當中的複製Redis
- Redis主從複製Redis
- redis之主從複製Redis
- Redis - 主從複製Redis
- Redis:主從複製Redis
- redis的主從複製的原理Redis
- 【Azure Developer】一個複製Redis Key到另一個Redis服務的工具(redis_copy_net8)DeveloperRedis
- redis(14)主從複製Redis
- Redis 主從複製原理Redis
- Redis複製流程:圖解Redis圖解
- Redis 主從複製(Replication)Redis
- redis系列:主從複製Redis
- redis學習十四、Redis主從複製Redis
- redis建立主從複製的過程Redis
- 技巧:Sketch 快速複製圖形的方法
- Redis複製過程詳解Redis
- redis 主從複製實現Redis
- Redis主從複製原理剖析Redis
- Redis 主從複製與哨兵Redis
- 分散式Redis主備複製分散式Redis