redis ha和docker上的哨兵

sqyvllje  于 2021-06-07  发布在  Redis
关注(0)|答案(1)|浏览(517)

我现在和码头上的redis ha奋斗了一个星期。我不太相信我的意图是否会奏效。文件是可以理解的,但是有许多例子与文件不符。
嗯,我想做的是建立一个redis集群,有1个主节点,2个副本和3个sentinel。它托管在192.168.1.10上。我想通过192.168.1.11的应用程序访问集群。没有哨兵,集群工作正常。复制工作正常。
当我启动sentinel时,我在所有3个redis容器上得到以下日志条目:redis-0、redis-1和redis-2

1:S 22 Dec 2020 18:43:38.349 * Connecting to MASTER 172.20.0.2:6379
1:S 22 Dec 2020 18:43:38.350 * MASTER <-> REPLICA sync started
1:S 22 Dec 2020 18:43:38.350 * Non blocking connect for SYNC fired the event.
1:S 22 Dec 2020 18:43:38.350 * Master replied to PING, replication can continue...
1:S 22 Dec 2020 18:43:38.350 * Trying a partial resynchronization (request eac3aa540e767589e9673ae0ed844d985ed2abb2:1856).
1:S 22 Dec 2020 18:43:38.350 * Master is currently unable to PSYNC but should be in the future: -NOMASTERLINK Can't SYNC while not connected with my master

我试着按照这个教程,但没有成功。与描述的行为相同。这是我的docker命令


# Redis (with custom redis.conf will not work the replication) so i keep it simple this way.

docker run --name redis-0 -d --network redis -p 6379:6379 redis redis-server
docker run --name redis-1 -d --network redis -p 6380:6379 redis redis-server --slaveof redis-0 6379
docker run --name redis-2 -d --network redis -p 6381:6379 redis redis-server --slaveof redis-0 6379

# Sentinel

docker run -d --name sentinel-0 --network redis -v ${PWD}/sentinel-0:/etc/redis/  redis  redis-sentinel /etc/redis/sentinel.conf
docker run -d --name sentinel-1 --network redis -v ${PWD}/sentinel-1:/etc/redis/  redis  redis-sentinel /etc/redis/sentinel.conf
docker run -d --name sentinel-2 --network redis -v ${PWD}/sentinel-2:/etc/redis/  redis  redis-sentinel /etc/redis/sentinel.conf

这就是 sentinel.conf ```
port 5000

sentinel monitor

sentinel monitor mymaster 172.20.0.2 6379 2
sentinel down-after-milliseconds mymaster 1000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1

sentinel容器对 `sentinel.conf` .
那些是我的 `iptables` 说明

Redis

/usr/sbin/iptables -t nat -A PREROUTING -p tcp --dport 6379 -j DNAT --to-destination 172.20.0.2:6379
/usr/sbin/iptables -t nat -A PREROUTING -p tcp --dport 6380 -j DNAT --to-destination 172.20.0.3:6379
/usr/sbin/iptables -t nat -A PREROUTING -p tcp --dport 6381 -j DNAT --to-destination 172.20.0.4:6379

Sentinel

/usr/sbin/iptables -t nat -A PREROUTING -p tcp --dport 26379 -j DNAT --to-destination 172.20.0.5:6379
/usr/sbin/iptables -t nat -A PREROUTING -p tcp --dport 26380 -j DNAT --to-destination 172.20.0.6:6379
/usr/sbin/iptables -t nat -A PREROUTING -p tcp --dport 26381 -j DNAT --to-destination 172.20.0.7:6379

我很清楚这些文件:
由于sentinel使用masters info输出信息自动检测副本,因此检测到的副本将无法访问,并且sentinel将永远无法故障转移到master,因为从系统的Angular 来看没有好的副本,因此,除非您指示docker将端口Map为1:1,否则当前无法使用sentinel监视使用docker部署的一组主示例和副本示例。
对于第一个问题,如果要使用docker和转发端口(或任何其他nat设置,其中端口被重新Map)运行一组sentinel示例,可以使用以下两个sentinel配置指令来强制sentinel宣布一组特定的ip和端口:
sentinel announce ip sentinel announce port注意docker能够在主机网络模式下运行(请检查 `--net=host` 选项以获取更多信息)。这不会产生任何问题,因为在此设置中不会重新Map端口。
我只是不知道把ip和端口放在哪里,它们的价值是什么。还要注意 `--net=host` 不会工作,因为我有3个容器在同一个host:port.
如何在为redis ha服务的docker环境中运行sentinel?
谢谢你的帮助!
编辑:
我做了一个故障转移测试,结果如下(sentinel 0、1和2上的结果相同)

docker exec -it sentinel-0 redis-cli -p 5000

127.0.0.1:5000> SENTINEL get-master-addr-by-name mymaster

  1. "172.20.0.2"
  2. "6379"

docker stop redis-0

redis-0

docker exec -it sentinel-0 redis-cli -p 5000

127.0.0.1:5000> SENTINEL get-master-addr-by-name mymaster

  1. "172.20.0.2"
  2. "6379"
qvsjd97n

qvsjd97n1#

跟着你的 Docker commands 以及 sentinel.conf ,对我很有效。

1:S 23 Dec 2020 03:14:59.370 * Connecting to MASTER redis-0:6379
1:S 23 Dec 2020 03:14:59.371 * MASTER <-> REPLICA sync started
1:S 23 Dec 2020 03:14:59.371 * Non blocking connect for SYNC fired the event.
1:S 23 Dec 2020 03:14:59.371 * Master replied to PING, replication can continue...
1:S 23 Dec 2020 03:14:59.372 * Trying a partial resynchronization (request 5c52aa10610b365f29fec2968e095c5b49eb6136:43).
1:S 23 Dec 2020 03:14:59.373 * Full resync from master: 1f843162cf808a500a5d57392baf585f6e1679a3:0

也许你可以查看redis-0日志,它是否接受replica'ask。

相关问题