人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

Redis Cluster集群收縮主從節(jié)點(diǎn)詳細(xì)教程

發(fā)布日期:2022-01-29 08:03 | 文章來源:源碼中國

Redis Cluster集群收縮主從節(jié)點(diǎn)

1.Cluster集群收縮概念

當(dāng)項(xiàng)目壓力承載力過高時(shí),需要增加節(jié)點(diǎn)來提高負(fù)載,當(dāng)項(xiàng)目壓力不是很大時(shí),也希望能夠?qū)⒓菏湛s下來,給其他項(xiàng)目使用,這就要用到集群收縮了

集群收縮操作和集群擴(kuò)容是一樣的,只需要把方向反過來即可。

擴(kuò)容的時(shí)候執(zhí)行一次命令就可以實(shí)現(xiàn)槽位遷移成功,而收縮的時(shí)候有幾個(gè)主節(jié)點(diǎn)就需要執(zhí)行多少次,比如除去要下線的節(jié)點(diǎn),還有3個(gè)主節(jié)點(diǎn),那么就需要執(zhí)行三次,填寫遷移出槽位的數(shù)量也需要除以3,每個(gè)節(jié)點(diǎn)也需要平均分配。

收縮的時(shí)候首先要填寫分出多少個(gè)槽位,然后填寫要分給誰,最后填寫從哪分出槽位,一般分多少個(gè)槽位,就需要看要下線的主機(jī)上有多少個(gè)槽位,然后除以集群主節(jié)點(diǎn)數(shù),使每一個(gè)主機(jī)點(diǎn)分到的槽位都是相同的,填寫要分配給誰的時(shí)候,第一次填寫第一個(gè)主節(jié)點(diǎn)的ID,第二次填寫第二個(gè)主節(jié)點(diǎn)的ID,最后填寫提供槽位的節(jié)點(diǎn)ID,就是下線節(jié)點(diǎn)的ID號。

集群收縮擴(kuò)容槽位的時(shí)候不會影響數(shù)據(jù)的使用。

集群收縮的源端就是要下線的主節(jié)點(diǎn),目標(biāo)端就是在線的主節(jié)點(diǎn)(分配給誰的節(jié)點(diǎn))。
咱們要清楚一點(diǎn),只有主節(jié)點(diǎn)是有槽位的,因此呢需要將主節(jié)點(diǎn)的槽位分配給其他主節(jié)點(diǎn),當(dāng)槽位清空后,這個(gè)主機(jī)節(jié)點(diǎn)就可以下線了。

收縮集群前后對比圖

集群收縮操作步驟:

? 1.執(zhí)行reshard命令將需要下線的主節(jié)點(diǎn)進(jìn)行槽位分散。

? 2.有幾個(gè)主節(jié)點(diǎn)就需要執(zhí)行幾次reshard命令,首先填寫要分出的槽位數(shù),然后填寫分給誰,最后填寫從哪里分。

? 3.當(dāng)槽位分散完成后,要下線的主節(jié)點(diǎn)沒有任何數(shù)據(jù)時(shí),將節(jié)點(diǎn)從集群中刪除。

集群信息

目前集群時(shí)四主四從共8個(gè)節(jié)點(diǎn),我們需要將集群改為三主三從,收縮出兩個(gè)節(jié)點(diǎn)給其他程序使用。

2.將6390主節(jié)點(diǎn)從集群中收縮

2.1.計(jì)算需要分給每一個(gè)節(jié)點(diǎn)的槽位數(shù)

可以看到6390節(jié)點(diǎn)上有4096個(gè)槽位,刪除要下線的6390節(jié)點(diǎn)后,我們還有3個(gè)主節(jié)點(diǎn),4096除3得到1365,分配槽位的時(shí)候給每個(gè)節(jié)點(diǎn)分配1365個(gè)槽位即可均勻。

2.2.分配1365個(gè)槽位給192.168.81.210的6380節(jié)點(diǎn)

我們需要將192.168.81.240的6390節(jié)點(diǎn)分出1365個(gè)槽位給192.168.81.210的6380節(jié)點(diǎn)。

只需要把What is the receiving node ID填寫成192.168.81.210的6380節(jié)點(diǎn)ID即可,指的是分配出來的槽位要給誰。

然后source node填寫192.168.81.240的6390節(jié)點(diǎn)的ID,這里指的是從哪個(gè)節(jié)點(diǎn)上分出1365個(gè)槽位,填寫ID后,回車后會提示還要從哪個(gè)節(jié)點(diǎn)上分配槽位,因?yàn)橹挥?390需要分出槽位,所以在這里填寫done,表示只有這個(gè)一個(gè)節(jié)點(diǎn)分出1365個(gè)槽位給其他節(jié)點(diǎn)。

[root@redis-1 /data/redis_cluster/redis-3.2.9/src]# ./redis-trib.rb reshard 192.168.81.210:6380
How many slots do you want to move (from 1 to 16384)? 1365				#分配出多少個(gè)槽位
What is the receiving node ID? 80e256579658eb256c5b710a3f82c439665794ba				#將槽位分給那個(gè)節(jié)點(diǎn)
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1:6bee155f136f40e28e1f60c8ddec3b158cd8f8e8					#從哪個(gè)節(jié)點(diǎn)分出槽位
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes			#輸入yes繼續(xù)

下面是收縮節(jié)點(diǎn)的過程截圖。

數(shù)據(jù)遷移過程。

槽位分出遷移成功。

2.3.分配1365個(gè)槽位給192.168.81.220的6380節(jié)點(diǎn)

[root@redis-1 /data/redis_cluster/redis-3.2.9/src]# ./redis-trib.rb reshard 192.168.81.210:6380
How many slots do you want to move (from 1 to 16384)? 1365				#分配出多少個(gè)槽位
What is the receiving node ID? 10dc7f3f9a753140a8494adbbe5a13d0026451a1				#將槽位分給那個(gè)節(jié)點(diǎn)
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1:6bee155f136f40e28e1f60c8ddec3b158cd8f8e8					#從哪個(gè)節(jié)點(diǎn)分出槽位
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes			#輸入yes繼續(xù)

收縮過程截圖展示。



2.4.分配1365個(gè)槽位給192.168.81.230的6380節(jié)點(diǎn)

[root@redis-1 /data/redis_cluster/redis-3.2.9/src]# ./redis-trib.rb reshard 192.168.81.210:6380
How many slots do you want to move (from 1 to 16384)? 1366				#分配出多少個(gè)槽位
What is the receiving node ID? a4381138fdc142f18881b7b6ca8ae5b0d02a3228				#將槽位分給那個(gè)節(jié)點(diǎn)
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1:6bee155f136f40e28e1f60c8ddec3b158cd8f8e8					#從哪個(gè)節(jié)點(diǎn)分出槽位
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes			#輸入yes繼續(xù)

收縮過程截圖展示。


當(dāng)最后一個(gè)節(jié)點(diǎn)遷移完數(shù)據(jù)后,6390主節(jié)點(diǎn)槽位數(shù)變?yōu)?。

2.5.查看當(dāng)前集群槽位分配

槽位及數(shù)據(jù)已經(jīng)從6390即將下線的主機(jī)遷移完畢,可以看下當(dāng)前集群三個(gè)主節(jié)點(diǎn)的槽位數(shù)。

可以非常清楚的看到,現(xiàn)在每個(gè)主節(jié)點(diǎn)的槽位數(shù)為5461。

如果覺得槽位重新分配后順序不太滿意,那么在執(zhí)行一下reshard,把其它節(jié)點(diǎn)的槽位都分給192.168.81.210的6380上,這樣一來,210的6380擁有的槽位就是0-16383,然后在將210的槽位一個(gè)節(jié)點(diǎn)分給5461個(gè),分完之后,各節(jié)點(diǎn)的順序就一致了。

3.驗(yàn)證數(shù)據(jù)遷移過程是否導(dǎo)致數(shù)據(jù)異常

多開幾個(gè)窗口,一個(gè)執(zhí)行數(shù)據(jù)槽位遷移,一個(gè)不斷創(chuàng)建key,一個(gè)查看key的創(chuàng)建進(jìn)度,一個(gè)查看key的數(shù)據(jù)。
持續(xù)測試,發(fā)現(xiàn)沒有任何數(shù)據(jù)異常,全部顯示ok。

4.將下線的主節(jié)點(diǎn)從集群中刪除

4.1.刪除節(jié)點(diǎn)

使用redis-trib刪除一個(gè)節(jié)點(diǎn),如果這個(gè)節(jié)點(diǎn)存在復(fù)制關(guān)系,有節(jié)點(diǎn)在復(fù)制當(dāng)前節(jié)點(diǎn)或者當(dāng)前節(jié)點(diǎn)復(fù)制別的節(jié)點(diǎn)的數(shù)據(jù),redis-trib會自動處理復(fù)制關(guān)系,然后將節(jié)點(diǎn)刪除,節(jié)點(diǎn)刪除后會把對應(yīng)的進(jìn)程也停止運(yùn)行。

刪除節(jié)點(diǎn)之前必須確保該節(jié)點(diǎn)沒有任何槽位和數(shù)據(jù),否則會刪除失敗。

命令:./redis-trib.rb del-node 節(jié)點(diǎn)IP:端口 ID

[root@redis-1 /data/redis_cluster/redis-3.2.9/src]# ./redis-trib.rb del-node 192.168.81.240:6390 6bee155f136f40e28e1f60c8ddec3b158cd8f8e8
>>> Removing node 6bee155f136f40e28e1f60c8ddec3b158cd8f8e8 from cluster 192.168.81.240:6390
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
[root@redis-1 /data/redis_cluster/redis-3.2.9/src]# ./redis-trib.rb del-node 192.168.81.240:6391 f6b9320dfbc929ad5a31cdb149360b0fd8de2e60
>>> Removing node f6b9320dfbc929ad5a31cdb149360b0fd8de2e60 from cluster 192.168.81.240:6391
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

4.2.調(diào)整主從交叉復(fù)制

刪掉192.168.81.240服務(wù)器上的兩個(gè)redis節(jié)點(diǎn)后,192.168.81.210服務(wù)器上的6380就沒有了復(fù)制關(guān)系,我們需要把192.168.81.230的6381節(jié)點(diǎn)復(fù)制192.168.81.210的6380節(jié)點(diǎn)。

[root@redis-1 ~]# redis-cli -h 192.168.81.230 -p 6381
192.168.81.230:6381> CLUSTER REPLICATE 80e256579658eb256c5b710a3f82c439665794ba
OK

4.3.當(dāng)節(jié)點(diǎn)存在數(shù)據(jù)無法刪除

[root@redis-1 /data/redis_cluster/redis-3.2.9/src]# ./redis-trib.rb del-node 192.168.81.220:6380 10dc7f3f9a753140a8494adbbe5a13d0026451a1
>>> Removing node 10dc7f3f9a753140a8494adbbe5a13d0026451a1 from cluster 192.168.81.220:6380
[ERR] Node 192.168.81.220:6380 is not empty! Reshard data away and try again.

5.將下線主機(jī)清空集群信息

redis-trib雖然能夠?qū)⒐?jié)點(diǎn)在集群中刪除,但是無法將其的集群信息清空,如果集群信息還有保留,那么該接地那就無法加入其它集群。

在下線的redis節(jié)點(diǎn)上使用cluster reset刪除集群信息即可。

192.168.81.240:6390> CLUSTER reset

OK

到此這篇關(guān)于Redis Cluster集群收縮主從節(jié)點(diǎn)詳細(xì)教程的文章就介紹到這了,更多相關(guān)Redis Cluster集群收縮內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!

海外服務(wù)器租用

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部