采坑记录:
docker sentinel模式安装完后因为是使用bridge模式,所以只有docker中运行的程序才能访问。刚开始尝试使用端口映射,返现sentinel返回的地址依然是docker的内网地址。
docker-compose.yml
version: '3.2'
services:
master:
container_name: redis-master-1
image: redis:3
command: redis-server --port 16379
ports:
- "16379"
network_mode: "host"
slave:
image: redis:3
container_name: redis-slave-1
ports:
- "16380"
network_mode: "host"
command: redis-server --port 16380 --slaveof redis-master 16379
sentinel:
container_name: redis-sentinel-1
build: sentinel
ports:
- "26379"
environment:
- SENTINEL_DOWN_AFTER=5000
- SENTINEL_FAILOVER=5000
network_mode: "host"
2、sentinel.conf文件:
# Example sentinel.conf can be downloaded from http://download.redis.io/redis-stable/sentinel.conf port 26379 dir /tmp sentinel monitor mymaster redis-master 16379 $SENTINEL_QUORUM sentinel down-after-milliseconds mymaster $SENTINEL_DOWN_AFTER sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster $SENTINEL_FAILOVER
3、由于compose和sentinel都使用域名连接master:redis-master,则需要在/etc/hosts中配置该域名解析
10.8.0.1 redis-master
注意此处一定要解析成程序能访问到的IP地址。
4、docker相关的一些命令
查看运行中的容器:docker container ls
启动tracker:docker container start tracker
启动storage:docker container start storage
停止tracker:docker container stop tracker
停止storage:docker container stop storage
docker exec -it tracker /bin/bash
docker logs xxx 查看日志 xxxx为容器Id
docker ps -a 查看所有
netstat -anp |grep 22122 docker exec -it redis-sentinel-1 redis-cli -h 10.8.0.1 -p 26379 SENTINEL get-master-addr-by-name mymaster 获取sentinel返回的redis节点地址
docker exec -it redis-sentinel-1 redis-cli -h 10.8.0.1 -p 26379 SENTINEL slaves mymaster 获取sentinel返回的redis节点地址