redis集群命令及常規操作


集群命令

--cluster-search-multiple-owners

 

[root@redis06 etc]# redis-cli --cluster help
Cluster Manager Commands:
  create         host1:port1 ... hostN:portN   # 創建集群
                 --cluster-replicas <arg>      # 指定從節點數量
  check          host:port             # 檢查集群
          --cluster-search-multiple-owners # 檢查是否有slots同事唄分配給了多個節點 info host:port fix host:port reshard host:port
--cluster-from <arg> --cluster-to <arg> --cluster-slots <arg> --cluster-yes --cluster-timeout <arg> --cluster-pipeline <arg> rebalance host:port --cluster-weight <node1=w1...nodeN=wN> --cluster-use-empty-masters --cluster-timeout <arg> --cluster-simulate --cluster-pipeline <arg> --cluster-threshold <arg> add-node new_host:new_port existing_host:existing_port --cluster-slave --cluster-master-id <arg> del-node host:port node_id call host:port command arg arg .. arg set-timeout host:port milliseconds import host:port --cluster-from <arg> --cluster-copy --cluster-replace help For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

 

對集群進行重新分片

重新分片並不會對正在運行的集群程序產生任何影響,重新分片操作基本上就是將某些主節點上的哈希槽移動到另外一些主節點上面,和創建集群一樣

 

[root@redis01 etc]# redis-cli --cluster reshard 10.0.0.10:6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 10.0.0.10:6379)
M: bb273c158818c55f8f3ad0d0b2d971157fd56c90 10.0.0.10:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: ad58497a499e41df39d2f597e64beb046c5dc756 10.0.0.72:6379
   slots: (0 slots) slave
   replicates fc80f137ccb33e09fe33f2e3364de00bbbc4e888
S: 97c7b9789303a8f1eb8f8516ab0d598c304635b8 10.0.0.71:6379
   slots: (0 slots) slave
   replicates 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7
M: fc80f137ccb33e09fe33f2e3364de00bbbc4e888 10.0.0.61:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 312b3228330eff446e5c9c159182bcdcd61353c6 10.0.0.70:6379
   slots: (0 slots) slave
   replicates bb273c158818c55f8f3ad0d0b2d971157fd56c90
M: 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 10.0.0.60:6379
   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.
  • #輸入要移動的哈希槽數量 How many slots do you want to move (from 1 to 16384)? 1000

    #輸入哈希槽移入的源主節點
    What is the receiving node ID? 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 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.
    • # 輸入節點ID 如果輸入all 表示從所有主節點移動槽位到指定節點ID,如果輸入all,將直接移動哈希槽,輸入done直接退出 Source node #1: fc80f137ccb33e09fe33f2e3364de00bbbc4e888 Source node #2: done Ready to move 1000 slots. Source nodes: M: fc80f137ccb33e09fe33f2e3364de00bbbc4e888 10.0.0.61:6379 slots:[10923-16383] (5461 slots) master 1 additional replica(s) Destination node: M: 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 10.0.0.60:6379 slots:[5461-10922] (5462 slots) master 1 additional replica(s) Resharding plan: Moving slot 10923 from fc80f137ccb33e09fe33f2e3364de00bbbc4e888 Moving slot 10924 from fc80f137ccb33e09fe33f2e3364de00bbbc4e888 Moving slot 10925 from fc80f137ccb33e09fe33f2e3364de00bbbc4e888 Moving slot 10926 from fc80f137ccb33e09fe33f2e3364de00bbbc4e888 Moving slot 10927 from fc80f137ccb33e09fe33f2e3364de00bbbc4e888

  • # 是否執行重新分片計划

Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 10923 from 10.0.0.61:6379 to 10.0.0.60:6379:
Moving slot 10924 from 10.0.0.61:6379 to 10.0.0.60:6379:
Moving slot 10925 from 10.0.0.61:6379 to 10.0.0.60:6379:
Moving slot 10926 from 10.0.0.61:6379 to 10.0.0.60:6379:

查看重新分片后的哈希槽分配情況

[root@redis01 etc]# redis-cli -c -h 10.0.0.10 -p 6379 -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
ad58497a499e41df39d2f597e64beb046c5dc756 10.0.0.72:6379@16379 slave fc80f137ccb33e09fe33f2e3364de00bbbc4e888 0 1581333622773 8 connected
97c7b9789303a8f1eb8f8516ab0d598c304635b8 10.0.0.71:6379@16379 slave 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 0 1581333622567 7 connected
bb273c158818c55f8f3ad0d0b2d971157fd56c90 10.0.0.10:6379@16379 myself,master - 0 1581333609000 1 connected 458-5460
fc80f137ccb33e09fe33f2e3364de00bbbc4e888 10.0.0.61:6379@16379 master - 0 1581333621726 8 connected 0-457 5461-6002 11923-16383
312b3228330eff446e5c9c159182bcdcd61353c6 10.0.0.70:6379@16379 slave bb273c158818c55f8f3ad0d0b2d971157fd56c90 0 1581333621209 4 connected
5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 10.0.0.60:6379@16379 master - 0 1581333623293 7 connected 6003-11922

目標節點的哈希槽分為了三部分,前兩部分是從其他節點移動過來的

命令輸出的解釋:

  • 節點 ID :例如 3fc783611028b1707fd65345e763befb36454d73 。
  • ip:port :節點的 IP 地址和端口號, 例如 127.0.0.1:7000 , 其中 :0 表示的是客戶端當前連接的 IP 地址和端口號。
  • flags :節點的角色(例如 master 、 slave 、 myself )以及狀態(例如 fail ,等等)。
  • 如果節點是一個從節點的話, 那么跟在 flags 之后的將是主節點的節點 ID : 例如 127.0.0.1:7002 的主節點的節點 ID 就是 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e 。
  • 集群最近一次向節點發送 PING 命令之后, 過去了多長時間還沒接到回復。
  • 節點最近一次返回 PONG 回復的時間。
  • 節點的配置紀元(configuration epoch):詳細信息請參考 Redis 集群規范 。
  • 本節點的網絡連接情況:例如 connected 。
  • 節點目前包含的槽:例如 127.0.0.1:7001 目前包含號碼為 5960 至 10921 的哈希槽。

注意:(1)舊版本使用redis-trib.rb reshard 127.0.0.1:6379移動哈希槽

   (2)不能將主節點的哈希槽移動到從節點(從節點是只讀的)

[root@redis01 etc]# redis-cli -c -h 10.0.0.10 -p 6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.0.0.10:6379> quit
[root@redis01 etc]# redis-cli --cluster reshard 10.0.0.10:6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 10.0.0.10:6379)
M: bb273c158818c55f8f3ad0d0b2d971157fd56c90 10.0.0.10:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: ad58497a499e41df39d2f597e64beb046c5dc756 10.0.0.72:6379
   slots: (0 slots) slave
   replicates fc80f137ccb33e09fe33f2e3364de00bbbc4e888
S: 97c7b9789303a8f1eb8f8516ab0d598c304635b8 10.0.0.71:6379
   slots: (0 slots) slave
   replicates 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7
M: fc80f137ccb33e09fe33f2e3364de00bbbc4e888 10.0.0.61:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 312b3228330eff446e5c9c159182bcdcd61353c6 10.0.0.70:6379
   slots: (0 slots) slave
   replicates bb273c158818c55f8f3ad0d0b2d971157fd56c90
M: 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 10.0.0.60:6379
   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.
How many slots do you want to move (from 1 to 16384)? 1000
What is the receiving node ID? 97c7b9789303a8f1eb8f8516ab0d598c304635b8                  
*** The specified node (97c7b9789303a8f1eb8f8516ab0d598c304635b8) is not known or not a master, please retry.

redis集群健康狀態檢查

[root@redis06 etc]# redis-cli --cluster check 10.0.0.72:6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.0.0.72:6379 (ad58497a...) -> 0 keys | 5461 slots | 1 slaves.
10.0.0.60:6379 (5a6291fd...) -> 0 keys | 5920 slots | 1 slaves.
10.0.0.10:6379 (bb273c15...) -> 0 keys | 5003 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 10.0.0.72:6379)
M: ad58497a499e41df39d2f597e64beb046c5dc756 10.0.0.72:6379
   slots:[0-457],[5461-6002],[11923-16383] (5461 slots) master
   1 additional replica(s)
M: 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 10.0.0.60:6379
   slots:[6003-11922] (5920 slots) master
   1 additional replica(s)
S: 97c7b9789303a8f1eb8f8516ab0d598c304635b8 10.0.0.71:6379
   slots: (0 slots) slave
   replicates 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7
M: bb273c158818c55f8f3ad0d0b2d971157fd56c90 10.0.0.10:6379
   slots:[458-5460] (5003 slots) master
   1 additional replica(s)
S: 312b3228330eff446e5c9c159182bcdcd61353c6 10.0.0.70:6379
   slots: (0 slots) slave
   replicates bb273c158818c55f8f3ad0d0b2d971157fd56c90
S: fc80f137ccb33e09fe33f2e3364de00bbbc4e888 10.0.0.61:6379
   slots: (0 slots) slave
   replicates ad58497a499e41df39d2f597e64beb046c5dc756
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

當一組主、從節點都宕機時,會出現哈希槽無節點接管,導致集群不可用

# 將72和61這組節點宕機
[root@redis06 etc]# redis-cli -c -h 10.0.0.61 -p 6379 -a 123456 shutdown

[root@redis06 etc]# redis-cli -c -h 10.0.0.72 -p 6379 -a 123456 shutdown


# 檢測集群狀態
[root@redis06 etc]# redis-cli --cluster check 10.0.0.71:6379 -a 123456

Could not connect to Redis at 10.0.0.61:6379: Connection refused
Could not connect to Redis at 10.0.0.72:6379: Connection refused
10.0.0.70:6379 (312b3228...) -> 0 keys | 5003 slots | 1 slaves.
10.0.0.60:6379 (5a6291fd...) -> 0 keys | 5920 slots | 1 slaves.
[OK] 0 keys in 2 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 10.0.0.71:6379)
S: 97c7b9789303a8f1eb8f8516ab0d598c304635b8 10.0.0.71:6379
   slots: (0 slots) slave
   replicates 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7
M: 312b3228330eff446e5c9c159182bcdcd61353c6 10.0.0.70:6379
   slots:[458-5460] (5003 slots) master
   1 additional replica(s)
M: 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 10.0.0.60:6379
   slots:[6003-11922] (5920 slots) master
   1 additional replica(s)
S: bb273c158818c55f8f3ad0d0b2d971157fd56c90 10.0.0.10:6379
   slots: (0 slots) slave
   replicates 312b3228330eff446e5c9c159182bcdcd61353c6
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[ERR] Not all 16384 slots are covered by nodes.

查看集群信息
[root@redis06 etc]# redis-cli -c -h 10.0.0.10 -p 6379 -a 123456 cluster info

cluster_state:fail
cluster_slots_assigned:16384
cluster_slots_ok:10923
cluster_slots_pfail:0
cluster_slots_fail:5461
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:11
cluster_my_epoch:11
cluster_stats_messages_ping_sent:15829
cluster_stats_messages_pong_sent:1445
cluster_stats_messages_sent:17274
cluster_stats_messages_ping_received:1445
cluster_stats_messages_pong_received:1449
cluster_stats_messages_fail_received:6
cluster_stats_messages_update_received:2
cluster_stats_messages_received:2902


在10這台服務器上設置一個鍵
[root@redis01 etc]# redis-cli -c -h 10.0.0.10 -p 6379 -a 123456 

10.0.0.10:6379> set foo bar
(error) CLUSTERDOWN The cluster is down

故障節點重新上線

[root@redis06 etc]# redis-server redis.conf
[root@redis06 etc]# ss -lntp
State       Recv-Q Send-Q           Local Address:Port                          Peer Address:Port              
LISTEN      0      128                  10.0.0.72:6379                                     *:*                   users:(("redis-server",pid=2079,fd=6))
LISTEN      0      128                          *:22                                       *:*                   users:(("sshd",pid=756,fd=3))
LISTEN      0      100                  127.0.0.1:25                                       *:*                   users:(("master",pid=840,fd=13))
LISTEN      0      128                  10.0.0.72:16379                                    *:*                   users:(("redis-server",pid=2079,fd=9))
LISTEN      0      32                          :::21                                      :::*                   users:(("vsftpd",pid=764,fd=4))
LISTEN      0      128                         :::22                                      :::*                   users:(("sshd",pid=756,fd=4))
LISTEN      0      100                        ::1:25                                      :::*                   users:(("master",pid=840,fd=14))

[root@redis03 etc]# redis-server redis.conf
[root@redis03 etc]# ss -lntp
State       Recv-Q Send-Q           Local Address:Port                          Peer Address:Port              
LISTEN      0      128                  10.0.0.61:6379                                     *:*                   users:(("redis-server",pid=2143,fd=6))
LISTEN      0      128                          *:22                                       *:*                   users:(("sshd",pid=768,fd=3))
LISTEN      0      128                  10.0.0.61:16379                                    *:*                   users:(("redis-server",pid=2143,fd=9))
LISTEN      0      128                         :::22                                      :::*                   users:(("sshd",pid=768,fd=4))

# 再次檢測

[root@redis06 etc]# redis-cli --cluster check 10.0.0.71:6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.0.0.70:6379 (312b3228...) -> 0 keys | 5003 slots | 1 slaves.
10.0.0.60:6379 (5a6291fd...) -> 0 keys | 5920 slots | 1 slaves.
10.0.0.61:6379 (fc80f137...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 10.0.0.71:6379)
S: 97c7b9789303a8f1eb8f8516ab0d598c304635b8 10.0.0.71:6379
   slots: (0 slots) slave
   replicates 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7
M: 312b3228330eff446e5c9c159182bcdcd61353c6 10.0.0.70:6379
   slots:[458-5460] (5003 slots) master
   1 additional replica(s)
M: 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 10.0.0.60:6379
   slots:[6003-11922] (5920 slots) master
   1 additional replica(s)
S: bb273c158818c55f8f3ad0d0b2d971157fd56c90 10.0.0.10:6379
   slots: (0 slots) slave
   replicates 312b3228330eff446e5c9c159182bcdcd61353c6
M: fc80f137ccb33e09fe33f2e3364de00bbbc4e888 10.0.0.61:6379
   slots:[0-457],[5461-6002],[11923-16383] (5461 slots) master
   1 additional replica(s)
S: ad58497a499e41df39d2f597e64beb046c5dc756 10.0.0.72:6379
   slots: (0 slots) slave
   replicates fc80f137ccb33e09fe33f2e3364de00bbbc4e888
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 集群擴容和縮容和哈希槽操作命令

# 將 ip 和 port 所指定的節點添加到集群中
CLUSTER MEET <ip> <port>
# 從集群中移除 node_id 指定的節點
CLUSTER FORGET <node_id>

將當前節點設置為 node_id 指定的節點的從節點

CLUSTER REPLICATE <node_id>


6、將節點的配置文件保存到硬盤里面


CLUSTER SAVECONFIG


7、將一個或多個槽(slot)指派(assign)給當前節點


CLUSTER ADDSLOTS <slot> [slot ...]


8、移除一個或多個槽對當前節點的指派


CLUSTER DELSLOTS <slot> [slot ...]


9、 移除指派給當前節點的所有槽,讓當前節點變成一個沒有指派任何槽的節點


CLUSTER FLUSHSLOTS


10、將槽 slot 指派給 node_id 指定的節點,如果槽已經指派給另一個節點,那么先讓另一個節點刪除該槽>,然后再進行指派


CLUSTER SETSLOT <slot> NODE <node_id>



11、將本節點的槽 slot 遷移到 node_id 指定的節點中


CLUSTER SETSLOT <slot> MIGRATING <node_id>


12、從 node_id 指定的節點中導入槽 slot 到本節點


CLUSTER SETSLOT <slot> IMPORTING <node_id>


13、取消對槽 slot 的導入(import)或者遷移(migrate)


CLUSTER SETSLOT <slot> STABLE


14、計算鍵 key 應該被放置在哪個槽上

CLUSTER KEYSLOT <key>


15、返回槽 slot 目前包含的鍵值對數量


CLUSTER COUNTKEYSINSLOT <slot>


16、返回 count 個 slot 槽中的鍵


CLUSTER GETKEYSINSLOT <slot> <count>

測試從節點是否能進行故障切換

# 停掉一個主節點
[root@redis06 etc]# redis-cli -c -h 10.0.0.61 -p 6379 -a 123456 shutdown Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. [root@redis06 etc]# ss -lntp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 10.0.0.72:6379 *:* users:(("redis-server",pid=1973,fd=6)) LISTEN 0 128 *:22 *:* users:(("sshd",pid=756,fd=3)) LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=840,fd=13)) LISTEN 0 128 10.0.0.72:16379 *:* users:(("redis-server",pid=1973,fd=9)) LISTEN 0 32 :::21 :::* users:(("vsftpd",pid=764,fd=4)) LISTEN 0 128 :::22 :::* users:(("sshd",pid=756,fd=4)) LISTEN 0 100 ::1:25 :::* users:(("master",pid=840,fd=14))
[root@redis06 etc]# redis
-cli -c -h 10.0.0.61 -p 6379 -a 123456 cluster nodes Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. Could not connect to Redis at 10.0.0.61:6379: Connection refused
#查看集群狀態

[root@redis06 etc]# redis
-cli -c -h 10.0.0.72 -p 6379 -a 123456 cluster nodes Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 10.0.0.60:6379@16379 master - 0 1581337801101 7 connected 6003-11922 ad58497a499e41df39d2f597e64beb046c5dc756 10.0.0.72:6379@16379 myself,master - 0 1581337801000 9 connected 0-457 5461-6002 11923-16383 97c7b9789303a8f1eb8f8516ab0d598c304635b8 10.0.0.71:6379@16379 slave 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 0 1581337803166 7 connected bb273c158818c55f8f3ad0d0b2d971157fd56c90 10.0.0.10:6379@16379 master - 0 1581337802652 1 connected 458-5460 312b3228330eff446e5c9c159182bcdcd61353c6 10.0.0.70:6379@16379 slave bb273c158818c55f8f3ad0d0b2d971157fd56c90 0 1581337802134 4 connected fc80f137ccb33e09fe33f2e3364de00bbbc4e888 10.0.0.61:6379@16379 master,fail - 1581337776852 1581337775113 8 disconnected

宕機節點恢復

[root@redis03 etc]# ss -lntp
State       Recv-Q Send-Q           Local Address:Port                          Peer Address:Port              
LISTEN      0      128                          *:22                                       *:*                   users:(("sshd",pid=768,fd=3))
LISTEN      0      128                         :::22                                      :::*                   users:(("sshd",pid=768,fd=4))
[root@redis03 etc]# redis-server redis.conf
[root@redis03 etc]# ss -lntp
State       Recv-Q Send-Q           Local Address:Port                          Peer Address:Port              
LISTEN      0      128                  10.0.0.61:6379                                     *:*                   users:(("redis-server",pid=2109,fd=6))
LISTEN      0      128                          *:22                                       *:*                   users:(("sshd",pid=768,fd=3))
LISTEN      0      128                  10.0.0.61:16379                                    *:*                   users:(("redis-server",pid=2109,fd=9))
LISTEN      0      128                         :::22                                      :::*                   users:(("sshd",pid=768,fd=4))

查看集群狀態

[OK] All 16384 slots covered.
[root@redis06 etc]# redis-cli --cluster check 10.0.0.72:6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.0.0.72:6379 (ad58497a...) -> 0 keys | 5461 slots | 1 slaves.
10.0.0.60:6379 (5a6291fd...) -> 0 keys | 5920 slots | 1 slaves.
10.0.0.10:6379 (bb273c15...) -> 0 keys | 5003 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 10.0.0.72:6379)
M: ad58497a499e41df39d2f597e64beb046c5dc756 10.0.0.72:6379
   slots:[0-457],[5461-6002],[11923-16383] (5461 slots) master
   1 additional replica(s)
M: 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7 10.0.0.60:6379
   slots:[6003-11922] (5920 slots) master
   1 additional replica(s)
S: 97c7b9789303a8f1eb8f8516ab0d598c304635b8 10.0.0.71:6379
   slots: (0 slots) slave
   replicates 5a6291fd3fb00119ae4828f5b86554fe4f35a1a7
M: bb273c158818c55f8f3ad0d0b2d971157fd56c90 10.0.0.10:6379
   slots:[458-5460] (5003 slots) master
   1 additional replica(s)
S: 312b3228330eff446e5c9c159182bcdcd61353c6 10.0.0.70:6379
   slots: (0 slots) slave
   replicates bb273c158818c55f8f3ad0d0b2d971157fd56c90
S: fc80f137ccb33e09fe33f2e3364de00bbbc4e888 10.0.0.61:6379
   slots: (0 slots) slave
   replicates ad58497a499e41df39d2f597e64beb046c5dc756
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

計數器測試集群一致性

consistency-test.rb創建了多個計數器(默認為 1000 個), 並通過發送 INCR key 命令來增加這些計數器的值。在增加計數器值的同時, consistency-test.rb 還執行以下操作:

    每次使用 INCR key 命令更新一個計數器時, 應用會記錄下計數器執行 INCR key 命令之后應該有的值。 舉個例子, 如果計數器的起始值為 0 , 而這次是程序第 50 次向它發送 INCR key 命令, 那么計數器的值應該是 50 。
    在每次發送 INCR key 命令之前, 程序會隨機從集群中讀取一個計數器的值, 並將它與自己記錄的值進行對比, 看兩個值是否相同。

換句話說, 這個程序是一個一致性檢查器(consistency checker): 
如果集群在執行 INCR key 命令的過程中, 丟失了某條 INCR key 命令, 又或者多執行了某條客戶端沒有確認到的 INCR key 命令, 那么檢查器將察覺到這一點
-----在前一種情況中, consistency-test.rb 記錄的計數器值將比集群記錄的計數器值要大; 而在后一種情況中, consistency-test.rb 記錄的計數器值將比集群記錄的計數器值要小。

安裝ruby

[root@redis06 etc]# yum install -y ruby ruby-devel rubygems rpm-build

 [root@redis06 etc]# ruby -v
 ruby 2.0.0p648 (2015-12-16) [x86_64-linux]

報錯,需要安裝高版本ruby

[root@redis06 etc]# gem install redis
Fetching: redis-4.1.3.gem (100%)
ERROR:  Error installing redis:
    redis requires Ruby version >= 2.3.0.

使用rvm安裝ruby

[root@redis01 etc]# curl -sSL https://get.rvm.io | bash -s stable
curl: (35) TCP connection reset by peer

[root@redis01 etc]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpg: requesting key 39499BDB from hkp server keys.gnupg.net
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: key 39499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 2
gpg:               imported: 2  (RSA: 2)

[root@redis01 etc]# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc
gpg: Signature made Wed 10 Jul 2019 04:31:02 AM EDT using RSA key ID 39499BDB
gpg: Good signature from "Piotr Kuczynski <piotr.kuczynski@gmail.com>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.9.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
  * Please do NOT forget to add your users to the rvm group.
     The installer no longer auto-adds root or users to the rvm group. Admins must do this.
     Also, please note that group memberships are ONLY evaluated at login time.
     This means that users must log out then back in before group membership takes effect!
Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

👉  Donate: https://opencollective.com/rvm/donate

讀取環境變量

[root@redis06 etc]# source /etc/profile.d/rvm.sh

安裝一個2.3以上的版本

[root@redis06 etc]# rvm install 2.6.3

指定默認版本

[root@redis06 etc]# rvm use 2.6.3 --default
Using /usr/local/rvm/gems/ruby-2.6.3

[root@redis06 redis-rb-cluster-master]# gem install redis
Fetching redis-4.1.3.gem
Successfully installed redis-4.1.3
Parsing documentation for redis-4.1.3
Installing ri documentation for redis-4.1.3
Done installing documentation for redis after 0 seconds
1 gem installed



解壓軟件包

[root@redis06 softwares]# unzip redis-rb-cluster-master.zip -d ../module/redis-5.0.0/
Archive:  redis-rb-cluster-master.zip
9a5b39fec03fb16ebb9b1796334dd95fc034ac14
   creating: ../module/redis-5.0.0/redis-rb-cluster-master/
  inflating: ../module/redis-5.0.0/redis-rb-cluster-master/README.md  
  inflating: ../module/redis-5.0.0/redis-rb-cluster-master/cluster.rb  
  inflating: ../module/redis-5.0.0/redis-rb-cluster-master/consistency-test.rb  
  inflating: ../module/redis-5.0.0/redis-rb-cluster-master/crc16.rb  
  inflating: ../module/redis-5.0.0/redis-rb-cluster-master/example.rb  

[root@redis06 softwares]# cd ../module/redis-5.0.0/redis-rb-cluster-master/

[root@redis06 redis-rb-cluster-master]# ll
total 32
-rw-rw-r-- 1 root root 10412 Oct 28  2015 cluster.rb
-rw-rw-r-- 1 root root  4083 Oct 28  2015 consistency-test.rb
-rw-rw-r-- 1 root root  4127 Oct 28  2015 crc16.rb
-rw-rw-r-- 1 root root   688 Oct 28  2015 example.rb
-rw-rw-r-- 1 root root  2031 Oct 28  2015 README.md

關閉redis集群認證,並重啟集群

[root@redis06 redis-rb-cluster-master]# find / -name "redis.conf" |xargs sed -ri.bak 's@(^requirepass.*)@#&@'

[root@redis06 redis-rb-cluster-master]# pkill redis

[root@redis06 redis-rb-cluster-master]# redis-server ../../redis-5.0.0/etc/redis.conf

[root@redis06 redis-rb-cluster-master]# ruby consistency-test.rb 10.0.0.72 6379
116 R (0 err) | 116 W (0 err) | 
1034 R (0 err) | 1034 W (0 err) | 
1948 R (0 err) | 1948 W (0 err) | 
2785 R (0 err) | 2785 W (0 err) | 
3622 R (0 err) | 3622 W (0 err) | 
4443 R (0 err) | 4443 W (0 err) | 
5253 R (0 err) | 5253 W (0 err) | 
6095 R (0 err) | 6095 W (0 err) | 
6918 R (0 err) | 6918 W (0 err) | 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM