- 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
推荐阅读
-
-
不务正业的朱飘飘|为什么现在的手机都设计成不可换电池?
-
硅胶|原创她曾与刘烨合作经典,如今超模颜秒变硅胶脸,面部僵硬肿胀不敢认
-
-
科技瘾力安卓顶级旗舰机皇体验依旧,三星Galaxy Note20系列真香
-
娱乐圈|假发假臀假肌肉,大半个娱乐圈“从头假到脚”,还有真人吗?
-
-
极光携手碧桂园核心联盟企业-融山信息科技打造房产营销智能平台
-
-
周兴哲|周兴哲《其实你并没那么孤单》疗愈人心 MV灵感来自新书
-
-
「科技趣谈」这个功能深受雷军喜爱,五一假期让雷军玩得有点停不下来!
-
娱乐圈又有一大瓜!网传邓超出轨嫩模,两人婚姻出现破裂
-
|终止1亿投资!加大裁员力度,任正非这次为何如此强势?
-
地理分界线|【地理探究】阴山对中华有哪些影响?究竟有多少地理意义?
-
育儿family|标准五花肉,网友笑翻:我家同款,开学后萌娃被校服“封印”
-
-
墓室|将军去世后立碑:此地无金无银,别挖!200年后挖开墓室众人懵了
-
-
飞机|台湾闹笑话了,通报没有美军飞机飞越台上空,结果被美军“打脸”