Tomato 的个人博客

记录精彩的程序人生

Open Source, Open Mind,
Open Sight, Open Future!
  menu
8 文章
0 浏览
1 当前访客
ღゝ◡╹)ノ❤️

Dockers创建Redis集群

命令示例

创建自定义网络

docker network create redis --subnet 172.18.0.0/16

创建redis挂载目录

for port in $(seq 1 6);
do 
	mkdir -p /home/apple/workspace/db/redis/node-${port}/conf
	touch /home/apple/workspace/db/redis/node-${port}/conf/redis.conf
	cat << EOF >/home/apple/workspace/db/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.18.0.1${port}
		cluster-announce-port 6379
		cluster-announce-bus-port 16379
		appendonly yes
		EOF
done

启动多个容器脚本

for i in $(seq 1 6)
do
echo ${i}
docker run -p 637${i}:6379 -p 1637${i}:16379 --name redis-${i} \
	-v /home/apple/workspace/db/redis/node-${i}:/data \
	-v /home/apple/workspace/db/redis/node-${i}/conf/redis.conf:/etc/redis/redis.conf \
	-d --net redis --ip 172.18.0.1${i} redis redis-server /etc/redis/redis.conf
done

在容器中配置redis集群

redis-cli --cluster create 172.18.0.11:6379 172.18.0.12:6379 \
> 172.18.0.13:6379 172.18.0.14:6379 172.18.0.15:6379 172.18.0.16:6379 \
> --cluster-replicas 1

标题:Dockers创建Redis集群
作者:MrTomato
地址:https://isee-you.icu/articles/2024/03/27/1711555122177.html