(1) 進行網絡設置node
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
Redis Cluster與Docker機制兼容。 若是在映射後的IP進行集羣配置,會失敗docker
方法1,如本文,進行內部網橋設置,進行不一樣IP,相同端口配置;網絡
方法2,https://blog.csdn.net/x3499633/article/details/88637819 。進行--net host,進行相同 的IP,不一樣的端口。ui
總之,就是NAT後的端口就不行了。 .net
(2) 進行集羣配置3d
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