- 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
推荐阅读
-
161的身高一般买f的内衣腰围52咋穿衣服!不想性感森女!其他的都可以!咋破穿!我还有一张娃娃脸?
-
少年一梦|马斯克脑机接口刚出来,浙大传来好消息,我国在AI领域再攻下一城
-
人走茶凉|华为HCIA/HCIP/HCIE数通Datacom系列,OSPF基础配置讲解
-
ZAKER|新桥城管中队:拆!,公共停车场私设地锁
-
河北一杂技学校4名学生在成都失联,其中两人已被找到
-
最受大众“喜爱”的城市,不是我们熟悉的北京,反而是这座城市!
-
-
-
?人民日报客户端|印尼新冠肺炎新增确诊1752例 累计确诊84882例
-
-
港股挖掘机|洛阳玻璃股份(01108)附属太阳能材料项目5月28日顺利投产
-
【东南地区】自宋代以后,为何没有朝代定都于关中,如长安这些地方?
-
-
不含香精的国产护肤品 佰草百丽日本小分子透明质酸钠原液
-
-
新车|艳丽,兰博基尼Huracán EVO后驱版亮相广州车展
-
减肥|要想减肥成功且不反弹,这五大“雷区”,你还敢踩吗?
-
华大基因前三季度净利预计超26亿元 同比增长约900%
-
-
#公益#记忆中没看过她作品,但年年来金鸡百花刷存在感,逢“鸡”必到