Docker容器

docker 高可用集群搭建 sentinel

本文主要是介绍docker 高可用集群搭建 sentinel,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1 首先先准备3 份配置文件
redis6380.conf  redis6381.conf  redis6382.conf
修改里面的端口号

2 分别启动三台redis  这里设置redis6380为master
因此 我们启动第一台redis的命令为
docker run -d -p 6380:6380 --name node01master -v /mydata/redis/data/:/data -v /mydata/redis/conf/:/etc/redis/ redis redis-server /etc/redis/redis6380.conf 
启动redis6381为slave
docker run -d -p 6381:6381 --name node02slave -v /mydata/redis/data/:/data -v /mydata/redis/conf/:/etc/redis/ redis redis-server /etc/redis/redis6381.conf --replicaof 192.168.0.137 6380
docker run -d -p 6381:6381 --name node02slave -v /mydata/redis/data:/data -v /mydata/redis/conf/:/etc/redis/  redis  redis-server /etc/redis/redis6381.conf --slaveof 192.168.0.137 6380
启动redis6382为slave
docker run -d -p 6382:6382 --name node03slave -v /mydata/redis/data/:/data -v /mydata/redis/conf/:/etc/redis/ redis redis-server /etc/redis/redis6382.conf --replicaof 192.168.0.137 6380
docker run -d -p 6382:6382 --name node03slave -v /mydata/redis/data:/data -v /mydata/redis/conf/:/etc/redis/  redis  redis-server /etc/redis/redis6382.conf --slaveof 192.168.0.137 6380
、
此时我们三台主从搭建完毕  因为主从无法出现故障时 无法选主  因此我们需要设置哨兵 监控 一旦主节点宕机  我们可以快速选主 实现服务高可用

然后我们需要启动三台哨兵
创建三个配置文件 26380.conf  26381.conf 26382.conf  并分别赋予他们写权限
scp ./26381.conf 192.168.0.138:/mydata/redis/conf
修改端口 和 主机地址
scp ./26382.conf 192.168.0.139:/mydata/redis/conf
chmod 777 26380.conf

然后执行 
node01执行
docker run --name redis26380-sentinel -v /mydata/redis/conf/:/etc/redis  -d redis redis-server /etc/redis/26380.conf --sentinel

docker run -p 26380:26380 --restart=always --name redis26380-sentinel -v /mydata/redis/conf/:/etc/redis -v /mydata/redis/data:/data  -d redis redis-sentinel /etc/redis/26380.conf


node02执行
docker run --name redis26381-sentinel -v /mydata/redis/conf/:/etc/redis  -d redis redis-server /etc/redis/26381.conf --sentinel

docker run -p 26381:26381 --restart=always --name redis26381-sentinel -v /mydata/redis/conf/:/etc/redis -v /mydata/redis/data:/data  -d redis redis-sentinel /etc/redis/26381.conf
 
node03执行
docker run --name redis26382-sentinel -v /mydata/redis/conf/:/etc/redis  -d redis redis-server /etc/redis/26382.conf --sentinel

docker run -p 26382:26382 --restart=always --name redis26382-sentinel -v /mydata/redis/conf/:/etc/redis -v /mydata/redis/data:/data  -d redis redis-sentinel /etc/redis/26382.conf
 

 Sep 2022 04:29:57.902 * Running mode=sentinel, port=26379.
1:X 07 Sep 2022 04:29:57.903 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:X 07 Sep 2022 04:29:57.903 # Could not create tmp config file (Permission denied)
1:X 07 Sep 2022 04:29:57.904 # WARNING: Sentinel was not able to save the new configuration on disk!!!: Permission denied
1:X 07 Sep 2022 04:29:57.904 # Sentinel ID is 7aa3ddfffe6517d1fac8141588d6420cb18519d0
1:X 07 Sep 2022 04:29:57.904 # +monitor master mymaster 192.168.0.137 6380 quorum 2
1:X 07 Sep 2022 04:29:57.906 * +slave slave 192.168.0.138:6381 192.168.0.138 6381 @ mymaster 192.168.0.137 6380
1:X 07 Sep 2022 04:29:57.906 # Could not create tmp config file (Permission denied)
1:X 07 Sep 2022 04:29:57.906 # WARNING: Sentinel was not able to save the new configuration on disk!!!: Permission denied
1:X 07 Sep 2022 04:29:57.906 * +slave slave 192.168.0.139:6382 192.168.0.139 6382 @ mymaster 192.168.0.137 6380
1:X 07 Sep 2022 04:29:57.906 # Could not create tmp config file (Permission denied)
1:X 07 Sep 2022 04:29:57.906 # WARNING: Sentinel was not able to save the new configuration on disk!!!: Permission denied

 

 

这篇关于docker 高可用集群搭建 sentinel的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!