#--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global # to have these messages end up in /var/log/haproxy.log you will # need to: # # 1) configure syslog to accept network log events. This is done # by adding the '-r' option to the SYSLOGD_OPTIONS in # /etc/sysconfig/syslog # # 2) configure local2 events to go to the /var/log/haproxy.log # file. A line like the following can be added to # /etc/sysconfig/syslog # # local2.* /var/log/haproxy.log # log stdout format raw local0 info #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults log global mode tcp retries 3 option redispatch maxconn 20000 timeout connect 600s timeout client 600s timeout server 600s listen stats bind 0.0.0.0:8080# 面板代理 mode http stats uri /haproxy-status # 面板地址 stats auth admin:admin # 面板user:pwd stats hide-version stats refresh 30s frontend redis16379 bind :16379# 代理端口 default_backend redis_16379_backend backend redis_16379_backend option tcp-check tcp-check connect tcp-check send AUTH\ bb123456\r\n # redis 密码 按需调整 tcp-check expect string +OK tcp-check send PING\r\n tcp-check expect string +PONG tcp-check send info\ replication\r\n tcp-check expect string role:master # 轮询 master节点 tcp-check send QUIT\r\n tcp-check expect string +OK server redis1 192.168.2.213:6379 check inter 1s server redis2 192.168.2.214:6379 check inter 1s server redis3 192.168.2.215:6379 check inter 1s
1:S 03 Feb 2023 09:07:22.284 * MASTER <-> REPLICA sync: receiving 214 bytes from master to disk 1:S 03 Feb 2023 09:07:22.284 * MASTER <-> REPLICA sync: Flushing old data 1:S 03 Feb 2023 09:07:22.284 * MASTER <-> REPLICA sync: Loading DB in memory 1:S 03 Feb 2023 09:07:22.285 * Loading RDB produced by version 6.2.4 1:S 03 Feb 2023 09:07:22.285 * RDB age 0 seconds 1:S 03 Feb 2023 09:07:22.285 * RDB memory usage when created 1.85 Mb 1:S 03 Feb 2023 09:07:22.285 * MASTER <-> REPLICA sync: Finished with success 1:S 03 Feb 2023 09:07:22.286 * Background append only file rewriting started by pid 13 1:S 03 Feb 2023 09:07:22.308 * AOF rewrite child asks to stop sending diffs. 13:C 03 Feb 2023 09:07:22.308 * Parent agreed to stop sending diffs. Finalizing AOF... 13:C 03 Feb 2023 09:07:22.308 * Concatenating 0.00 MB of AOF diff received from parent. 13:C 03 Feb 2023 09:07:22.309 * SYNC append only file rewrite performed 13:C 03 Feb 2023 09:07:22.309 * AOF rewrite: 4 MB of memory used by copy-on-write 1:S 03 Feb 2023 09:07:22.348 * Background AOF rewrite terminated with success 1:S 03 Feb 2023 09:07:22.348 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB) 1:S 03 Feb 2023 09:07:22.348 * Background AOF rewrite finished successfully 1:S 03 Feb 2023 10:07:14.007 * 1 changes in 3600 seconds. Saving... 1:S 03 Feb 2023 10:07:14.009 * Background saving started by pid 15 15:C 03 Feb 2023 10:07:14.012 * DB saved on disk 15:C 03 Feb 2023 10:07:14.013 * RDB: 4 MB of memory used by copy-on-write 1:S 03 Feb 2023 10:07:14.109 * Background saving terminated with success
sentinel:
1 2 3 4 5 6 7 8 9 10 11 12 13
1:X 03 Feb 2023 09:07:24.787 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 1:X 03 Feb 2023 09:07:24.787 # Redis version=6.2.4, bits=64, commit=00000000, modified=0, pid=1, just started 1:X 03 Feb 2023 09:07:24.787 # Configuration loaded 1:X 03 Feb 2023 09:07:24.788 * monotonic clock: POSIX clock_gettime 1:X 03 Feb 2023 09:07:24.788 * Running mode=sentinel, port=26379. 1:X 03 Feb 2023 09:07:24.788 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 1:X 03 Feb 2023 09:07:24.789 # Sentinel ID is 49d6ef4a1346ec4a05bec6a6387e6fd66c2a177e 1:X 03 Feb 2023 09:07:24.789 # +monitor master mymaster 192.168.2.12 6379 quorum 2 1:X 03 Feb 2023 09:09:48.027 # +sdown sentinel 32c2d1980d2d054c811f474140f17bb60c1a6dde 192.168.2.214 26379 @ mymaster 192.168.2.215 6379 1:X 03 Feb 2023 09:09:48.099 # +sdown slave 192.168.2.214:6379 192.168.2.11 6379 @ mymaster 192.168.2.12 6379 1:X 03 Feb 2023 09:11:54.402 * +reboot slave 192.168.2.214:6379 192.168.2.11 6379 @ mymaster 192.168.2.12 6379 1:X 03 Feb 2023 09:11:54.502 # -sdown slave 192.168.2.214:6379 192.168.2.11 6379 @ mymaster 192.168.2.12 6379 1:X 03 Feb 2023 09:11:54.502 # -sdown sentinel 32c2d1980d2d054c811f474140f17bb60c1a6dde 192.168.2.11 26379 @ mymaster 192.168.2.215 6379
haproxy:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[NOTICE] (1) : New worker #1 (8) forked Connect from 10.0.0.2:3768 to 10.0.0.249:16379 (redis16379/TCP) Connect from 10.0.0.2:3767 to 10.0.0.249:16379 (redis16379/TCP) Connect from 10.0.0.2:3769 to 10.0.0.249:16379 (redis16379/TCP) Server redis_16379_backend/redis1 is DOWN, reason: Layer7 timeout, info: " at step 7 of tcp-check (expect string 'role:master')", check duration: 1001ms. 2 active and 0 backup servers left. 2 sessions active, 0 requeued, 0 remaining in queue. [WARNING] (8) : Server redis_16379_backend/redis1 is DOWN, reason: Layer7 timeout, info: " at step 7 of tcp-check (expect string 'role:master')", check duration: 1001ms. 2 active and 0 backup servers left. 2 sessions active, 0 requeued, 0 remaining in queue. [WARNING] (8) : Server redis_16379_backend/redis2 is DOWN, reason: Layer7 timeout, info: " at step 7 of tcp-check (expect string 'role:master')", check duration: 1001ms. 1 active and 0 backup servers left. 1 sessions active, 0 requeued, 0 remaining in queue. Server redis_16379_backend/redis2 is DOWN, reason: Layer7 timeout, info: " at step 7 of tcp-check (expect string 'role:master')", check duration: 1001ms. 1 active and 0 backup servers left. 1 sessions active, 0 requeued, 0 remaining in queue. Connect from 10.0.0.2:3765 to 10.0.0.249:16379 (redis16379/TCP) Connect from 10.0.0.2:3764 to 10.0.0.249:16379 (redis16379/TCP) Connect from 10.0.0.2:3770 to 10.0.0.249:16379 (redis16379/TCP) Connect from 10.0.0.2:3771 to 10.0.0.249:16379 (redis16379/TCP) Connect from 10.0.0.2:3766 to 10.0.0.249:16379 (redis16379/TCP) Connect from 10.0.0.2:3772 to 10.0.0.249:16379 (redis16379/TCP)
代理面板
访问IP:8080/haproxy-status
停止服务
1
docker stack rm redis-sentinel
连接测试
使用redis连接工具测试连接
连接到Redis单实例
正常连接IP:6379即可
连接到Redis哨兵
连接到IP:26379
连接到Haproxy代理
连接到haproxy:16379端口
测试数据同步
通过Haproxy添加新的键值:name:jonty
新增成功
查看哨兵连接:
可以看到已经同步成功
查看同步日志
1 2 3 4 5
1:S 03 Feb 2023 11:11:55.079 * 1 changes in 3600 seconds. Saving... 1:S 03 Feb 2023 11:11:55.081 * Background saving started by pid 16 16:C 03 Feb 2023 11:11:55.083 * DB saved on disk 16:C 03 Feb 2023 11:11:55.084 * RDB: 4 MB of memory used by copy-on-write 1:S 03 Feb 2023 11:11:55.181 * Background saving terminated with success
[root@manager redis-swarm]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION eyufo1vxn0m5xksslcns6gdau * manager Ready Active Reachable 20.10.23 xki7hv7tw44394vqyhidco14w worker1 Down Active Unreachable 20.10.23 xv4fw7yzwg5iwypea65z9n9yn worker2 Ready Active Leader 20.10.23