#檢查 Cluster 情況 (未登入 Redis node 時):
redis-cli --cluster check <redis node domain or IP>:<port>
範例:
redis-cli --cluster check xxx.xxx.xxx:6379
修復 Redis Server Cluster Slot 分配不正常等 node 問題:
redis-cli --cluster fix xxx.xxx.xxx:6379
回應範例(以下為三組 Master node 和 Slave node,實際上可能會有更多組):
xxx.xxx.xxx:6379 (1ba418d4...) -> 4 keys | 5461 slots | 1 slaves. xxx.xxx.xxx:6381 (4131a66e...) -> 4 keys | 5461 slots | 1 slaves. xxx.xxx.xxx:6380 (ba5a4554...) -> 4 keys | 5462 slots | 1 slaves. [OK] 12 keys in 3 masters. 0.00 keys per slot on average. >>> Performing Cluster Check (using node xxx.xxx.xxx:6379) M: 1ba418d421ac322943423091360c909a549b3d39 xxx.xxx.xxx:6379 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 431b199172871c4c61f4e2f48ed1b9117dd3e801 xxx.xxx.xxx:6384 slots: (0 slots) slave replicates 1ba418d421ac322943423091360c909a549b3d39 S: 2fb427cf8acb3521c67c45fc2cfe1ac2a669a3c0 xxx.xxx.xxx:6383 slots: (0 slots) slave replicates 4131a66e5cadfd91c48b824d5288ddb1445d8bd1 M: 4131a66e5cadfd91c48b824d5288ddb1445d8bd1 xxx.xxx.xxx:6381 slots:[10923-16383] (5461 slots) master 1 additional replica(s) M: ba5a4554bc90d750de37a5da39b93dca896bab72 xxx.xxx.xxx:6380 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: 70712afa54623608772bafd1926305e895d7d076 xxx.xxx.xxx:6382 slots: (0 slots) slave replicates ba5a4554bc90d750de37a5da39b93dca896bab72 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
在回應中, "M" 代表 Master node、"S" 代表依附於 Master node 的 "Slave
node",
Slave node 的 replicates 值指出了它依附的是哪一個 Master node
Slave node 的 replicates 值指出了它依附的是哪一個 Master node
#登入 Redis node (會進入 Redis 互動 command line 模式,"-c" 代表 Cluster Mode):
redis-cli -h xxx.xxx.xxx -p 6379 -c
#查看 Cluster 狀態(登入 Redis node 後):
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:6 cluster_my_epoch:1 cluster_stats_messages_ping_sent:3649 cluster_stats_messages_pong_sent:3775 cluster_stats_messages_sent:7424 cluster_stats_messages_ping_received:3770 cluster_stats_messages_pong_received:3646 cluster_stats_messages_meet_received:5 cluster_stats_messages_received:7421 total_cluster_links_buffer_limit_exceeded:0
#啟動 Redis node:
redis-server <Redis config 檔的位置> --port <Redis node 的 port> --cluster-announce-ip "<Redis node 的 IP 或 hostname>"
範例:
redis-server /usr/local/etc/redis/redis.conf --port "6379" --cluster-announce-ip "xxx.xxx.xxx"
#建立 Redis Cluster:
redis-cli --cluster create <Redis node-1 IP or hostname:<port> <Redis node-2 IP or hostname:<port> ...<可多個 Redis node>....... --cluster-replicas <一個 Redis master node 要有幾個依附的 Redis slave node>
範例:
redis-cli --cluster create xxx.xxx.xxx:6379 xxx.xxx.xxx:6380 xxx.xxx.xxx:6381 xxx.xxx.xxx:6382 --cluster-replicas 1
#清除cluster中所有 node 的 key資料 (等同於對每個 cluster 中的所有 node 執行 flushall)
redis-cli --cluster call <cluster 中的任一node ip 或 hostname>:<Redis node 的 port> flushall
範例:
redis-cli --cluster call xxx.xxx.xxx:6379 flushall
沒有留言 :
張貼留言