wget http://download.redis.io/releases/redis-6.0.0.tar.gz mkdir -p /data/software tar -zxvf redis-6.0.0.tar.gz -C /data/software cd /data/software/redis-6.0.0 make
# --cluster-replicas 1:为集群中的每个节点创建一个从节点 # -a 123456:指定密码 [root@localhost 6667]# src/redis-cli --cluster create 192.168.1.102:6666 192.168.1.103:6666 192.168.1.104:6666 192.168.1.102:6667 192.168.1.103:6667 192.168.1.104:6667 --cluster-replicas 1 -a 123456 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 192.168.1.103:6667 to 192.168.1.102:6666 Adding replica 192.168.1.104:6667 to 192.168.1.103:6666 Adding replica 192.168.1.102:6667 to 192.168.1.104:6666 M: 9b4d69b96870637bf09450c45eaacf423aedafb6 192.168.1.102:6666 slots:[0-5460] (5461 slots) master M: 588f93f38d8e8937d2e458f32f130c8c5ca7a9f7 192.168.1.103:6666 slots:[5461-10922] (5462 slots) master M: ecb366aec1d0b7a709a55230d0488ca11bf56403 192.168.1.104:6666 slots:[10923-16383] (5461 slots) master S: cd237e96d59187e0472d103ce22d655bc23ca570 192.168.1.102:6667 replicates ecb366aec1d0b7a709a55230d0488ca11bf56403 S: 382d9791ab78fca6b1e4b150324bad138b312848 192.168.1.103:6667 replicates 9b4d69b96870637bf09450c45eaacf423aedafb6 S: e13a50aa9068480aa65b258791bf2ec885505f41 192.168.1.104:6667 replicates 588f93f38d8e8937d2e458f32f130c8c5ca7a9f7 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 node 192.168.1.102:6666) M: 9b4d69b96870637bf09450c45eaacf423aedafb6 192.168.1.102:6666 slots:[0-5460] (5461 slots) master 1 additional replica(s) M: 588f93f38d8e8937d2e458f32f130c8c5ca7a9f7 192.168.1.103:6666 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: e13a50aa9068480aa65b258791bf2ec885505f41 192.168.1.104:6667 slots: (0 slots) slave replicates 588f93f38d8e8937d2e458f32f130c8c5ca7a9f7 M: ecb366aec1d0b7a709a55230d0488ca11bf56403 192.168.1.104:6666 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: cd237e96d59187e0472d103ce22d655bc23ca570 192.168.1.102:6667 slots: (0 slots) slave replicates ecb366aec1d0b7a709a55230d0488ca11bf56403 S: 382d9791ab78fca6b1e4b150324bad138b312848 192.168.1.103:6667 slots: (0 slots) slave replicates 9b4d69b96870637bf09450c45eaacf423aedafb6 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
[root@localhost 6667]# redis-cli --cluster check 192.168.1.102:6666 -a 123456
测试
1 2 3 4 5 6 7 8 9 10
[root@localhost 6667]# src/redis-cli -h 192.168.1.102 -p 6666 -a 123456 -c Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 192.168.1.102:6666> set chen kaixin OK
[root@localhost 6667]# src/redis-cli -h 192.168.1.103 -p 6666 -a 123456 -c Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 192.168.1.103:6666> get chen -> Redirected to slot [2419] located at 192.168.1.102:6666 "kaixin"