- 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
推荐阅读
-
北京日报|庞星火:海淘要关注海关食品检疫信息,做好外包装消杀
-
服装搭配师mai|月亮姐姐穿得真嫩!私服打扮像学生妹,42岁娃娃脸依旧娇俏甜美
-
-
-
反派|港剧《隐形战队》:大反派有可能是谭道德和KC?
-
-
兵王故事|天亮之后发现乌龙,上门道歉吃闭门羹,美特种兵呼叫空中支援
-
科技领袖|T280TWS PLUS体验,鲜活低频,悦听时尚好音乐,JBL
-
-
【汇源医师】要“鱼死网破”?做好1点让它乖乖溜走,幽门螺杆菌感染
-
-
企鹅科技 但比iPhone11香,iPhone12概念图:黑边框太粗是最大败笔
-
办公室VS运动|詹皇要提前统治比赛,裁判别抢戏了,湖人西决G3!掘金破釜沉舟
-
金华抽屉|又一地产大鳄进军兰溪!狂砸6.65亿拍得黄金地块,刚刚
-
娱乐易夏成为沈腾口碑最低综艺节目,《笑起来真好看》豆瓣评分4.3分
-
-
杭州大叔清晨不慎落水,危急关头民警“现学现用”救回一条命!
-
-
创业板|7月27日起可启动创业板注册制股票及存托凭证网上发行业务
-
「大连13岁行凶男孩家人始终不道歉」大连13岁行凶男孩家人始终不道歉,女童母亲申请强制执行