Docker - redis集群

1. 创建自定义网络

docker network create --driver bridge --subnet 192.168.0.0/16 redis    #创建自定义网络
docker network inspect redis                                           #查看是否创建成功
docker network rm redis                                                #删除网络

2. 编写脚本创建目录和复制未修改的配置文件

for port in $(seq 1 6); \
do \
mkdir -p /home/redis/redis-3000${port}
cp /home/redis/redis.conf /home/redis/redis-3000${port}/redis.conf
done

3. 修改主表redis-30001的redis.conf

bind 0.0.0.0
timeout 0
tcp-keepalive 30
daemonize no

4. 启动主表

docker run -d --name redis-30001 -p 30001:6379 --net redis --ip 192.168.0.11 -v /home/redis/redis-30001/redis.conf:/etc/redis/redis.conf -v /home/redis/redis-30001/data:/data redis:5.0.8 redis-server /etc/redis/redis.conf

5. 修改五个从表的配置文件

bind 0.0.0.0
timeout 0
tcp-keepalive 30
daemonize no
slaveof 192.168.0.11 6379

6. 脚本启动五从表

for port in $(seq 2 6); \
do \
docker run -d --name redis-3000${port} -p 3000${port}:6379 --net redis --ip 192.168.0.1${port} -v /home/redis/redis-3000${port}/redis.conf:/etc/redis/redis.conf -v /home/redis/redis-3000${port}/data:/data redis:5.0.8 redis-server /etc/redis/redis.conf
done

你可能感兴趣的:(Linux,linux)