docker 搭建redis 集群
一、创建6个redis节点的配置文件
bind 0.0.0.0 port 6381 databases 1 save 3600 1 save 300 100 save 60 10000 dbfilename dump6381.rdb dir ./ appendonly yes appendfilename "appendonly6381.aof" appendfsync everysec cluster-enabled yes cluster-node-timeout 15000 cluster-config-file nodes.6381.conf cluster-announce-ip 10.211.55.8 (宿主机ip) cluster-announce-port 6381 (宿主机映射端口) cluster-announce-bus-port 16381
二、创建6个redis节点(三主三从)
创建docker网络
docker network create redisnetwork --subnet 172.38.0.0/16
docker run -di --name redis6380 -p 6380:6379 -p 16380:16379 --restart=always -v /usr/local/redis-cluster/cluster-config/redis-cluster6380.conf:/etc/redis/redis.conf -v /usr/local/redis-cluster/data:/data --net redisnetwork --ip 172.38.0.10 redis:6.2.6 --appendonly yes --cluster-enabled yes --dbfilename dump6380.rdb --dir ./ --appendfilename appendonly6380.aof --cluster-config-file nodes6380.conf --cluster-announce-ip 10.211.55.8 --cluster-announce-port 6380 --cluster-announce-bus-port 16380 docker run -di --name redis6381 -p 6381:6379 -p 16381:16379 --restart=always -v /usr/local/redis-cluster/cluster-config/redis-cluster6381.conf:/etc/redis/redis.conf -v /usr/local/redis-cluster/data:/data --net redisnetwork --ip 172.38.0.11 redis:6.2.6 --appendonly yes --cluster-enabled yes --dbfilename dump6381.rdb --dir ./ --appendfilename appendonly6381.aof --cluster-config-file nodes6381.conf --cluster-announce-ip 10.211.55.8 --cluster-announce-port 6381 --cluster-announce-bus-port 16381 docker run -di --name redis6382 -p 6382:6379 -p 16382:16379 --restart=always -v /usr/local/redis-cluster/cluster-config/redis-cluster6382.conf:/etc/redis/redis.conf -v /usr/local/redis-cluster/data:/data --net redisnetwork --ip 172.38.0.12 redis:6.2.6 --appendonly yes --cluster-enabled yes --dbfilename dump6382.rdb --dir ./ --appendfilename appendonly6382.aof --cluster-config-file nodes6382.conf --cluster-announce-ip 10.211.55.8 --cluster-announce-port 6382 --cluster-announce-bus-port 16382 docker run -di --name redis6383 -p 6383:6379 -p 16383:16379 --restart=always -v /usr/local/redis-cluster/cluster-config/redis-cluster6383.conf:/etc/redis/redis.conf -v /usr/local/redis-cluster/data:/data --net redisnetwork --ip 172.38.0.13 redis:6.2.6 --appendonly yes --cluster-enabled yes --dbfilename dump6383.rdb --dir ./ --appendfilename appendonly6383.aof --cluster-config-file nodes6383.conf --cluster-announce-ip 10.211.55.8 --cluster-announce-port 6383 --cluster-announce-bus-port 16383 docker run -di --name redis6384 -p 6384:6379 -p 16384:16379 --restart=always -v /usr/local/redis-cluster/cluster-config/redis-cluster6384.conf:/etc/redis/redis.conf -v /usr/local/redis-cluster/data:/data --net redisnetwork --ip 172.38.0.14 redis:6.2.6 --appendonly yes --cluster-enabled yes --dbfilename dump6384.rdb --dir ./ --appendfilename appendonly6384.aof --cluster-config-file nodes6384.conf --cluster-announce-ip 10.211.55.8 --cluster-announce-port 6384 --cluster-announce-bus-port 16384 docker run -di --name redis6385 -p 6385:6379 -p 16385:16379 --restart=always -v /usr/local/redis-cluster/cluster-config/redis-cluster6385.conf:/etc/redis/redis.conf -v /usr/local/redis-cluster/data:/data --net redisnetwork --ip 172.38.0.15 redis:6.2.6 --appendonly yes --cluster-enabled yes --dbfilename dump6385.rdb --dir ./ --appendfilename appendonly6385.aof --cluster-config-file nodes6385.conf --cluster-announce-ip 10.211.55.8 --cluster-announce-port 6385 --cluster-announce-bus-port 16385
三、进入任意一个容器中
docker exec -it redis6380 /bin/bash
四、进入到容器,输入下命令,创建集群
redis-cli --cluster create 10.211.55.8:6381 10.211.55.8:6382 10.211.55.8:6383 10.211.55.8:6384 10.211.55.8:6385 10.211.55.8:6380 --cluster-replicas 1
五、进入到任一容器
redis-cli -c cluster nodes