Redis集羣的關閉與重啓

1、注意

[root@master bin]# ./redis-cli --cluster create 192.168.230.21:7001 192.168.230.21:7002 192.168.230.21:7003 192.168.230.21:8001 192.168.230.21:8002 192.168.230.21:8003 --cluster-replicas 1 -a 123456

上面的命令只能在新創健集羣的時候執行一次,目的是爲了建立內部各個節點的對應關係,比如主從關係,這些關係僅且只能在一個集羣中初始化時對應一次;

如果再此執行,則會出現如下錯誤:

[root@master bin]# ./redis-cli --cluster create 192.168.230.21:7001 192.168.230.21:7002 192.168.230.21:7003 192.168.230.21:8001 192.168.230.21:8002 192.168.230.21:8003 --cluster-replicas 1 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
[ERR] Node 192.168.230.21:7001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

2、集羣關閉

集羣關閉直接將各個節點的進程kill掉即可;

[root@master bin]# ps -ef | grep redis
root      11516      1  0 16:15 ?        00:00:10 ./redis-server 192.168.230.21:7002 [cluster]
root      11521      1  0 16:15 ?        00:00:09 ./redis-server 192.168.230.21:7003 [cluster]
root      11526      1  0 16:15 ?        00:00:10 ./redis-server 192.168.230.21:8001 [cluster]
root      11531      1  0 16:15 ?        00:00:10 ./redis-server 192.168.230.21:8002 [cluster]
root      11536      1  0 16:15 ?        00:00:10 ./redis-server 192.168.230.21:8003 [cluster]
root      11869      1  0 16:33 ?        00:00:07 ./redis-server 192.168.230.21:7001 [cluster]
root      12528   9737  0 17:39 pts/7    00:00:00 grep --color=auto redis
[root@master bin]# kill -9 11516
[root@master bin]# kill -9 11521
[root@master bin]# kill -9 11526
[root@master bin]# kill -9 11531
[root@master bin]# kill -9 11536
[root@master bin]# kill -9 11869
[root@master bin]# ps -ef | grep redis
root      12552   9737  0 17:40 pts/7    00:00:00 grep --color=auto redis

3、集羣開啓及連接

(1)集羣開啓

[root@master bin]# ./redis-server /opt/softWare/redis-cluster/redis01/redis.conf 
12553:C 31 Mar 2020 17:40:59.875 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12553:C 31 Mar 2020 17:40:59.875 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=12553, just started
12553:C 31 Mar 2020 17:40:59.875 # Configuration loaded
[root@master bin]# ./redis-server /opt/softWare/redis-cluster/redis02/redis.conf 
12558:C 31 Mar 2020 17:41:03.697 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12558:C 31 Mar 2020 17:41:03.697 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=12558, just started
12558:C 31 Mar 2020 17:41:03.697 # Configuration loaded
[root@master bin]# ./redis-server /opt/softWare/redis-cluster/redis03/redis.conf 
12563:C 31 Mar 2020 17:41:06.702 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12563:C 31 Mar 2020 17:41:06.702 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=12563, just started
12563:C 31 Mar 2020 17:41:06.702 # Configuration loaded
[root@master bin]# ./redis-server /opt/softWare/redis-cluster/redis04/redis.conf 
12568:C 31 Mar 2020 17:41:09.742 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12568:C 31 Mar 2020 17:41:09.742 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=12568, just started
12568:C 31 Mar 2020 17:41:09.742 # Configuration loaded
[root@master bin]# ./redis-server /opt/softWare/redis-cluster/redis05/redis.conf 
12574:C 31 Mar 2020 17:41:12.760 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12574:C 31 Mar 2020 17:41:12.760 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=12574, just started
12574:C 31 Mar 2020 17:41:12.760 # Configuration loaded
[root@master bin]# ./redis-server /opt/softWare/redis-cluster/redis06/redis.conf 
12580:C 31 Mar 2020 17:41:16.406 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12580:C 31 Mar 2020 17:41:16.406 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=12580, just started
12580:C 31 Mar 2020 17:41:16.406 # Configuration loaded
[root@master bin]# ps -ef | grep redis
root      12554      1  0 17:40 ?        00:00:00 ./redis-server 192.168.230.21:7001 [cluster]
root      12559      1  0 17:41 ?        00:00:00 ./redis-server 192.168.230.21:7002 [cluster]
root      12564      1  0 17:41 ?        00:00:00 ./redis-server 192.168.230.21:7003 [cluster]
root      12569      1  0 17:41 ?        00:00:00 ./redis-server 192.168.230.21:8001 [cluster]
root      12575      1  0 17:41 ?        00:00:00 ./redis-server 192.168.230.21:8002 [cluster]
root      12581      1  0 17:41 ?        00:00:00 ./redis-server 192.168.230.21:8003 [cluster]
root      12587   9737  0 17:41 pts/7    00:00:00 grep --color=auto redis

(2)集羣連接

[root@master bin]# ./redis-cli -p 7001 -a 123456 -h 192.168.230.21 -a 123456 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.230.21:7001> DBSIZE
(integer) 2
192.168.230.21:7001> keys *
1) "aa"
2) "ss"
192.168.230.21:7001> set str STR
-> Redirected to slot [6928] located at 192.168.230.21:7002
OK
192.168.230.21:7002>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章