# 输入ping,如果每台redis都返回pong,说明配置成功
redis-cli -h10.0.0.16 -p6379-a'123456'
redis-cli -h10.0.0.15 -p6379-a'123456'
redis-cli -h10.0.0.14 -p6379-a'123456'
redis-cli -h10.0.0.13 -p6379-a'123456'
redis-cli -h10.0.0.12 -p6379-a'123456'
redis-cli -h10.0.0.11 -p6379-a'123456'
root@redis4:~# redis-cli -h 10.0.0.14 -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.14:6379>ping
PONG
10.0.0.14:6379>
3.创建集群
3.1创建集群
root@redis1:~# redis-cli -a 123456 --cluster create 10.0.0.11:6379 10.0.0.12:6379 10.0.0.13:6379 10.0.0.14:6379 10.0.0.15:6379 10.0.0.16:6379 --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 10.0.0.15:6379 to 10.0.0.11:6379
Adding replica 10.0.0.16:6379 to 10.0.0.12:6379
Adding replica 10.0.0.14:6379 to 10.0.0.13:6379
M: 849866f5d6959ef1c3f6d416f2f0db7345399f9c 10.0.0.11:6379
slots:[0-5460](5461 slots) master
M: d48cbb52775fd99f6c17a5e6d90fa21057c1edd6 10.0.0.12:6379
slots:[5461-10922](5462 slots) master
M: 9c9bed986328aeb72f6e9ecabb6fe76d8d86ae15 10.0.0.13:6379
slots:[10923-16383](5461 slots) master
S: 4fd9cd7e5cb078962ae2edd03444d50ed76ba41d 10.0.0.14:6379
replicates 9c9bed986328aeb72f6e9ecabb6fe76d8d86ae15
S: fbb2a0af5cadb72899284feaa4e11cd1cd922029 10.0.0.15:6379
replicates 849866f5d6959ef1c3f6d416f2f0db7345399f9c
S: 2a2c22e17408dee097ff99c285985f2bdeaf2e53 10.0.0.16:6379
replicates d48cbb52775fd99f6c17a5e6d90fa21057c1edd6
Can I set the above configuration? (type 'yes' to accept): yes>>> Nodes configuration updated
>>> Assign a different config epoch to each node>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join.>>> Performing Cluster Check (using node10.0.0.11:6379)
M: 849866f5d6959ef1c3f6d416f2f0db7345399f9c 10.0.0.11:6379
slots:[0-5460](5461 slots) master
1 additional replica(s)
S: 4fd9cd7e5cb078962ae2edd03444d50ed76ba41d 10.0.0.14:6379
slots: (0 slots) slave
replicates 9c9bed986328aeb72f6e9ecabb6fe76d8d86ae15
M: 9c9bed986328aeb72f6e9ecabb6fe76d8d86ae15 10.0.0.13:6379
slots:[10923-16383](5461 slots) master
1 additional replica(s)
M: d48cbb52775fd99f6c17a5e6d90fa21057c1edd6 10.0.0.12:6379
slots:[5461-10922](5462 slots) master
1 additional replica(s)
S: fbb2a0af5cadb72899284feaa4e11cd1cd922029 10.0.0.15:6379
slots: (0 slots) slave
replicates 849866f5d6959ef1c3f6d416f2f0db7345399f9c
S: 2a2c22e17408dee097ff99c285985f2bdeaf2e53 10.0.0.16:6379
slots: (0 slots) slave
replicates d48cbb52775fd99f6c17a5e6d90fa21057c1edd6
[OK] All nodes agree about slots configuration.
>>> Check foropen slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.``
3.2验证集群
3.2.1查看主从状态
主节点:role:master
root@redis1:~# redis-cli -c -h 10.0.0.11 -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.11:6379> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:18573bbf4a6219fa15f28781c6f17c16f63f98c0
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:8064
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:8064
从节点:role:slave
root@redis4:~# redis-cli -c -h 10.0.0.14 -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.14:6379> info replication
# Replication
role:slave
master_host:10.0.0.13
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_read_repl_offset:14
slave_repl_offset:14
master_link_down_since_seconds:-1
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:ecfb75ada6e667d04bf1662b116bde35341a97d3
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:14
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
3.2.2查看指定master节点的slave节点信息(查看对应关系)
root@redis1:~# redis-cli -c -h 10.0.0.11 -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.11:6379> cluster nodes
849866f5d6959ef1c3f6d416f2f0db7345399f9c 10.0.0.11:6379@16379 myself,master - 016702561700001 connected 0-5460
4fd9cd7e5cb078962ae2edd03444d50ed76ba41d 10.0.0.14:6379@16379 slave 9c9bed986328aeb72f6e9ecabb6fe76d8d86ae15 016702561710003 connected
9c9bed986328aeb72f6e9ecabb6fe76d8d86ae15 10.0.0.13:6379@16379 master - 016702561691353 connected 10923-16383
d48cbb52775fd99f6c17a5e6d90fa21057c1edd6 10.0.0.12:6379@16379 master - 016702561710002 connected 5461-10922
fbb2a0af5cadb72899284feaa4e11cd1cd922029 10.0.0.15:6379@16379 slave 849866f5d6959ef1c3f6d416f2f0db7345399f9c 016702561722181 connected
2a2c22e17408dee097ff99c285985f2bdeaf2e53 10.0.0.16:6379@16379 slave d48cbb52775fd99f6c17a5e6d90fa21057c1edd6 016702561711982 connected
10.0.0.11:6379>
3.2.3验证集群状态
root@redis2:~# redis-cli -h 10.0.0.11 -p 6379 -a 123456 CLUSTER INFO
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
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:709
cluster_stats_messages_pong_sent:777
cluster_stats_messages_sent:1486
cluster_stats_messages_ping_received:772
cluster_stats_messages_pong_received:709
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:1486
total_cluster_links_buffer_limit_exceeded:0
查看任意节点的集群状态
root@redis3:~# redis-cli -a 123456 --cluster info 10.0.0.12:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.0.0.12:6379 (d48cbb52...) ->0 keys |5462 slots |1 slaves.
10.0.0.11:6379 (849866f5...) ->0 keys |5461 slots |1 slaves.
10.0.0.13:6379 (9c9bed98...) ->0 keys |5461 slots |1 slaves.
[OK]0 keys in3 masters.
0.00 keys per slot on average.