[root@localhost tomcatData]# docker run -d --name redis-node-1 --net host --privileged=true -v /redis/redis-node-1:/data redis --cluster-enabled yes --appendonly yes --port 6379
7f597842ac768d5d25124f560a1fd07488b29c44b2d7bf35560701ad52157aa6
[root@localhost tomcatData]# docker run -d --name redis-node-2 --net host --privileged=true -v /redis/redis-node-2:/data redis --cluster-enabled yes --appendonly yes --port 6380
72dbd4eef385a6dd521b8167619542b7b75d049dc306ef33c4478537f5ee8153
[root@localhost tomcatData]# docker run -d --name redis-node-3 --net host --privileged=true -v /redis/redis-node-3:/data redis --cluster-enabled yes --appendonly yes --port 6381
b385ca96ea0d29ad7d5dda0f1ab69d2d359e6009587d83500f2c586ef656b319
[root@localhost tomcatData]# docker run -d --name redis-node-4 --net host --privileged=true -v /redis/redis-node-4:/data redis --cluster-enabled yes --appendonly yes --port 6382
808b5e0c9ddb7736e0855644b917da05ad0ec307a4b1eb39b967ccb3edff1ed5
[root@localhost tomcatData]# docker run -d --name redis-node-5 --net host --privileged=true -v /redis/redis-node-5:/data redis --cluster-enabled yes --appendonly yes --port 6383
9a7156a41bc4abe6edb0f45354dc1aa1a812e2c8a667ea53036f66690317ba51
[root@localhost tomcatData]# docker run -d --name redis-node-6 --net host --privileged=true -v /redis/redis-node-6:/data redis --cluster-enabled yes --appendonly yes --port 6384
8016db0a503c2563fe06433d347191c84388d39f7d4cefec069e1e2bfe8ca07f
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
54734fb05ac1 redis "docker-entrypoint.s…" 2 minutes ago Up 2 minutes redis-node-6
a9830d1571ff redis "docker-entrypoint.s…" 2 minutes ago Up 2 minutes redis-node-5
111f4e7b1888 redis "docker-entrypoint.s…" 2 minutes ago Up 2 minutes redis-node-4
304aee9902f3 redis "docker-entrypoint.s…" 3 minutes ago Up 3 minutes redis-node-3
4b58839a75fe redis "docker-entrypoint.s…" 3 minutes ago Up 3 minutes redis-node-2
615e92e7c167 redis "docker-entrypoint.s…" 4 minutes ago Exited (1) 4 minutes ago redis-node-1
04ba18605068 redis "docker-entrypoint.s…" 13 hours ago Up 13 hours 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp myredis
983cab77b3f3 mysql "docker-entrypoint.s…" 3 days ago Exited (0) 13 hours ago mysql3131
dbc4fa32de95 registry "/entrypoint.sh /etc…" 3 days ago Created distracted_knuth
96afa0e2bb9c registry "/entrypoint.sh /etc…" 3 days ago Created xenodochial_babbage
命令格式: --cluster-replicas 1 表示为每个master创建一个slave节点
redis-cli --cluster create 192.168.216.130:6378 192.168.216.130:6380 192.168.216.130:6381 192.168.216.130:6382 192.168.216.130:6383 192.168.216.130:6384 --cluster-replicas 1
root@localhost:/data# redis-cli --cluster create 192.168.216.130:6378 192.168.216.130:6380 192.168.216.130:6381 192.168.216.130:6382 192.168.216.130:6383 192.168.216.130:6384 --cluster-replicas 1
>>> 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.216.130:6383 to 192.168.216.130:6378
Adding replica 192.168.216.130:6384 to 192.168.216.130:6380
Adding replica 192.168.216.130:6382 to 192.168.216.130:6381
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: ec8c48e4fa51f203c6e0bc5956fb575b9f7b84ab 192.168.216.130:6378
slots:[0-5460] (5461 slots) master
M: db7c89c11e63efe5293508f2a7a5cd39316a4efc 192.168.216.130:6380
slots:[5461-10922] (5462 slots) master
M: affd3d49af6e0a650e0d7990b100f37da0adb9d3 192.168.216.130:6381
slots:[10923-16383] (5461 slots) master
S: a4687fbc50556343b1f71d2179a57249415ab00a 192.168.216.130:6382
replicates db7c89c11e63efe5293508f2a7a5cd39316a4efc
S: 3967b0ec029eeb11d7a2549dad21e0697fc23e7a 192.168.216.130:6383
replicates affd3d49af6e0a650e0d7990b100f37da0adb9d3
S: 9e34bb0683ca49ae6fd680888c1c405261553d81 192.168.216.130:6384
replicates ec8c48e4fa51f203c6e0bc5956fb575b9f7b84ab
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.216.130:6378)
M: ec8c48e4fa51f203c6e0bc5956fb575b9f7b84ab 192.168.216.130:6378
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: db7c89c11e63efe5293508f2a7a5cd39316a4efc 192.168.216.130:6380
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: a4687fbc50556343b1f71d2179a57249415ab00a 192.168.216.130:6382
slots: (0 slots) slave
replicates db7c89c11e63efe5293508f2a7a5cd39316a4efc
S: 3967b0ec029eeb11d7a2549dad21e0697fc23e7a 192.168.216.130:6383
slots: (0 slots) slave
replicates affd3d49af6e0a650e0d7990b100f37da0adb9d3
M: affd3d49af6e0a650e0d7990b100f37da0adb9d3 192.168.216.130:6381
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 9e34bb0683ca49ae6fd680888c1c405261553d81 192.168.216.130:6384
slots: (0 slots) slave
replicates ec8c48e4fa51f203c6e0bc5956fb575b9f7b84ab
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
命令格式:redis-cli --cluster check 【本台redis自己的IP】:【本台redis自己的端口】
redis-cli --cluster check 192.168.216.130:6378
root@localhost:/data# redis-cli --cluster check 192.168.216.130:6378
192.168.216.130:6378 (ec8c48e4...) -> 0 keys | 5461 slots | 1 slaves.
192.168.216.130:6380 (db7c89c1...) -> 0 keys | 5462 slots | 1 slaves.
192.168.216.130:6381 (affd3d49...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.216.130:6378)
M: ec8c48e4fa51f203c6e0bc5956fb575b9f7b84ab 192.168.216.130:6378
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: db7c89c11e63efe5293508f2a7a5cd39316a4efc 192.168.216.130:6380
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: a4687fbc50556343b1f71d2179a57249415ab00a 192.168.216.130:6382
slots: (0 slots) slave
replicates db7c89c11e63efe5293508f2a7a5cd39316a4efc
S: 3967b0ec029eeb11d7a2549dad21e0697fc23e7a 192.168.216.130:6383
slots: (0 slots) slave
replicates affd3d49af6e0a650e0d7990b100f37da0adb9d3
M: affd3d49af6e0a650e0d7990b100f37da0adb9d3 192.168.216.130:6381
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 9e34bb0683ca49ae6fd680888c1c405261553d81 192.168.216.130:6384
slots: (0 slots) slave
replicates ec8c48e4fa51f203c6e0bc5956fb575b9f7b84ab
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
加参数 -c ,防止路由失效
root@localhost:/data# redis-cli -p 6379 -c
127.0.0.1:6379> get name
-> Redirected to slot [5798] located at 192.168.216.130:6380
"zhangsan"
192.168.216.130:6380>