Docker和Redis搭配进行Sentinel或Cluster使用的大坑
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进行连接时,常常会出现以下情况:
- 拿到的上述地址在宿主机中是无法连接的
- 正常连接但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=hostoption in the Docker documentation for more information.
尝试使用host代替默认的bridge网络进行使用
[code]--net=host
然而依旧连接无效,甚至只开一个master都无法正常连接
查阅docker文档,可以发现,在windows平台上,docker实际先是运行了一层linux的虚拟机,而这个host主机网络模式中的“主机”,指的是这个linux虚拟机本身,而非我们的宿主机,因此指定了host主机网络模式,也是无法使用的。
目前来看,只能通过真实的部署,才可以达到想要的效果,docker对此的支持还比较有限。
阅读更多- 使用sentinel进行redis主从切换的操作步骤(failOver故障转移)(何志雄)
- 使用Docker Compose部署基于Sentinel的高可用Redis集群
- 使用Docker Compose部署基于Sentinel的高可用Redis集群
- 使用Docker Compose部署基于Sentinel的高可用Redis集群
- Windos Docker Redis cluster 集群部署(linux一样)
- redis-cluster研究和使用
- 使用spring-data-redis进行对redis的操作,封装的一些操作方法
- Redis Cluster 3.0搭建与使用
- 使用openvidu 进行WebAPP开发环境部署(使用docker部署)
- java使用Redis6–sentinel单点故障主从自动切换
- redis sentinel & cluster 原理分析
- Redis/Redis-sentinel环境建立和验证---接着昨天的验证流程,再按照binding物理IP的方式进行
- 【Redis笔记】 第5篇: redis监控工具-redis sentinel使用说明及注意事项
- 在boot2docker上使用nsenter进行docker调试
- 【Redis】Redis学习(二) master/slave、sentinel、Cluster简单总结
- Redis-Cluster实战--5.使用redis-cli安装
- 详解JavaEE 使用 Redis 数据库进行内容缓存和高访问负载
- spring配置单Redis,Sentinel 哨兵模式,Redis Cluster集群,Redis Sharding集群
- ubuntu 使用docker运行redis
- 使用Docker运行tensorflow进行隔离式的深度学习