1、正在运行的redis集群节点
[root@master bin]# ps -ef | grep redis
root 11511 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:7001 [cluster]
root 11516 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:7002 [cluster]
root 11521 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:7003 [cluster]
root 11526 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:8001 [cluster]
root 11531 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:8002 [cluster]
root 11536 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:8003 [cluster]
root 11550 9737 0 16:15 pts/7 00:00:00 grep --color=auto redis
2、redis主从节点信息
[root@master bin]# ./redis-cli -h 192.168.xxx.21 -p 7001 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.xxx.21:7001> cluster nodes
4eeb33782a53ef45bc27425b7552f59e32161beb 192.168.xxx.21:7002@17002 master - 0 1585643059000 2 connected 5461-10922
c0364456ceda977d64bc54a92cac8ba78a889ae6 192.168.xxx.21:8001@18001 slave f32e781fa533c13f3bf58fe30fb58d334fbaa745 0 1585643060849 4 connected
b079ecb2b9d1469db26cfd8e3e05f1878953c542 192.168.xxx.21:8003@18003 slave 34e977da07e02b7fb15d96ee30d9524058544991 0 1585643059842 6 connected
34e977da07e02b7fb15d96ee30d9524058544991 192.168.xxx.21:7003@17003 master - 0 1585643059000 3 connected 10923-16383
07e010fd2eb940097c89f0023ca26306ba1a7583 192.168.xxx.21:8002@18002 slave 4eeb33782a53ef45bc27425b7552f59e32161beb 0 1585643059000 5 connected
f32e781fa533c13f3bf58fe30fb58d334fbaa745 192.168.xxx.21:7001@17001 myself,master - 0 1585643058000 1 connected 0-5460
192.168.xxx.21:7001>
由此可知:主节点7001的从节点为8001;主节点7002的从节点为8002;主节点7003的从节点为8003;
3、连接redis并设置三个新值
[root@master bin]# ./redis-cli -p 7001 -a 123456 -h 192.168.xxx.21 -a 123456 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.xxx.21:7001> DBSIZE
(integer) 0
192.168.xxx.21:7001> set aa AA
OK
192.168.xxx.21:7001> set ss SS
OK
192.168.xxx.21:7001> set str STR
-> Redirected to slot [6928] located at 192.168.xxx.21:7002
OK
192.168.xxx.21:7002>
由上可见,key=aa,ss分到了7001节点插槽上了,key=str分到了7002插槽上了;
4、验证主从复制
[root@master bin]# ./redis-cli -h 192.168.xxx.21 -p 8001 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.xxx.21:8001> DBSIZE
(integer) 2
192.168.xxx.21:8001> keys *
1) "ss"
2) "aa"
192.168.xxx.21:8001>
[root@master bin]# ./redis-cli -h 192.168.xxx.21 -p 8002 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.xxx.21:8002> DBSIZE
(integer) 1
192.168.xxx.21:8002> keys *
1) "str"
192.168.xxx.21:8002>
5、验证7001主节点宕机
[root@master bin]# ps -ef | grep redis
root 11511 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:7001 [cluster]
root 11516 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:7002 [cluster]
root 11521 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:7003 [cluster]
root 11526 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:8001 [cluster]
root 11531 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:8002 [cluster]
root 11536 1 0 16:15 ? 00:00:00 ./redis-server 192.168.xxx.21:8003 [cluster]
root 11550 9737 0 16:15 pts/7 00:00:00 grep --color=auto redis
[root@master bin]# kill -9 11511
[root@master bin]# ps -ef | grep redis
root 11516 1 0 16:15 ? 00:00:01 ./redis-server 192.168.xxx.21:7002 [cluster]
root 11521 1 0 16:15 ? 00:00:01 ./redis-server 192.168.xxx.21:7003 [cluster]
root 11526 1 0 16:15 ? 00:00:01 ./redis-server 192.168.xxx.21:8001 [cluster]
root 11531 1 0 16:15 ? 00:00:01 ./redis-server 192.168.xxx.21:8002 [cluster]
root 11536 1 0 16:15 ? 00:00:01 ./redis-server 192.168.xxx.21:8003 [cluster]
8001由slave变为了master;
192.168.xxx.21:7002> set aa AA
-> Redirected to slot [1180] located at 192.168.xxx.21:8001
OK
192.168.xxx.21:8001>
由此可知,7001上的插槽也移动到了8001上;
6、恢复7001正常
[root@master bin]# ./redis-server /opt/softWare/redis-cluster/redis01/redis.conf
11868:C 31 Mar 2020 16:33:45.473 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11868:C 31 Mar 2020 16:33:45.473 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=11868, just started
11868:C 31 Mar 2020 16:33:45.473 # Configuration loaded
[root@master bin]# ps -ef | grep redis
root 11516 1 0 16:15 ? 00:00:02 ./redis-server 192.168.xxx.21:7002 [cluster]
root 11521 1 0 16:15 ? 00:00:02 ./redis-server 192.168.xxx.21:7003 [cluster]
root 11526 1 0 16:15 ? 00:00:02 ./redis-server 192.168.xxx.21:8001 [cluster]
root 11531 1 0 16:15 ? 00:00:02 ./redis-server 192.168.xxx.21:8002 [cluster]
root 11536 1 0 16:15 ? 00:00:02 ./redis-server 192.168.xxx.21:8003 [cluster]
root 11869 1 0 16:33 ? 00:00:00 ./redis-server 192.168.xxx.21:7001 [cluster]
由此可见,7001变为了8001的从节点;
综上:Redis集群HA和主从复制验证成功;