- 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
推荐阅读
-
黄叶|养文竹,谨记2多、2少,不黄叶,还不断冒新芽
-
-
小米|小米有品开卖99元剃须刀:5层悬浮刀片 比手术刀还要薄
-
-
狗不理|一家老字号的大溃败:从狗不理变成“Go Believe”开始
-
#玫瑰#亚洲最大的鲜花市场在昆明,玫瑰3毛一朵,网红直播卖花
-
-
奔驰c180最新价格?奔驰c200l和c180l哪个保
-
国际金融报|全球五大石油巨头二季度集体亏损!沙特阿美CEO:最坏的情况可能已经过去了
-
央视网|?美国国家飓风中心:得克萨斯州和路易斯安那州将面临飓风威胁
-
-
建行App上线数字货币钱包 数字金融时代将带给你哪些影响?
-
省长|地级市市长升任副省长,打破常规的背后,有着这些共同点
-
阿古朵|阿古朵连招用错输一半,小学生喜欢乱来,梦飞却用这个18连胜上国服第一
-
朱一龙|赵今麦新片失利后,这个6月只剩下朱一龙的新电影撑场了
-
成都2例境外输入病例详情公布:自开罗乘同一航班抵达
-
喜指|俗语“宅子有3喜,家中出人才”,你知道3喜指的是啥吗
-
-
-