- 192.168.0.210从Redis哨兵配置文件,配置哨兵sentinel1实例运行的端口36382 , Redis密码 , 并将配置文件sentinel1.conf上传至/opt/container/redis/sentinel1/conf目录
# 哨兵sentinel实例运行的端口port 36382daemonize nopidfile /var/run/redis-sentinel1.piddir /tmpsentinel monitor mymaster 192.168.0.210 26381 2sentinel auth-pass mymaster "Redis密码"# 指定多少毫秒之后 主节点没有应答哨兵sentinel 此时 哨兵主观上认为主节点下线 默认30秒sentinel down-after-milliseconds mymaster 30000# 指定了在发生failover主备切换时最多可以有多少个slave同时对新的master进行同步,这个数字越小 , 完成failover所需的时间就越长sentinel parallel-syncs mymaster 1# 故障转移的超时时间sentinel failover-timeout mymaster 180000sentinel deny-scripts-reconfig yes - 192.168.0.195从Redis哨兵配置文件,配置哨兵sentinel2实例运行的端口36383 , Redis密码,并将配置文件sentinel2.conf上传至/opt/container/redis/sentinel2/conf目录
appendonly yesport 26383appendfilename appendonly.aofappendfsync everysecauto-aof-rewrite-min-size 10Mauto-aof-rewrite-percentage 100requirepass "设置密码" replicaof 192.168.0.210 26381masterauth "设置密码" replica-read-only no5. 在两台服务器上分别执行docker-compose安装启动命令将docker-compose-redis.yml上传至/opt/software目录,这个目录可以自己选择,然后到目录下执行安装启动命令
docker-compose -f docker-compose-redis.yml up -d[root@localhost software]# docker-compose -f docker-compose-redis.yml up -d[+] Running 10/10 ? sentinel1 Pulled15.7s ? redisSlave1 Pulled15.7s ? sentinel Pulled3.4s? a2abf6c4d29d Already exists0.0s? c7a4e4382001 Pull complete0.4s? 4044b9ba67c9 Pull complete1.0s? c8388a79482f Pull complete2.3s? 413c8bb60be2 Pull complete2.3s? 1abfd3011519 Pull complete2.4s ? redisMaster Pulled15.7sWARN[0015] Found orphan containers ([mysql Nginx]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up. [+] Running 4/4 ? Container redis-sentinel-1Started0.5s ? Container redis-slave-1Started0.6s ? Container redis-masterStarted0.6s ? Container redis-sentinelStarted0.5s通过docker ps命令可以看到redis和redis哨兵已经安装并启动成功
[root@localhost software]# docker psCONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMESf609322cabaaredis:latest"docker-entrypoint.s…"59 seconds agoUp 58 seconds6379/tcp, 0.0.0.0:26381->26381/tcp, :::26381->26381/tcpredis-master18b75828b5b7redis:latest"docker-entrypoint.s…"59 seconds agoUp 58 seconds6379/tcp, 0.0.0.0:36381->36381/tcp, :::36381->36381/tcpredis-sentinelf0f9a037c7aeredis:latest"docker-entrypoint.s…"59 seconds agoUp 58 seconds6379/tcp, 0.0.0.0:26382->26382/tcp, :::26382->26382/tcpredis-slave-1e51d3b0bc696redis:latest"docker-entrypoint.s…"59 seconds agoUp 58 seconds6379/tcp, 0.0.0.0:36382->36382/tcp, :::36382->36382/tcpredis-sentinel-16. 通过命令查看redis哨兵状态
docker exec -it f609322cabaa bashcd /usr/local/bin - 运行info Replication命令查看主节点信息,我们可以看到connected_slaves有2个,其中slave0的ip为172.18.0.1,这是因为其获取的是docker的ip地址
./redis-cli-h 127.0.0.1 -p 26381 -a "密码" info Replication# Replicationrole:masterconnected_slaves:2slave0:ip=172.18.0.1,port=26382,state=online,offset=700123,lag=0slave1:ip=192.168.0.195,port=26383,state=online,offset=700123,lag=0master_failover_state:no-failovermaster_replid:9ee56f68d25b71158544f6cfafc677822c401ec3master_replid2:0000000000000000000000000000000000000000master_repl_offset:700123second_repl_offset:-1repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:700123 - 同样的操作方式进入到Sentinel容器,通过INFO Sentinel命令查看哨兵信息,我们可以看到有两个redis从服务,三个哨兵
root@fba6d91e10f6:/usr/local/bin# ./redis-cli -h 127.0.0.1 -p 36381 INFO Sentinel# Sentinelsentinel_masters:1sentinel_tilt:0sentinel_running_scripts:0sentinel_scripts_queue_length:0sentinel_simulate_failure_flags:0master0:name=mymaster,status=ok,address=192.168.0.210:26381,slaves=2,sentinels=37. 测试redis哨兵主备切换
docker stop 5541698b65a1 - 进入到Sentinel容器,通过INFO Sentinel命令查看哨兵信息,可以看到主Redis服务地址已经切换到192.168.0.195:26383
推荐阅读
-
邓锄头挖科技@高级产品不会告诉你的“十一条”需求沟通中超有效的注意事项!
-
-
忘川秋水|她在吐蕃的40年,真实生活是怎样的?,唐朝和亲入藏的文成公主
-
新华社|巴西又有州长感染新冠病毒,总计已有10个州长感染
-
你见过凌晨4点的高铁线吗 这背后的事情可以去思考一下
-
-
今年起,农村开启“禁养”模式,专家表示支持,农民的话很戳心!
-
旭日暖阳|5.99万元起售,新一代瑞虎5x哪款配置值得买?,上市就降1万元
-
净利|公告精选:山西省属燃气企业整合重组;万华化学上调10月份中国地区MDI价格
-
[社保缴费]30岁不交社保每年在银行存1万,退休后存下的钱真比社
-
-
唆麻 知识“风起”吹向百度知识属性,百度移动生态的底色从“双轮驱动”到“纵队协作”,差异化优势已成形与直播打配合,短视频必不可少结语:模式重构,总得有人先做,短视频娱乐“内卷
-
『孕妈』孕妈必备︱健荣凡士林霜,一款可以闭眼入手的润肤霜
-
「呆闻天下」惹事全靠实力,美国不愧是军事超级大国!武器出口是俄罗斯的三倍
-
宽松大方|秋日时尚穿搭,选一条宽松针织裙+松糕鞋搭配,简单大方轻松显高
-
-
『豪情NBA』霍华德“满血回归”,本赛季超值的五大底薪球员
-
行业唯一入选!Leader洗衣机获美国IDEA设计大奖
-
北青网综合|陕西新增1例境外输入确诊病例,涉及这趟航班
-