我正在尝试在系统上使用docker-compose创建一个redis-sentinel集群,并使它对主机可见(这是为了尝试复制将在本地使用redis-sentinel的应用程序)。
我创建了以下docker-compose.yaml
文件来设置哨兵和Redis本身
version: '2'
networks:
app-tier:
driver: bridge
services:
redis-sentinel:
image: s7anley/redis-sentinel-docker
environment:
- ANNOUNCE_IP=127.0.0.1
- ANNOUNCE_PORT=26379
- MASTER_NAME=mymaster
- MASTER=redis
networks:
- app-tier
ports:
- '26379:26379'
redis:
image: bitnami/redis:latest
environment:
- ALLOW_EMPTY_PASSWORD=yes
networks:
- app-tier
ports:
- '6379:6379'
volumes:
redis_data:
driver: local
哨兵设法启动并正确找到了redis主机,但是它似乎不尊重announce-ip
选项,实际上似乎完全忽略了它。
即当我在主机上启动redis-cli
并请求主服务器的地址时,我得到了这个
redis-cli -p 26379
127.0.0.1:26379> SENTINEL get-master-addr-by-name mymaster
1) "192.168.32.2"
2) "6379"
127.0.0.1:26379>
报告的IP应该是127.0.0.1
而不是192.168.32.2
(这是docker在网络中使用的内部IP)
这是在docker映像中使用的sentinel.conf
文件
port 26379
sentinel announce-ip 127.0.0.1
sentinel announce-port 26379
sentinel monitor mymaster redis 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel failover-timeout mymaster 180000
sentinel parallel-syncs mymaster
这是启动后redis-sentinel重写配置文件后的样子
port 26379
sentinel myid 4e7786e55f2b4ec31bdd36c1c3af6e2d3f2569e3
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 192.168.32.2 6379 2
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel current-epoch 0
# Generated by CONFIG REWRITE
dir "/data"
sentinel announce-ip "127.0.0.1"
sentinel announce-port 26379
有人知道这是什么原因吗?