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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

慕菲烟云

坚持原创,希望大家多多交流

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值