Redis集群部署实战(docker版)

先创建一个网卡
docker network create redis --subnet 172.38.0.0/16image

通过脚本创建六个redis配置
for port in $(seq 1 6);
do
mkdir -p /mydata/redis/node-${port}/conf
touch /mydata/redis/node-${port}/conf/redis.conf
cat << EOF >/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

image

docker run -p 637${port}:6379 -p 1637${port}:16379 --name redis-${port}
-v /mydata/redis/node-${port}/data:/data
-v /mydata/redis/node-${port}/conf/redis.conf:/etc/redis/redis.conf
-d --net redis --ip 172.38.0.1${port} redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf (通过脚本启动)

image

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:5.0.9-alpine3.11 redis-server /etc/redis/redis.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

/data # redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379 172.38.0.14:6379 1
72.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: 43ecac57d81cd97030dc1fd35728e5387faa758f 172.38.0.11:6379
slots:[0-5460] (5461 slots) master
M: aeda148ebf832e2ab7684595813c7858261b6f8e 172.38.0.12:6379
slots:[5461-10922] (5462 slots) master
M: 91ce5c16a7b2dc724145ae5bc0137c4b8b1264b9 172.38.0.13:6379
slots:[10923-16383] (5461 slots) master
S: 322880e37e9f401cc705729aaec8789e5919808d 172.38.0.14:6379
replicates 91ce5c16a7b2dc724145ae5bc0137c4b8b1264b9
S: bff4df376b3d8af9643ccced17084dcfdf8f9c75 172.38.0.15:6379
replicates 43ecac57d81cd97030dc1fd35728e5387faa758f
S: 6bd617ce197a910ff88a996fc3f3139bb5661967 172.38.0.16:6379
replicates aeda148ebf832e2ab7684595813c7858261b6f8e
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: 43ecac57d81cd97030dc1fd35728e5387faa758f 172.38.0.11:6379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 6bd617ce197a910ff88a996fc3f3139bb5661967 172.38.0.16:6379
slots: (0 slots) slave
replicates aeda148ebf832e2ab7684595813c7858261b6f8e
S: 322880e37e9f401cc705729aaec8789e5919808d 172.38.0.14:6379
slots: (0 slots) slave
replicates 91ce5c16a7b2dc724145ae5bc0137c4b8b1264b9
M: aeda148ebf832e2ab7684595813c7858261b6f8e 172.38.0.12:6379
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
M: 91ce5c16a7b2dc724145ae5bc0137c4b8b1264b9 172.38.0.13:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: bff4df376b3d8af9643ccced17084dcfdf8f9c75 172.38.0.15:6379
slots: (0 slots) slave
replicates 43ecac57d81cd97030dc1fd35728e5387faa758f
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.image
查看集群信息 cluster infoimage
查看节点 cluster nodesimage
测试主从机制
随便set一个值,然后把对应主机停了,看从机是否可用image

image
可见在14从机上
查看集群节点,13故障14变成masterimage
至此docker搭建集群完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值