您的位置:首页 > 运维架构 > Docker

Docker和Redis搭配进行Sentinel或Cluster使用的大坑

2018-11-19 15:43 1301 查看

docker默认是使用bridge的网络环境构建container

由于slave是基于对网络环境的检测来告知master自己的IP,类似地,sentinel是也是这样返回有效的master信息以及向其他sentinel广播自身位置,在docker环境中,这通常会导致slave和sentinel无法正常获取真实或有效的IP地址。

通常是类似如下

[code]172.18.0.?
127.0.0.?

【注意】上述的127.0.0.?是相对于container自身的localhost,而并非宿主机的。即在宿主机中访问127.0.0.?是访问不到反馈出来的地址的

在使用如jedis或redisson进行连接时,常常会出现以下情况:

  1. 拿到的上述地址在宿主机中是无法连接的
  2. 正常连接但sentinel之间无法互相发现,即选举/投票机制将会失效

查阅redis的文档

Redis Cluster and Docker

Currently Redis Cluster does not support NATted environments and in general environments where IP addresses or TCP ports are remapped.

Docker uses a technique called port mapping: programs running inside Docker containers may be exposed with a different port compared to the one the program believes to be using. This is useful in order to run multiple containers using the same ports, at the same time, in the same server.

In order to make Docker compatible with Redis Cluster you need to use the host networking mode of Docker. Please check the 

--net=host
 option in the Docker documentation for more information.

尝试使用host代替默认的bridge网络进行使用

[code]--net=host

 然而依旧连接无效,甚至只开一个master都无法正常连接

查阅docker文档,可以发现,在windows平台上,docker实际先是运行了一层linux的虚拟机,而这个host主机网络模式中的“主机”,指的是这个linux虚拟机本身,而非我们的宿主机,因此指定了host主机网络模式,也是无法使用的。

 

目前来看,只能通过真实的部署,才可以达到想要的效果,docker对此的支持还比较有限。

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: