docker-compose安装redis一主二从三哨兵集群

准备

docker安装参考:

CentOS 安装 docker详解_centos安装docker_慕菲烟云的博客-CSDN博客

docker-compose安装参考:docker之docker-compose_docker compose no-cache_慕菲烟云的博客-CSDN博客

准备一台Linux服务器(IP :192.168.2.168)

编写docker-compose.yaml文件

version: '3.3'
services:
  redis-master:
    image: redis:7.0
    container_name: redis-master
    #restart: always
    command: redis-server --port 6379 --requirepass 123456  --appendonly yes --masterauth 123456 --replica-announce-ip 192.168.2.168 --replica-announce-port 6379
    volumes:
      - ./data/master:/data
    ports:
      - 6379:6379
  redis-slave-1:  
    image: redis:7.0
    container_name: redis-slave-1
    #restart: always
    command: redis-server --slaveof 192.168.2.168 6379 --port 6379  --requirepass 123456 --masterauth 123456  --appendonly yes --replica-announce-ip 192.168.2.168 --replica-announce-port 6380
    volumes:
      - ./data/slave1:/data
    ports:
      - 6380:6379
  redis-slave-2:
    image: redis:7.0
    container_name: redis-slave-2
    #restart: always
    command: redis-server --slaveof 192.168.2.168 6379 --port 6379  --requirepass 123456 --masterauth 123456  --appendonly yes --replica-announce-ip 192.168.2.168 --replica-announce-port 6381
    volumes:
      - ./data/slave2:/data
    ports:
      - 6381:6379
 
  redis-sentinel-1:
    image: redis:7.0
    container_name: redis-sentinel-1
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    #restart: always
    ports:
      - 26379:26379
    volumes:
      - ./config/sentinel1/:/usr/local/etc/redis/
 
  redis-sentinel-2:
    image: redis:7.0
    container_name: redis-sentinel-2
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    #restart: always
    ports:
      - 26380:26379
    volumes:
      - ./config/sentinel2/:/usr/local/etc/redis/
 
  redis-sentinel-3:
    image: redis:7.0
    container_name: redis-sentinel-3
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    #restart: always
    ports:
      - 26381:26379
    volumes:
      - ./config/sentinel3/:/usr/local/etc/redis/

编写sentinel.conf文件

#redis/config/sentinel1/sentinel.conf
port 26379
dir "/tmp"
sentinel monitor mymaster 192.168.2.168 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster 123456
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
#sentinel对外公布的ip地址
sentinel announce-ip "192.168.2.168"
#sentinel对外公布的端口号
sentinel announce-port 26379

#redis/config/sentinel2/sentinel.conf
port 26379
dir "/tmp"
sentinel monitor mymaster 192.168.2.168 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster 123456
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
sentinel announce-ip "192.168.2.168"
sentinel announce-port 26380

#redis/config/sentinel3/sentinel.conf
port 26379
dir "/tmp"
sentinel monitor mymaster 192.168.2.168 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster 123456
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
sentinel announce-ip "192.168.2.168"
sentinel announce-port 26381

文件目录树

redis

------config

------------sentinel1

------------------sentinel.conf

------------sentinel2

------------------sentinel.conf

------------sentinel3

------------------sentinel.conf

------ docker-compose.yaml

------data

------------master

------------slave1

------------slave2

启动验证

#进入到redis目录
cd redis
#后台启动redis集群
docker-compose up -d
#查看docker启动情况
docker ps
#进入redis-master容器
docker exec -it redis-master bash
#连接redis
redis-cli
#输入密码
auth 123456
#查看集群情况
info replication

 

 docker-compose安装redis一主二从三哨兵集群_第1张图片

你可能感兴趣的:(docker,redis,bootstrap)