cluster-require-full-coverage <yes/no>:默认情况下当集群中16384个槽,有任何一个没有指派到节点时,整个集群是不可用的。对应在线上,如果某个主节点宕机,而又没有从节点的话,是不允许对外提供服务的。建议将该参数设置为no,避免某个主节点的故障导致其它主节点不可用。
Redis Cluster的相关命令
CLUSTER ADDSLOTS slot [slot ...]:对当前节点手动分配slot。
CLUSTER MEET ip port:将其它节点添加到Redis Cluster中。
CLUSTER INFO:打印Cluster的相关信息。
# redis-cli -c 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:702
cluster_stats_messages_pong_sent:664
cluster_stats_messages_sent:1366
cluster_stats_messages_ping_received:659
cluster_stats_messages_pong_received:702
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:1366
CLUSTER KEYSLOT key:查看key对应的slot
127.0.0.1:6379> cluster keyslot hello
(integer) 866
127.0.0.1:6379> cluster keyslot world
(integer) 9059
127.0.0.1:6379> cluster keyslot hello{tag}
(integer) 8338
127.0.0.1:6379> cluster keyslot world{tag}
(integer) 8338
CLUSTER NODES:获取Cluster的节点信息,与当前节点的集群配置文件中的内容基本一致,只不过后者还会维护当前节点的配置纪元。
[root@slowtech conf]# redis-cli -p 6380 -c cluster nodes
72969ae6214dce5783d5b13b1bad34701303e96c 127.0.0.1:6382@16382 slave 7396e133fd8143335d5991734e68fcfcfc5adfd1 0 1539594959692 4 connected
a0efce44c96f95b2cdaf1101805710f41dfe4d06 127.0.0.1:6381@16381 master - 0 1539594962724 3 connected 10923-16383
276cf1128c50faa81a6b073079cc5e2c7a51a4ec 127.0.0.1:6380@16380 myself,master - 0 1539594958000 2 connected 5461-10922
b39826ebe9e741c8dc1fea7ee6966a42c5030726 127.0.0.1:6384@16384 slave a0efce44c96f95b2cdaf1101805710f41dfe4d06 0 1539594961000 6 connected
81f99ce264626895e30a5030ac27b84efedfa622 127.0.0.1:6383@16383 slave 276cf1128c50faa81a6b073079cc5e2c7a51a4ec 0 1539594961713 5 connected
7396e133fd8143335d5991734e68fcfcfc5adfd1 127.0.0.1:6379@16379 master - 0 1539594960703 1 connected 0-5460
[root@slowtech conf]# cat nodes-6380.conf
72969ae6214dce5783d5b13b1bad34701303e96c 127.0.0.1:6382@16382 slave 7396e133fd8143335d5991734e68fcfcfc5adfd1 0 1539592972569 4 connected
a0efce44c96f95b2cdaf1101805710f41dfe4d06 127.0.0.1:6381@16381 master - 0 1539592969000 3 connected 10923-16383
276cf1128c50faa81a6b073079cc5e2c7a51a4ec 127.0.0.1:6380@16380 myself,master - 0 1539592969000 2 connected 5461-10922
b39826ebe9e741c8dc1fea7ee6966a42c5030726 127.0.0.1:6384@16384 slave a0efce44c96f95b2cdaf1101805710f41dfe4d06 0 1539592971000 6 connected
81f99ce264626895e30a5030ac27b84efedfa622 127.0.0.1:6383@16383 slave 276cf1128c50faa81a6b073079cc5e2c7a51a4ec 0 1539592971000 5 connected
7396e133fd8143335d5991734e68fcfcfc5adfd1 127.0.0.1:6379@16379 master - 0 1539592971558 1 connected 0-5460
vars currentEpoch 6 lastVoteEpoch 0
CLUSTER REPLICATE node-id:在对应的从节点上执行,后面接的是主节点的节点ID。
CLUSTER SLAVES node-id:查看某个节点的从节点。
[root@slowtech conf]# redis-cli -c cluster slaves a0efce44c96f95b2cdaf1101805710f41dfe4d06
1) "b39826ebe9e741c8dc1fea7ee6966a42c5030726 127.0.0.1:6384@16384 slave a0efce44c96f95b2cdaf1101805710f41dfe4d06 0 1539596409000 6 connected"
[root@slowtech conf]# redis-cli -c cluster slaves b39826ebe9e741c8dc1fea7ee6966a42c5030726
(error) ERR The specified node is not a master
CLUSTER SLOTS:输出slot与节点的映射关系。
# redis-cli cluster slots
1) 1) (integer) 5461
2) (integer) 10922
3) 1) "127.0.0.1"
2) (integer) 6380
3) "276cf1128c50faa81a6b073079cc5e2c7a51a4ec"
4) 1) "127.0.0.1"
2) (integer) 6383
3) "81f99ce264626895e30a5030ac27b84efedfa622"
2) 1) (integer) 0
2) (integer) 5460
3) 1) "127.0.0.1"
2) (integer) 6379
3) "7396e133fd8143335d5991734e68fcfcfc5adfd1"
4) 1) "127.0.0.1"
2) (integer) 6382
3) "72969ae6214dce5783d5b13b1bad34701303e96c"
3) 1) (integer) 10923
2) (integer) 16383
3) 1) "127.0.0.1"
2) (integer) 6381
3) "a0efce44c96f95b2cdaf1101805710f41dfe4d06"
4) 1) "127.0.0.1"
2) (integer) 6384
3) "b39826ebe9e741c8dc1fea7ee6966a42c5030726"
READONLY:默认情况下,从节点不对外提供读服务,即使收到了读请求,也会重定向到对应的主节点。若要读节点对外提供读服务,可执行readonly。
# redis-cli -p 6382
127.0.0.1:6382> get k3
(error) MOVED 4576 127.0.0.1:6379
127.0.0.1:6382> readonly
OK
127.0.0.1:6382> get k3
"hello"
READWRITE: 关闭READONLY选项。