文章目录
- 1.Redis集群
- 2.搭建步骤
- 2.1 创建Redis网络
- 2.2 创建6个Redis配置
- 2.3 启动容器
1.Redis集群
文章图片
启动6个Redis容器,上面三个是主,后面三个是备!
2.搭建步骤 2.1 创建Redis网络
docker network create redis --subnet 172.38.0.0/162.2 创建6个Redis配置
文章图片
for port in $(seq 1 6);
\
do \
mkdir -p /mydata/redis/node-${port}/conf
touch /mydata/redis/node-${port}/conf/redis.conf
cat <>/mydata/redis/node-${port}/conf/redis.conf
port 6379
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 172.38.0.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done
文章图片
2.3 启动容器
docker run -p 6371:6379 -p 16371:16379 --name redis-1 -v /mydata/redis/node-1/data:/data -v /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.38.0.11 redis redis-server /etc/redis/redis.confdocker run -p 6372:6379 -p 16372:16379 --name redis-2 -v /mydata/redis/node-2/data:/data -v /mydata/redis/node-2/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.38.0.12 redis redis-server /etc/redis/redis.confdocker run -p 6373:6379 -p 16373:16379 --name redis-3 -v /mydata/redis/node-3/data:/data -v /mydata/redis/node-3/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.38.0.13 redis redis-server /etc/redis/redis.confdocker run -p 6374:6379 -p 16374:16379 --name redis-4 -v /mydata/redis/node-4/data:/data -v /mydata/redis/node-4/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.38.0.14 redis redis-server /etc/redis/redis.confdocker run -p 6375:6379 -p 16375:16379 --name redis-5 -v /mydata/redis/node-5/data:/data -v /mydata/redis/node-5/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.38.0.15 redis redis-server /etc/redis/redis.confdocker run -p 6376:6379 -p 16376:16379 --name redis-6 -v /mydata/redis/node-6/data:/data -v /mydata/redis/node-6/conf/redis.conf:/etc/redis/redis.conf -d --net redis --ip 172.38.0.16 redis redis-server /etc/redis/redis.conf
文章图片
生成集群:
docker exec -it redis-1 /bin/sh
redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379 172.38.0.14:6379 172.38.0.15:6379 172.38.0.16:6379 --cluster-replicas 1
[root@worker redis]# docker exec -it redis-1 /bin/sh
# ls
appendonly.aof nodes.conf# redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379 172.38.0.14:6379 172.38.0.15:6379 172.38.0.16:6379 --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 172.38.0.15:6379 to 172.38.0.11:6379
Adding replica 172.38.0.16:6379 to 172.38.0.12:6379
Adding replica 172.38.0.14:6379 to 172.38.0.13:6379
M: e265852a7d42d326f8c455e9bac4a31359f36319 172.38.0.11:6379
slots:[0-5460] (5461 slots) master
M: 775b58126a96dc5b6cfef118ecd377c6e4e3ba2b 172.38.0.12:6379
slots:[5461-10922] (5462 slots) master
M: c74df5eccc23de487d9ed6e13d951a3abd49a688 172.38.0.13:6379
slots:[10923-16383] (5461 slots) master
S: dd6d0f47e7d861c08234659e53992b2f83930200 172.38.0.14:6379
replicates c74df5eccc23de487d9ed6e13d951a3abd49a688
S: dc033ff79856c051aa0d1c6fbccc05d5fd2f7411 172.38.0.15:6379
replicates e265852a7d42d326f8c455e9bac4a31359f36319
S: 305f5b5d141d894cf42a658d265993b167a80171 172.38.0.16:6379
replicates 775b58126a96dc5b6cfef118ecd377c6e4e3ba2b
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.38.0.11:6379)
M: e265852a7d42d326f8c455e9bac4a31359f36319 172.38.0.11:6379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: c74df5eccc23de487d9ed6e13d951a3abd49a688 172.38.0.13:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: dc033ff79856c051aa0d1c6fbccc05d5fd2f7411 172.38.0.15:6379
slots: (0 slots) slave
replicates e265852a7d42d326f8c455e9bac4a31359f36319
S: dd6d0f47e7d861c08234659e53992b2f83930200 172.38.0.14:6379
slots: (0 slots) slave
replicates c74df5eccc23de487d9ed6e13d951a3abd49a688
M: 775b58126a96dc5b6cfef118ecd377c6e4e3ba2b 172.38.0.12:6379
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 305f5b5d141d894cf42a658d265993b167a80171 172.38.0.16:6379
slots: (0 slots) slave
replicates 775b58126a96dc5b6cfef118ecd377c6e4e3ba2b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
docker搭建redis集群完成!
【Docker|狂神说Java -- Redis集群部署】
文章图片
文章图片
推荐阅读
- linux|2022年云原生趋势
- 个人日记|K8s中Pod生命周期和重启策略
- k8s|k8s(六)(配置管理与集群安全机制)
- Redis|redis原理之布隆过滤器(Bloom Filter)
- Go|Docker后端部署详解(Go+Nginx)
- docker|Docker
- redis安装与基本使用
- java|图解四种 IO 模型
- Redis|Redis性能解析--Redis为什么那么快()
- java|你跳一次涨多少(今天见识到跳槽天花板!!)