docker-compose安装redis-sentinel集群

安装Docker-compose

  1. 安装docker-compose, 执行下面的命令,可通过https://docs.docker.com/compose/install/#install-compose, 找到docker-compose linux安装方法。
    sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-uname -s-uname -m -o /usr/local/bin/docker-compose

  2. 添加目录权限
    sudo chmod +x /usr/local/bin/docker-compose

  3. 验证docker-compose安装是否成功
    docker-compose --version
    #安装需要目录
    mkdir -p /home/redis-sentinel-cluster/data/master
    mkdir -p /home/redis-sentinel-cluster/data/slave1
    mkdir -p /home/redis-sentinel-cluster/data/slave2
    mkdir -p /home/redis-sentinel-cluster/data/slave3
    mkdir -p /home/redis-sentinel-cluster/data/sentinel-1
    mkdir -p /home/redis-sentinel-cluster/data/sentinel-2
    mkdir -p /home/redis-sentinel-cluster/data/sentinel-3
    mkdir -p /var/redis/log

vim /home/redis-sentinel-cluster/sentinel-1.conf

port 26383
dir “/home/redis-sentinel-cluster”
sentinel monitor mymaster 192.168.0.124 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 5000
sentinel parallel-syncs mymaster 1
sentinel config-epoch mymaster 0

vim /home/redis-sentinel-cluster/sentinel-2.conf

port 26380
dir “/home/redis-sentinel-cluster”
sentinel monitor mymaster 192.168.0.124 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 5000
sentinel parallel-syncs mymaster 1
sentinel config-epoch mymaster 0

vim /home/redis-sentinel-cluster/sentinel-3.conf

port 26381
dir “/home/redis-sentinel-cluster”
sentinel monitor mymaster 192.168.0.124 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 5000
sentinel parallel-syncs mymaster 1
sentinel config-epoch mymaster 0

#部分参数解释
1)monitor 指的是初始化的监控主切点,ip和端口,后面的数字3代表,必须3个sentinel才能判断主节点是否失败

2)down-after-milliseconds 指的是超过5000秒,且没有回复,则判定主节点不可达

3)failover-timeout 指的是故障转移时间

4)parallel-syncs 指的是故障转移到新的主节点时,从节点的复制节点数量

vim /home/redis-sentinel-cluster/docker-compose.yml

version: ‘3.1’
services:
master:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis:3
container_name: master

network_mode: "host"
volumes:
  - ./data/master:/data
  - ./log:/var/redis/log
command: redis-server --port 6379

slave1:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis:3
container_name: slave1

network_mode: "host"
volumes:
  - ./data/slave1:/data
  - ./log:/var/redis/log
command: redis-server --port 26384 --slaveof 192.168.0.124 6379

slave2:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis:3
container_name: slave2

network_mode: "host"
volumes:
  - ./data/slave2:/data
  - ./log:/var/redis/log
command: redis-server --port 26385 --slaveof 192.168.0.124 6379

slave3:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis:3
container_name: slave3

network_mode: "host"
volumes:
  - ./data/slave3:/data
  - ./log:/var/redis/log
command: redis-server --port 26386 --slaveof 192.168.0.124 6379  

sentinel-1:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis-sentinel:3
container_name: sentinel-1

network_mode: "host"
volumes:
  - ./sentinel-1.conf:/etc/redis/sentinel.conf
  - ./data/sentinel-1:/data
  - ./log:/var/redis/log

sentinel-2:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis-sentinel:3
container_name: sentinel-2

network_mode: "host"
volumes:
  - ./sentinel-2.conf:/etc/redis/sentinel.conf
  - ./data/sentinel-2:/data
  - ./log:/var/redis/log

sentinel-3:
image: registry.cn-hangzhou.aliyuncs.com/boshen-ns/redis-sentinel:3
container_name: sentinel-3

network_mode: "host"
volumes:
  - ./sentinel-3.conf:/etc/redis/sentinel.conf
  - ./data/sentinel-3:/data
  - ./log:/var/redis/log

#redis启动与哨兵启动
cd /home/redis-sentinel-cluster
docker-compose up -d
redis-sentinel sentinel-*.conf

备注:当6379被占用时,可以改为其他端口如16379

当突然断电时,删除/home/redis-sentinel-cluster/data/master/下的数据重启,如果还不行whereis redis ,然后删除查出的目录/etc/redis/下所有数据

你可能感兴趣的:(docker部署服务)