您好,登錄后才能下訂單哦!
這篇文章為大家帶來有關redis高可用集群的詳細介紹。大部分知識點都是大家經常用到的,為此分享給大家做個參考。一起跟隨小編過來看看吧。
Redis是我們目前最大規模使用的緩存中間件,由于它強大高效而又便捷的功能,得到廣泛的使用。
Redis在2015年發布了3.0.0,官方支持redis cluster。至此結束了redis沒有集群的時代,之前我們用的redis cluster多的是twitter發布的Twemproxy還有就是豌豆莢開發的codis。本文將進行理解和實踐redis cluster。下面,我盡量用通熟易懂的方式來闡述。
redis cluster在設計的時候,就考慮到了去中心化,去中間件,也就是說,在集群中的每個節點都是平等的關系,都是對等的,每個節點都保存各自的數據和整個集群的狀態。每個節點都和其他所有節點連接,而且這些連接保持活躍,這樣就保證了我們只需要連接集群中的任意一個節點,就可以獲取到其他節點的數據。
我們知道集群中的每個節點都是對等的關系并且都保存各自的數據,那么redis是如何合理分配這些節點和數據的呢?
Redis Cluster沒有使用傳統的一致性哈希來分配數據,而是采用另外一種哈希槽(hash slot)的方式來分配的。
redis cluster默認分配了16384個slot,當我們set一個key時,會采用CRC16算法來取模得到所屬的slot,然后將這個key分到哈希槽區間的節點上,具體算法就是:CRC16(key) % 16384
。
需要注意的是:Redis集群至少需要3個節點,因為投票容錯機制要求超過半數節點認為某個節點掛了該節點才是掛了,所以2個節點無法構成集群。
所以,我們假設現在有3個節點已經部署成redis cluster,分別是:A,B,C 三個節點,他們可以是一臺機器上的三個端口,也可以是三臺不同的服務器;那么采用哈希槽(hash slot)的方式來分配16384個slot,它們三個節點分別承擔的slot區間是:
節點A覆蓋0-5461; 節點B覆蓋 5462-10922; 節點C覆蓋 10923-16383;
那么,現在我想設置一個key,比如叫my_name:set my_name linux
按照redis cluster的哈希槽算法:CRC16('my_name')%16384 = 2412。
那么就會把這個key的存儲分配到A上了。
同樣,當我連接(A,B,C)任何一個節點想獲取my_name這個key時,也會這樣的算法,然后內部跳轉到A節點上獲取數據。
這種哈希槽分配方式的好處就是很清晰,比如我想新增一個節點ID,redis cluster的這種做法是從各個節點的前面各拿取一部分slot到D上。大致就會變成這樣:(我會在接下來的實踐中實驗)
節點A覆蓋 1365-5460;節點B覆蓋 6827-10922;節點C覆蓋 12288-16383; 節點D覆蓋0-1364,5461-6826,10923-12287;
同樣,刪除一個節點也是類似,移動完成后就可以刪除這個節點了。
所以redis cluster 就是這樣一個形狀:
redis cluster為了保證數據的高可用性,加入了主從模式,一個主節點對應一個或多個從節點,主節點提供數據存取,從節點則是從主節點拉取數據備份,當這個主節點掛掉后,就會有這個從節點存取一個來充當主節點,從而保證集群不會掛掉。
上邊那個例子里,集群有ABC三個主節點,如果這3個節點都沒有加入從節點,如果B掛掉了,我們就無法訪問整個集群了。A和C的slot也無法訪問。所以我們在集群建立的時候,一定要為每個主節點都添加從節點,比如像這樣,集群包含主節點A,B,C,以及從節點A1,B1,C1,那么即使B掛掉,系統也可以繼續正確工作。因為B1節點提替代了B節點,所以redis集群將會選擇B1節點作為新的主節點,集群將會繼續正確地提供服務。需要注意的是,當B重新開啟后,它就會變成B1的從節點,而不會重新變成主節點。
如果節點B和B1同時掛了,Redis集群就無法繼續正常地提供服務了,一般情況下,是不會也不允許兩節點同時掛掉。
流程下圖所示:
依據redis cluster內部故障轉移實現原理,reids集群至少需要3個節點,并且要保證集群的高可用,需要每個節點都有從節點,因此搭建redis集群至少需要6臺服務器,三主三從。
條件有限,并且是測試環境,所以我們在兩臺機器上創建一個偽集群,通過不同的TCP端口啟動多個redis實例,組成集群,當然實際生產環境的Redis集群搭建和這里是一樣的。
目前redis cluster 的搭建有兩種方式:
1,手動方式搭建,即手動執行cluster命令,一步步完成搭建流程。
2,自動方式搭建,即使用官方提供的集群管理工具快速搭建。
兩種方式原理一樣,自動搭建方式只是將手動搭建方式中需要執行的redis命令封裝到了可執行程序。生產環境中推薦使用自動方式搭建,簡單快捷,不易出錯;本文實戰演示兩種方式都會提及。
環境描述:
主機A:172.16.1.100(CentOS 7.3),啟動三個實例7000,7001,7002;全部為主
主機B:172.16.1.110(CentOS 7.3),啟動三個實例8000,8001,8002;全部為從
1,安裝redis
A主機:
[root@redis01-server ~]# tar zxf redis-4.0.14.tar.gz
[root@redis01-server ~]# mv redis-4.0.14 /usr/local/redis
[root@redis01-server ~]# cd /usr/local/redis/
[root@redis01-server redis]# make && make install
#安裝完成,修改配置文件:
[root@redis01-server ~]# vim /usr/local/redis/redis.conf
69 bind 172.16.1.100 #設置為當前redis主機的ip地址
92 port 7000 #設置redis的監聽端口
136 daemonize yes #以守護進程運行redis實例
814 cluster-enabled yes #啟動集群模式
822 cluster-config-file nodes-7000.conf #設置當前節點集群配置文件路徑
828 cluster-node-timeout 5000 #設置當前連接超時秒數
672 appendonly yes #開啟AOF持久化模式
676 appendfilename "appendonly-7000.aof" #保存數據的AOF文件名稱
B主機:
[root@redis02-server ~]# tar zxf redis-4.0.14.tar.gz
[root@redis02-server ~]# mv redis-4.0.14 /usr/local/redis
[root@redis02-server ~]# cd /usr/local/redis
[root@redis02-server redis]# make && make install
[root@redis02-server ~]# vim /usr/local/redis/redis.conf
bind 172.16.1.110
port 8000
daemonize yes
cluster-enabled yes
cluster-config-file nodes-8000.conf
cluster-node-timeout 5000
appendonly yes
appendfilename "appendonly-8000.aof"
2,根據上述的規劃,創建各個節點啟動配置文件的存放目錄
A主機:
[root@redis01-server ~]# mkdir /usr/local/redis-cluster
[root@redis01-server ~]# cd /usr/local/redis-cluster/
[root@redis01-server redis-cluster]# mkdir {7000,7001,7002}
B主機:
[root@redis02-server ~]# mkdir /usr/local/redis-cluster
[root@redis02-server ~]# cd /usr/local/redis-cluster/
[root@redis02-server redis-cluster]# mkdir {8000,8001,8002}
3,將主配文件分別拷貝到相對應的目錄下
A主機:
[root@redis01-server ~]# cp /usr/local/redis/redis.conf /usr/local/redis-cluster/7000/
[root@redis01-server ~]# cp /usr/local/redis/redis.conf /usr/local/redis-cluster/7001/
[root@redis01-server ~]# cp /usr/local/redis/redis.conf /usr/local/redis-cluster/7002/
B主機:
[root@redis02-server ~]# cp /usr/local/redis/redis.conf /usr/local/redis-cluster/8000/
[root@redis02-server ~]# cp /usr/local/redis/redis.conf /usr/local/redis-cluster/8001/
[root@redis02-server ~]# cp /usr/local/redis/redis.conf /usr/local/redis-cluster/8002/
#修改各自的監聽TCP端口號:
A主機:
[root@redis01-server ~]# sed -i "s/7000/7001/g" /usr/local/redis-cluster/7001/redis.conf
[root@redis01-server ~]# sed -i "s/7000/7002/g" /usr/local/redis-cluster/7002/redis.conf
B主機:
[root@redis02-server ~]# sed -i "s/8000/8001/g" /usr/local/redis-cluster/8001/redis.conf
[root@redis02-server ~]# sed -i "s/8000/8002/g" /usr/local/redis-cluster/8002/redis.conf
4,啟動reids服務
A主機:
[root@redis01-server ~]# ln -s /usr/local/bin/redis-server /usr/local/sbin/
[root@redis01-server ~]# redis-server /usr/local/redis-cluster/7000/redis.conf
[root@redis01-server ~]# redis-server /usr/local/redis-cluster/7001/redis.conf
[root@redis01-server ~]# redis-server /usr/local/redis-cluster/7002/redis.conf
#確保各節點服務正常運行:
[root@redis01-server ~]# ps -ef | grep redis
root 19595 1 0 04:55 ? 00:00:00 redis-server 172.16.1.100:7000 [cluster]
root 19602 1 0 04:56 ? 00:00:00 redis-server 172.16.1.100:7001 [cluster]
root 19607 1 0 04:56 ? 00:00:00 redis-server 172.16.1.100:7002 [cluster]
root 19612 2420 0 04:58 pts/0 00:00:00 grep --color=auto redis
B主機:
[root@redis02-server ~]# ln -s /usr/local/bin/redis-server /usr/local/sbin/
[root@redis02-server ~]# redis-server /usr/local/redis-cluster/8000/redis.conf
[root@redis02-server ~]# redis-server /usr/local/redis-cluster/8001/redis.conf
[root@redis02-server ~]# redis-server /usr/local/redis-cluster/8002/redis.conf
[root@redis02-server ~]# ps -ef | grep redis
root 18485 1 0 00:17 ? 00:00:00 redis-server 172.16.1.110:8000 [cluster]
root 18490 1 0 00:17 ? 00:00:00 redis-server 172.16.1.110:8001 [cluster]
root 18495 1 0 00:17 ? 00:00:00 redis-server 172.16.1.110:8002 [cluster]
root 18501 1421 0 00:19 pts/0 00:00:00 grep --color=auto redis
5,節點握手
雖然上面6各節點都啟用集群支持,但默認情況下它們是不相互信任或者說沒有聯系的。節點握手就是在各個節點之間創建鏈接(每個節點與其他節點相連),形成一個完整的網絡,即集群。
節點握手的命令如下:
cluster meet ip port
我們創建的6個節點可以通過redis-cli 連接到A節點執行如下五組命令完成握手:
注意:需要關閉集群中各臺主機的防火墻:systemctl stop firewalld
,否則無法完成握手
[root@redis01-server ~]# redis-cli -h 172.16.1.100 -p 7000
172.16.1.100:7000> cluster meet 172.16.1.100 7001
OK
172.16.1.100:7000> cluster meet 172.16.1.100 7002
OK
172.16.1.100:7000> cluster meet 172.16.1.110 8000
OK
172.16.1.100:7000> cluster meet 172.16.1.110 8001
OK
172.16.1.100:7000> cluster meet 172.16.1.110 8002
OK
#查看握手是否正常:
172.16.1.100:7000> cluster nodes
060a11f6985df66e4b9cf596355bbe334f843587 172.16.1.100:7001@17001 master - 0 1584155029000 1 connected
2fb26d79f703f9fbd8841e4ee93ea88f7df5dad9 172.16.1.110:8002@18002 master - 0 1584155029000 5 connected
6d3ac8cf0dc3c8400d2df8d0559fbe8bdce0c34d 172.16.1.110:8000@18000 master - 0 1584155029243 3 connected
cc3b16e067bf1ce9978c13870f0e1d538102a733 172.16.1.110:8001@18001 master - 0 1584155030000 0 connected
0f74b9e2d07e159fdc0fc1edffd3d0b305adc2fd 172.16.1.100:7000@17000 myself,master - 0 1584155028000 2 connected
c0fefd1442b3fa4e41eb6fba5073dcc1427ca812 172.16.1.100:7002@17002 master - 0 1584155030249 4 connected
可以看到,集群中所有節點都已經建立鏈接,自此,節點握手完成。
#雖然節點已經建立鏈接,但此時redis集群還并沒有處于上線狀態,執行cluster info命令來查看目前集群的運行狀態:
172.16.1.100:7000> cluster info
cluster_state:fail #表示當前集群處于下線狀態
cluster_slots_assigned:0 #為0 表示目前所有槽沒有被分配到節點上
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:0
cluster_current_epoch:5
cluster_my_epoch:2
cluster_stats_messages_ping_sent:612
cluster_stats_messages_pong_sent:627
cluster_stats_messages_meet_sent:10
cluster_stats_messages_sent:1249
6,分配槽位
只有給集群中所有主節點分配好槽位(slot),集群才能正常上線,分配槽位的命令如下:cluster addslots slot [slot ...]
#根據預先規劃,需要使用cluster addslots 命令手動將16384個哈希槽大致均等分配給主節點A,B,C。
[root@redis01-server ~]# redis-cli -h 172.16.1.100 -p 7000 cluster addslots {0..5461}
OK
[root@redis01-server ~]# redis-cli -h 172.16.1.100 -p 7001 cluster addslots {5462..10922}
OK
[root@redis01-server ~]# redis-cli -h 172.16.1.100 -p 7002 cluster addslots {10923..16383}
OK
槽位分配完成后,可以再次查看目前集群的狀態:
[root@redis01-server ~]# redis-cli -h 172.16.1.100 -p 7000 cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:2
cluster_stats_messages_ping_sent:2015
cluster_stats_messages_pong_sent:2308
cluster_stats_messages_meet_sent:10
cluster_stats_messages_sent:4333
cluster_stats_messages_ping_received:2308
cluster_stats_messages_pong_received:2007
cluster_stats_messages_received:4315
cluster_state:ok 證明redis集群成功上線。
#如需刪除分配槽,可以執行cluster delslots 命令,例如:[root@redis01-server ~]# redis-cli -h 172.16.1.100 -p 7000 cluster delslots {10923..16383}
#查看槽位分配情況:
[root@redis01-server ~]# redis-cli -h 172.16.1.100 -p 7000 cluster nodes
060a11f6985df66e4b9cf596355bbe334f843587 172.16.1.100:7001@17001 master - 0 1584156388000 1 connected 5462-10922
2fb26d79f703f9fbd8841e4ee93ea88f7df5dad9 172.16.1.110:8002@18002 master - 0 1584156387060 5 connected
6d3ac8cf0dc3c8400d2df8d0559fbe8bdce0c34d 172.16.1.110:8000@18000 master - 0 1584156386056 3 connected
cc3b16e067bf1ce9978c13870f0e1d538102a733 172.16.1.110:8001@18001 master - 0 1584156387000 0 connected
0f74b9e2d07e159fdc0fc1edffd3d0b305adc2fd 172.16.1.100:7000@17000 myself,master - 0 1584156387000 2 connected 0-5461
c0fefd1442b3fa4e41eb6fba5073dcc1427ca812 172.16.1.100:7002@17002 master - 0 1584156386000 4 connected 10923-16383
可以看到三個主節點槽位已完成分配,但是還有三個從節點沒有使用,如果此時有一個主節點故障,那么整個集群也就掛了,所以我們需要為從節點配置主節點,實現高可用。
7,主從復制
集群復制命令如下:
cluster replicate node-id
1)連接集群中任意一個節點,獲得所有主節點的node-id
[root@redis01-server ~]# redis-cli -h 172.16.1.110 -p 8000 cluster nodes
2fb26d79f703f9fbd8841e4ee93ea88f7df5dad9 172.16.1.110:8002@18002 master - 0 1584157179543 5 connected
c0fefd1442b3fa4e41eb6fba5073dcc1427ca812 172.16.1.100:7002@17002 master - 0 1584157179946 4 connected 10923-16383
6d3ac8cf0dc3c8400d2df8d0559fbe8bdce0c34d 172.16.1.110:8000@18000 myself,master - 0 1584157179000 3 connected
060a11f6985df66e4b9cf596355bbe334f843587 172.16.1.100:7001@17001 master - 0 1584157180952 1 connected 5462-10922
cc3b16e067bf1ce9978c13870f0e1d538102a733 172.16.1.110:8001@18001 master - 0 1584157180549 0 connected
0f74b9e2d07e159fdc0fc1edffd3d0b305adc2fd 172.16.1.100:7000@17000 master - 0 1584157179544 2 connected 0-5461
2)執行如下三組命令分別為從節點指定其主節點,使集群可以自動完成主從復制
[root@redis02-server ~]# redis-cli -h 172.16.1.110 -p 8000 cluster replicate 0f74b9e2d07e159fdc0fc1edffd3d0b305adc2fd
OK
[root@redis02-server ~]# redis-cli -h 172.16.1.110 -p 8001 cluster replicate 060a11f6985df66e4b9cf596355bbe334f843587
OK
[root@redis02-server ~]# redis-cli -h 172.16.1.110 -p 8002 cluster replicate c0fefd1442b3fa4e41eb6fba5073dcc1427ca812
OK
3)查看集群中各個節點的復制狀態信息:
[root@redis02-server ~]# redis-cli -h 172.16.1.110 -p 8000 cluster nodes
2fb26d79f703f9fbd8841e4ee93ea88f7df5dad9 172.16.1.110:8002@18002 slave c0fefd1442b3fa4e41eb6fba5073dcc1427ca812 0 1584157699631 5 connected
c0fefd1442b3fa4e41eb6fba5073dcc1427ca812 172.16.1.100:7002@17002 master - 0 1584157700437 4 connected 10923-16383
6d3ac8cf0dc3c8400d2df8d0559fbe8bdce0c34d 172.16.1.110:8000@18000 myself,slave 0f74b9e2d07e159fdc0fc1edffd3d0b305adc2fd 0 1584157699000 3 connected
060a11f6985df66e4b9cf596355bbe334f843587 172.16.1.100:7001@17001 master - 0 1584157701442 1 connected 5462-10922
cc3b16e067bf1ce9978c13870f0e1d538102a733 172.16.1.110:8001@18001 slave 060a11f6985df66e4b9cf596355bbe334f843587 0 1584157699932 1 connected
0f74b9e2d07e159fdc0fc1edffd3d0b305adc2fd 172.16.1.100:7000@17000 master - 0 1584157700000 2 connected 0-5461
可以看到所有從節點都作為對應主節點的備份節點,至此,已經成功以手動方式搭建一個redis集群。
總結手動搭建redis集群的關鍵步驟:
1,在各節點安裝redis
2,修改配置文件,開啟集群模式
3,啟動各節點redis服務
4,節點握手
5,為主節點分配槽位
6,主從節點建立復制關系
推薦博文:
redis的 rdb 和 aof 持久化的區別:https://www.cnblogs.com/shizhengwen/p/9283973.html
Redis 3.0版本之后官方發布了一個集群管理工具 redis-trib.rb,集成在Redis源碼包的src目錄下。其封裝了redis提供的集群命令,使用簡單,便捷。
環境描述:
主機A:172.16.1.100(CentOS 7.3),啟動三個實例7000,7001,7002;
主機B:172.16.1.110(CentOS 7.3),啟動三個實例8000,8001,8002;
1,執行上邊”手動搭建redis“的步驟1-4(到啟動redis即可(確保redis服務正常運行),關閉防火墻。
2,集群管理工具搭建
redis-trib.rb 是 Redis 作者使用 Ruby 語言開發的,故使用該工具之前還需要先在機器上安裝 Ruby 環境。
注意的是:從Redis 5.0 版本開始便把這個工具集成到 redis-cli 中,以--cluster參數提供使用,其中create命令可以用來創建集群。
1)安裝Ruby環境以及其他依賴項(兩臺主機)
[root@redis-01 ~]# yum -y install ruby ruby-devel rubygems rpm-build openssl openssl-devel
#確認安裝版本:
[root@redis-01 ~]# ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
2)使用redis-trib.rb 腳本搭建集群
[root@redis-01 ~]# ln -s /usr/local/redis/src/redis-trib.rb /usr/local/sbin/
[root@redis-01 ~]# redis-trib.rb create --replicas 1 172.16.1.100:7000 172.16.1.100:7001 172.16.1.100:7002 172.16.1.110:8000 172.16.1.110:8001 172.16.1.110:8002
#這里使用create命令,--replicas 1 參數表示為每個主節點創建一個從節點(隨機分配),其他參數是實例的地址集合
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError)
from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/sbin/redis-trib.rb:25:in `<main>'
上面報錯是需要redis的gem包來安裝ruby和redis的接口,安裝gem包,網址: https://rubygems.org/gems/redis/ 選擇對應的版本下載,這里選擇3.3.0版本:
[root@redis-01 ~]# gem install -l redis-3.3.0.gem
Successfully installed redis-3.3.0
Parsing documentation for redis-3.3.0
Installing ri documentation for redis-3.3.0
1 gem installed
#重新創建集群
[root@redis-01 ~]# redis-trib.rb create --replicas 1 172.16.1.100:7000 172.16.1.100:7001 172.16.1.100:7002 172.16.1.110:8000 172.16.1.110:8001 172.16.1.110:8002
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
172.16.1.100:7000
172.16.1.110:8000
172.16.1.100:7001
Adding replica 172.16.1.110:8002 to 172.16.1.100:7000
Adding replica 172.16.1.100:7002 to 172.16.1.110:8000
Adding replica 172.16.1.110:8001 to 172.16.1.100:7001
M: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots:0-5460 (5461 slots) master
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:10923-16383 (5461 slots) master
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
replicates 4debd0b5743826d203d1af777824eb1b83105d21
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:5461-10922 (5462 slots) master
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
S: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
replicates 8613a457f8009aaf784df0ac6d7039034b16b6a6
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join..
>>> Performing Cluster Check (using node 172.16.1.100:7000)
M: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots: (0 slots) slave
replicates 8613a457f8009aaf784df0ac6d7039034b16b6a6
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 4debd0b5743826d203d1af777824eb1b83105d21
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
redis-trib會提示你做了什么配置,輸入yes接受,集群就被配置和加入了,意思是實例會經過互相交流后啟動。
至此,集群可以說是搭建完成了,一條命令解決,可以說是非常方便。
1)測試集群的狀態:
[root@redis-01 ~]# redis-trib.rb check 172.16.1.100:7000
>>> Performing Cluster Check (using node 172.16.1.100:7000)
M: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots: (0 slots) slave
replicates 8613a457f8009aaf784df0ac6d7039034b16b6a6
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 4debd0b5743826d203d1af777824eb1b83105d21
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:10923-16383 (5461 slots) master
1 additional replica(s)
可以看到有3個主節點(M),分別是7000,8000,7001,3個從節點(S),分別是7002,8001,8002。每個節點都是成功的連接狀態。
2)測試連接集群
集群搭建成功了;按照redis cluster的特點,它是去中心化,每個節點都是對等的,所以,你連接哪個節點都可以獲取和設置數據,接下來進行測試:
[root@redis-01 ~]# redis-cli -h 172.16.1.100 -p 7000 -c //集群模式需要加上-c參數
172.16.1.100:7000> set my_name linux //設置一個值
-> Redirected to slot [12803] located at 172.16.1.100:7001
//前面有說到,分配key的時候,它會使用CRC16('my_name')%16384算法來計算將這個key放到哪個節點,這里分配到了12803 ,所以slot就分配到了 7001(范圍:10923-16383)這個節點上
OK
172.16.1.100:7001> get my_name //獲取該數據值
"linux"
redis cluster 采用的方式很直接,創建完key后,它直接跳轉到7001節點了,而不是還在自身的7000節點,現在我們連接8002這個從節點:
[root@redis-01 ~]# redis-cli -h 172.16.1.110 -p 8002 -c
172.16.1.110:8002> get my_name
-> Redirected to slot [12803] located at 172.16.1.100:7001
"linux"
//同樣是獲取 key(my_name)的值,它同樣也是跳轉到了7001上,并返回該數據值
3)測試集群的高可用
當前我的redis集群有3個主節點(7000,8000,7001)提供數據存儲和讀取,3個從節點(7002,8001,8002)負責把主節點的數據同步到自己的節點上來,所以我們來看一下從節點的appendonly.aof的內容(因為剛才創建的值分配給了7001節點,而7001主節點對應的從節點是8001,所以我們查看8001的aof文件)
[root@redis-02 ~]# cat appendonly-8001.aof
*2
$6
SELECT
$1
0
*3
$3
set
$7
my_name
$5
linux
可以看到的確是從主節點同步過來的數據。
注意:你的redis在哪個路徑下啟動,dump.rdb 文件或者appendonly.aof文件就會產生在啟動所在的目錄,如果想要自定義路徑可以修改配置文件:263 dir ./ #把相對路徑修改為絕對路徑
#下面,我們模擬其中一臺master主服務器掛掉:
[root@redis-01 ~]# ps -ef | grep redis
root 5598 1 0 01:02 ? 00:00:06 redis-server 172.16.1.100:7000 [cluster]
root 5603 1 0 01:02 ? 00:00:06 redis-server 172.16.1.100:7001 [cluster]
root 5608 1 0 01:02 ? 00:00:06 redis-server 172.16.1.100:7002 [cluster]
root 19735 2242 0 03:32 pts/0 00:00:00 grep --color=auto redis
[root@redis-01 ~]# kill 5598
#測試集群的狀態:
[root@redis-01 ~]# redis-trib.rb check 172.16.1.100:7000
[ERR] Sorry, can't connect to node 172.16.1.100:7000
[root@redis-01 ~]# redis-trib.rb check 172.16.1.100:7001
>>> Performing Cluster Check (using node 172.16.1.100:7001)
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 4debd0b5743826d203d1af777824eb1b83105d21
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots:0-5460 (5461 slots) master
0 additional replica(s)
從上面的結果可以看到,當7000主節點掛掉了,那么這個時候,7000的從節點只有8002一個,所以8002就會被選舉成master節點了。并且原來7000節點上的數據不會丟失,而是會轉移到了8002節點上,當用戶再次獲取數據時,則是從8002上面獲取了。
既然7000節點服務器因為某些原因宕機了,但是當我們把故障解決后,重新將7000節點加入集群中,那么7000節點會在集群中充當什么角色呢?
[root@redis-01 ~]# redis-server /usr/local/redis-cluster/7000/redis.conf
[root@redis-01 ~]# ps -ef | grep redis
root 5603 1 0 01:02 ? 00:00:08 redis-server 172.16.1.100:7001 [cluster]
root 5608 1 0 01:02 ? 00:00:08 redis-server 172.16.1.100:7002 [cluster]
root 19771 1 0 03:50 ? 00:00:00 redis-server 172.16.1.100:7000 [cluster]
root 19789 2242 0 03:51 pts/0 00:00:00 grep --color=auto redis
#查看集群的狀態:
[root@redis-01 ~]# redis-trib.rb check 172.16.1.100:7001
>>> Performing Cluster Check (using node 172.16.1.100:7001)
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 4debd0b5743826d203d1af777824eb1b83105d21
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots: (0 slots) slave
replicates 3cc268dfbb918a99159900643b318ec87ba03ad9
可以看到7000節點已經成功加入集群,但它卻作為了8002的從節點。
新加入一個節點,分兩種情況:1是作為主節點,2是作為一個主節點的從節點,我們分別來實踐一下。
1,作為主節點加入
1)新建一個7003節點,作為一個新的master節點加入:
[root@redis-01 ~]# mkdir /usr/local/redis-cluster/7003
[root@redis-01 ~]# cd /usr/local/redis-cluster/
[root@redis-01 redis-cluster]# cp 7000/redis.conf 7003/
[root@redis-01 redis-cluster]# sed -i "s/7000/7003/g" 7003/redis.conf
#啟動7003 redis服務:
[root@redis-01 ~]# redis-server /usr/local/redis-cluster/7003/redis.conf
[root@redis-01 ~]# ps -ef | grep redis
root 5603 1 0 01:02 ? 00:00:09 redis-server 172.16.1.100:7001 [cluster]
root 5608 1 0 01:02 ? 00:00:09 redis-server 172.16.1.100:7002 [cluster]
root 19771 1 0 03:50 ? 00:00:00 redis-server 172.16.1.100:7000 [cluster]
root 19842 1 0 04:06 ? 00:00:00 redis-server 172.16.1.100:7003 [cluster]
root 19847 2242 0 04:06 pts/0 00:00:00 grep --color=auto redis
2)將7003節點加入集群
[root@redis-01 ~]# redis-trib.rb add-node 172.16.1.100:7003 172.16.1.100:7000 //add-node是加入指令,前面表示新加入的節點,后邊表示加入的集群的一個節點,用來辨識是哪個集群,理論上哪個都可以
>>> Adding node 172.16.1.100:7003 to cluster 172.16.1.100:7000
>>> Performing Cluster Check (using node 172.16.1.100:7000)
S: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots: (0 slots) slave
replicates 3cc268dfbb918a99159900643b318ec87ba03ad9
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
M: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 4debd0b5743826d203d1af777824eb1b83105d21
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 172.16.1.100:7003 to make it join the cluster.
[OK] New node added correctly.
表示新的節點連接成功,而且也已經加入到集群了,我們再來檢查一下:
[root@redis-01 ~]# redis-trib.rb check 172.16.1.100:7003
>>> Performing Cluster Check (using node 172.16.1.100:7003)
M: edd51c8389ba069d49fe54c24c535716ce06e62b 172.16.1.100:7003
slots: (0 slots) master
0 additional replica(s)
M: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 4debd0b5743826d203d1af777824eb1b83105d21
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
S: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots: (0 slots) slave
replicates 3cc268dfbb918a99159900643b318ec87ba03ad9
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
可以看到集群中有7個節點,7003也作為了master節點,但是有注意到7003節點的slots是0;也就是說,雖然它現在是主節點,但是并沒有分配任何slot給它,所以它現在還不負責數據的存取。所以需要我們手動對集群進行重新分片遷移;
3)遷移slot節點
#這個命令是用來遷移slot節點的,后邊的172.16.1.100:7000 表示是哪個集群,端口隨便哪個節點都是可以的:
[root@redis-01 ~]# redis-trib.rb reshard 172.16.1.100:7000
How many slots do you want to move (from 1 to 16384)?
#回車后,它提示我們需要遷移多少slot到7003上,我們可以算一下:16384/4 = 4096,也就是說,為了負載均衡,我們需要移動4096個槽點到7003上
How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID?
#它又提示我們,接受的node ID是多少,7003的id我們通過上面的信息就可以獲得
What is the receiving node ID? edd51c8389ba069d49fe54c24c535716ce06e62b
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:
#接著 redis-trib 會向你詢問重新分片的源節點(source node),也就是要從哪個節點中取出 4096 個哈希槽, 并將這些槽移動到7003節點上面。如果我們不打算從特定的節點上取出指定數量的哈希槽, 那么可以向 redis-trib 輸入 all ,這樣的話, 集群中的所有主節點都會成為源節點, redis-trib 將從各個源節點中各取出一部分哈希槽, 湊夠 4096 個, 然后移動到7003節點上,所以我們輸入all:
Source node #1:all
#接下來就開始遷移了,并且會詢問你是否確認:
Do you want to proceed with the proposed reshard plan (yes/no)? yes
輸入yes回車后,redis-trib就會正式開始執行重新分片操作,將指定的哈希槽從源節點一個個地移動到7003節點上面。遷移完畢之后,我們來檢查一下:
[root@redis-01 ~]# redis-trib.rb check 172.16.1.100:7000
>>> Performing Cluster Check (using node 172.16.1.100:7000)
S: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots: (0 slots) slave
replicates 3cc268dfbb918a99159900643b318ec87ba03ad9
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
M: edd51c8389ba069d49fe54c24c535716ce06e62b 172.16.1.100:7003
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
0 additional replica(s)
M: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 4debd0b5743826d203d1af777824eb1b83105d21
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:6827-10922 (4096 slots) master
1 additional replica(s)
我們著重看7003:”0-1364,5461-6826,10923-12287 (4096 slots) “
這些原來在其他節點上的slot遷移到了7003上。原來,它只是間隔的移動,并不是銜接的整體移動,我們來驗證7003節點上邊是否有數據:
[root@redis-01 ~]# redis-cli -h 172.16.1.100 -p 7003 -c
172.16.1.100:7003> get my_name
-> Redirected to slot [12803] located at 172.16.1.100:7001
"linux"
//證明7003主節點已經正常工作了。
2,作為從節點加入
1)新建一個8003節點,作為7003的從節點,步驟類似,這里就省略了,啟動8003的redis服務后,我們把它加入到集群中的從節點中:
/使用add-node -slave --master-id命令,master-id指向的是你需要選擇哪個節點作為新加入從節點的主節點,172.16.1.110:8003表示你需要新加入的從節點,最后則是選擇當前集群中的任意一個節點即可
[root@redis-02 ~]# redis-trib.rb add-node --slave --master-id edd51c8389ba069d49fe54c24c535716ce06e62b 172.16.1.110:8003 172.16.1.110:8000
>>> Adding node 172.16.1.110:8003 to cluster 172.16.1.110:8000
>>> Performing Cluster Check (using node 172.16.1.110:8000)
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:6827-10922 (4096 slots) master
1 additional replica(s)
M: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: edd51c8389ba069d49fe54c24c535716ce06e62b 172.16.1.100:7003
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
0 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 4debd0b5743826d203d1af777824eb1b83105d21
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
S: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots: (0 slots) slave
replicates 3cc268dfbb918a99159900643b318ec87ba03ad9
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 172.16.1.110:8003 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 172.16.1.100:7003.
[OK] New node added correctly.
上邊提示說,已經選擇了7003作為master節點,并且成功了。我們來檢查一下集群各個節點的狀態:
[root@redis-02 ~]# redis-trib.rb check 172.16.1.110:8003
>>> Performing Cluster Check (using node 172.16.1.110:8003)
S: 4ffabff843d32364fc506f3445980f5a04aa4292 172.16.1.110:8003
slots: (0 slots) slave
replicates edd51c8389ba069d49fe54c24c535716ce06e62b
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots:6827-10922 (4096 slots) master
1 additional replica(s)
S: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots: (0 slots) slave
replicates 3cc268dfbb918a99159900643b318ec87ba03ad9
M: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots:1365-5460 (4096 slots) master
1 additional replica(s)
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:12288-16383 (4096 slots) master
1 additional replica(s)
M: edd51c8389ba069d49fe54c24c535716ce06e62b 172.16.1.100:7003
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
1 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 4debd0b5743826d203d1af777824eb1b83105d21
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
#驗證該從節點是否能夠在集群中通信:
[root@redis-02 ~]# redis-cli -h 172.16.1.110 -p 8003 -c
172.16.1.110:8003> get my_name
-> Redirected to slot [12803] located at 172.16.1.100:7001
"linux"
//證明從節點加入成功,并且正常工作
redis集群中有添加節點,那肯定就會有移除節點的需求,redis cluster 同樣支持移除節點的功能,同樣也是redis-trib.rb的用法。
語法格式:
redis-trib del-node ip:端口 `<node-id>`
1,移除主節點
//和新加節點不同的是,移除需要節點的node-id。那么我們嘗試將8000這個主節點移除:
[root@redis-02 ~]# redis-trib.rb del-node 172.16.1.110:8000 4debd0b5743826d203d1af777824eb1b83105d21
>>> Removing node 4debd0b5743826d203d1af777824eb1b83105d21 from cluster 172.16.1.110:8000
[ERR] Node 172.16.1.110:8000 is not empty! Reshard data away and try again.
報錯了,它提示我們說,由于8000節點里面已經有數據了,不能被移除,要先將它的數據轉移出去,也就是說得重新分片,所以用上面增加新節點后的分片方式一樣,再重新分片一次:
[root@redis-01 ~]# redis-trib.rb reshard 172.16.1.100:7000
#提示,我們要分多少個槽點,由于8000上有4096個槽點,所以這里填寫4096
How many slots do you want to move (from 1 to 16384)? 4096
#提示我們,需要移動到哪個id上,那就選擇移動到8002主節點上
What is the receiving node ID? 3cc268dfbb918a99159900643b318ec87ba03ad9
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:
#這里就是關鍵了,他要我們從哪個節點去轉移數據到8002,因為我們是要移除8000的,所以,我們就得填寫8000節點的id了:
Source node #1:4debd0b5743826d203d1af777824eb1b83105d21
Source node #2:done //輸入done命令,表示結束
Do you want to proceed with the proposed reshard plan (yes/no)? yes //輸入yes
ok,這樣8000主節點中原有的數據就遷移成功了。
我們檢查一下節點的狀態:
[root@redis-01 ~]# redis-trib.rb check 172.16.1.100:7000
>>> Performing Cluster Check (using node 172.16.1.100:7000)
S: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots: (0 slots) slave
replicates 3cc268dfbb918a99159900643b318ec87ba03ad9
S: 4ffabff843d32364fc506f3445980f5a04aa4292 172.16.1.110:8003
slots: (0 slots) slave
replicates edd51c8389ba069d49fe54c24c535716ce06e62b
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
M: edd51c8389ba069d49fe54c24c535716ce06e62b 172.16.1.100:7003
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
1 additional replica(s)
M: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots:1365-5460,6827-10922 (8192 slots) master
2 additional replica(s)
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: d161ab43746405c2b517e3ffc98321956431191c 172.16.1.100:7002
slots: (0 slots) slave
replicates 3cc268dfbb918a99159900643b318ec87ba03ad9
M: 4debd0b5743826d203d1af777824eb1b83105d21 172.16.1.110:8000
slots: (0 slots) master
0 additional replica(s)
//可以看到8000節點上的slots已經為0,而它上邊的slots已經遷移到了8002節點上了。
#現在重新對8000主節點進行移除操作:
[root@redis-02 ~]# redis-trib.rb del-node 172.16.1.110:8000 4debd0b5743826d203d1af777824eb1b83105d21
>>> Removing node 4debd0b5743826d203d1af777824eb1b83105d21 from cluster 172.16.1.110:8000
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
[root@redis-02 ~]# redis-trib.rb check 172.16.1.110:8000
[ERR] Sorry, can't connect to node 172.16.1.110:8000
ok,主節點移除成功。
2,移除從節點
移除一個從節點就簡單多了,因為不需要考慮數據的遷移,我們將7002這個從節點給移除:
[root@redis-02 ~]# redis-trib.rb del-node 172.16.1.100:7002 d161ab43746405c2b517e3ffc98321956431191c
>>> Removing node d161ab43746405c2b517e3ffc98321956431191c from cluster 172.16.1.100:7002
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
//提示7002從節點已經成功移除。
[root@redis-02 ~]# redis-trib.rb check 172.16.1.100:7000 //檢查當前集群的狀態信息
>>> Performing Cluster Check (using node 172.16.1.100:7000)
S: 8613a457f8009aaf784df0ac6d7039034b16b6a6 172.16.1.100:7000
slots: (0 slots) slave
replicates 3cc268dfbb918a99159900643b318ec87ba03ad9
S: 4ffabff843d32364fc506f3445980f5a04aa4292 172.16.1.110:8003
slots: (0 slots) slave
replicates edd51c8389ba069d49fe54c24c535716ce06e62b
S: 948421116dd1859002c78a2df0b9845bdc7db631 172.16.1.110:8001
slots: (0 slots) slave
replicates 5721b77733b1809449c6fc5806f38f1cacb1de8c
M: edd51c8389ba069d49fe54c24c535716ce06e62b 172.16.1.100:7003
slots:0-1364,5461-6826,10923-12287 (4096 slots) master
1 additional replica(s)
M: 3cc268dfbb918a99159900643b318ec87ba03ad9 172.16.1.110:8002
slots:1365-5460,6827-10922 (8192 slots) master
1 additional replica(s)
M: 5721b77733b1809449c6fc5806f38f1cacb1de8c 172.16.1.100:7001
slots:12288-16383 (4096 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
以上就是redis高可用集群的詳細內容了,看完之后是否有所收獲呢?如果想了解更多相關內容,歡迎關注億速云行業資訊!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。