简体   繁体   English

Redis 哨兵 Docker 设置

[英]Redis sentinel Docker setup

Bascially I am trying to setup a single Redis-sentinel docker instance and want to make calls from my app container.基本上,我正在尝试设置一个 Redis-sentinel docker 实例,并希望从我的应用程序容器进行调用。 The issue I am running is this - the redis-sentinel container is linked to the app container.我正在运行的问题是 - redis-sentinel 容器链接到应用程序容器。

So, initially the app asks the sentinel process about the redis master.因此,最初应用程序向哨兵进程询问有关 redis master 的信息。 The sentinel then says it is "127.0.0.1".然后哨兵说它是“127.0.0.1”。 But the app container assumes that it is local to the container.但是应用程序容器假定它是容器本地的。 This can be overcome with announce-ip/announce-port parameters passed at the start of sentinel process.这可以通过在哨兵进程开始时传递的 announce-ip/announce-port 参数来克服。 However, the issue is this -然而,问题是——

the redis-sentinel container tries to start up before the link is being established. redis-sentinel 容器尝试在建立链接之前启动。 So even during the time of sentinel process launch the.network interface hence the link IP is not available.因此,即使在哨兵进程启动 .network 接口期间,链接 IP 也不可用。

One solution I could think of is to busy wait till the.network interface is established.我能想到的一种解决方案是忙等到.network 接口建立。 So, the question then boils down to "how can source container discover its newly established.network interface? Is there anything docker sets on the source container for it to discover different links?"那么,问题就归结为“源容器如何发现其新建立的.network接口?源容器上是否设置了docker来发现不同的链接?”

The linking is all managed in docker-compose file.链接全部在 docker-compose 文件中进行管理。

If there is any other simple solution, I am welcome to try that as well.如果有任何其他简单的解决方案,我也欢迎尝试。

There is no need for a custom sentinel image, or messing with the network.不需要自定义哨兵图像,也不需要弄乱网络。 See myredis-ha-learning project using Spring Data Redis , bitnami/redis and bitnami/redis-sentinel images.使用Spring Data Redisbitnami/redisbitnami/redis-sentinel图像查看我的redis-ha-learning项目。 The Docker Compose file is here . Docker Compose 文件在这里 My code auto detects the sentinels based on the Docker Compose container names.我的代码根据 Docker Compose 容器名称自动检测哨兵。

I have this configuration example here using docker compose that can be of help.我这里有这个配置示例,使用 docker compose 可以提供帮助。

https://github.com/oneyottabyte/redis_sentinel https://github.com/oneyottabyte/redis_sentinel

So, the solution that worked for me is simply reading the /etc/hosts file on the source container.因此,对我有用的解决方案只是读取源容器上的 /etc/hosts 文件。 I busy wait till the link is established and then use that network interface IP to start the sentinel process.我忙着等待链接建立,然后使用该网络接口 IP 启动哨兵进程。 This is just a stop gap solution and it is not scalable.这只是一个止损解决方案,不可扩展。 Redis-sentinel is still not production ready in dockerizable format as confirmed in this post .正如这篇文章中所确认的那样,Redis-sentinel 仍然没有以可泊坞窗格式进行生产。 So I decided to install Redis/sentinel on the physical hosts.所以我决定在物理主机上安装Redis/sentinel。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM