redis6 docker下的集群配置

(1)  进行网络设置

docker network create --subnet=172.19.0.0/24 redis-net
build_one 6382 redis6382 172.19.0.2
build_one 6383 redis6383 172.19.0.3
build_one 6384 redis6384 172.19.0.4
build_one 6385 redis6385 172.19.0.5
build_one 6386 redis6386 172.19.0.6
build_one 6387 redis6387 172.19.0.7

Redis Cluster与Docker机制兼容。 如果在映射后的IP进行集群配置,会失败

方法1,如本文,进行内部网桥设置,进行不同IP,相同端口配置;

方法2,https://blog.csdn.net/x3499633/article/details/88637819 。进行--net host,进行相同 的IP,不同的端口。

总之,就是NAT后的端口就不行了。 

(2) 进行集群配置

root@localhost dockerOffline]# vi functions/run_clusterRedis.sh 
[root@localhost dockerOffline]# docker exec -it redis6382 redis-cli --cluster create 172.19.0.2:6380 172.19.0.3:6380 172.19.0.4:6380 172.19.0.5:6380 172.19.0.6:6380 172.19.0.7:6380 --cluster-replicas 1 -a gbcom@gidata@123
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 172.19.0.6:6380 to 172.19.0.2:6380
Adding replica 172.19.0.7:6380 to 172.19.0.3:6380
Adding replica 172.19.0.5:6380 to 172.19.0.4:6380
M: 38fd39736b47d9620047090b2e05274d4bc8b819 172.19.0.2:6380
   slots:[0-5460] (5461 slots) master
M: dfd6cd26c4a55ba50d47af2cf24fa81dbd70b7e5 172.19.0.3:6380
   slots:[5461-10922] (5462 slots) master
M: 6a4fa959afb87b03ced727d273f3421fa136a055 172.19.0.4:6380
   slots:[10923-16383] (5461 slots) master
S: 471cc558057354ccf6e1b6092b6d20ce368a1819 172.19.0.5:6380
   replicates 6a4fa959afb87b03ced727d273f3421fa136a055
S: e91fc9c30e9df6836e6ca622dbffc8ab6262272e 172.19.0.6:6380
   replicates 38fd39736b47d9620047090b2e05274d4bc8b819
S: 5d3ed6ed6eb03d52feffe592327f3c2aeded7337 172.19.0.7:6380
   replicates dfd6cd26c4a55ba50d47af2cf24fa81dbd70b7e5
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 172.19.0.2:6380)
M: 38fd39736b47d9620047090b2e05274d4bc8b819 172.19.0.2:6380
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 6a4fa959afb87b03ced727d273f3421fa136a055 172.19.0.4:6380
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: e91fc9c30e9df6836e6ca622dbffc8ab6262272e 172.19.0.6:6380
   slots: (0 slots) slave
   replicates 38fd39736b47d9620047090b2e05274d4bc8b819
S: 471cc558057354ccf6e1b6092b6d20ce368a1819 172.19.0.5:6380
   slots: (0 slots) slave
   replicates 6a4fa959afb87b03ced727d273f3421fa136a055
S: 5d3ed6ed6eb03d52feffe592327f3c2aeded7337 172.19.0.7:6380
   slots: (0 slots) slave
   replicates dfd6cd26c4a55ba50d47af2cf24fa81dbd70b7e5
M: dfd6cd26c4a55ba50d47af2cf24fa81dbd70b7e5 172.19.0.3:6380
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@localhost dockerOffline]# docker exec -it redis6382 redis-cli -h 10.30.2.5 -p 6382 -a gbcom@gidata@123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.30.2.5:6382> set dualven 10000
OK
10.30.2.5:6382> get dualven
"10000"
10.30.2.5:6382> set hujuan 2000
(error) MOVED 7033 172.19.0.3:6380
10.30.2.5:6382> get hujuan
(error) MOVED 7033 172.19.0.3:6380
10.30.2.5:6382> get hujuan
(error) MOVED 7033 172.19.0.3:6380
10.30.2.5:6382> exit
[root@localhost dockerOffline]# docker exec -it redis6382 redis-cli -c -h 10.30.2.5 -p 6382 -a gbcom@gidata@123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.30.2.5:6382> set hujuan
(error) ERR wrong number of arguments for 'set' command
10.30.2.5:6382> set hujuan 20000
-> Redirected to slot [7033] located at 172.19.0.3:6380

(3) 结果

(4) 测试

扫描二维码关注公众号,回复: 12672933 查看本文章

docker exec -it redis6387 redis-cli -h 10.60.2.185 -p 6387 -c -a *********

 

猜你喜欢

转载自blog.csdn.net/dualvencsdn/article/details/108474017