redis 主从 哨兵

redis 主从

docker-compose.yml

version: '3.7'
services:
  master:
    image: redis
    container_name: redis-master
    restart: always
    command: redis-server   --appendonly yes
    ports:
      - 6379:6379
    volumes:
      - ./data1:/data
  slave1:
    image: redis
    container_name: redis-slave-1
    restart: always
    command: redis-server --slaveof redis-master 6379    --appendonly yes
    ports:
      - 6380:6379
    volumes:
      - ./data2:/data
  slave2:
    image: redis
    container_name: redis-slave-2
    restart: always
    command: redis-server --slaveof redis-master 6379   --appendonly yes
    ports:
      - 6381:6379
    volumes:
      - ./data3:/data

sudo docker-compose -f  docker-compose.yml up  -d

哨兵

docker-compose.yml

version: '3.7'
services:
  sentinel1:
    image: redis
    container_name: redis-sentinel-1
    restart: always
    ports:
      - 26379:26379
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
      - ./sentinel1.conf:/usr/local/etc/redis/sentinel.conf
  sentinel2:
    image: redis
    container_name: redis-sentinel-2
    restart: always
    ports:
    - 26380:26379
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
      - ./sentinel2.conf:/usr/local/etc/redis/sentinel.conf
  sentinel3:
    image: redis
    container_name: redis-sentinel-3
    ports:
      - 26381:26379
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    volumes:
      - ./sentinel3.conf:/usr/local/etc/redis/sentinel.conf
networks:
  default:
    external:
      name: redis_default

 配置文件

port 26379
dir /tmp
sentinel monitor mymaster 172.19.0.3 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

 解释: 172.19.0.3  redis master ip

              sentinel1.conf 

              sentinel2.conf

              sentinel3.conf

             复制3份文件和docker-compose.yml 同一级目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值