docker-compose 多机 Redis 一主两从 哨兵模式

1、服务器配置方案

2、安装redis 

2.1、安装正式一(Master)

创建基础目录

mkdir -p /data/redis/{conf,data}

创建配置文件

touch /data/redis/conf/redis.conf

 编辑vi redis.conf

bind 0.0.0.0
port 6379
logfile "6379.log"
daemonize no
protected-mode no
masterauth "123456"
requirepass 123456
replica-announce-ip "10.0.1.237"   #本机IP
replica-announce-port 6379

创建vi docker-compose.yml文件 

version: '3'
services:
  redis:
    image: redis:6.0.6
    container_name: redis-master
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 6379:6379
      - 16379:16379
    privileged: true
    volumes:
      - /data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - /data/redis/data:/data
    command: sh -c "redis-server /usr/local/etc/redis/redis.conf"

2.2、安装正式二(Slave)

创建基础目录

mkdir -p /data/redis/{conf,data}

创建配置文件

touch /data/redis/conf/redis.conf

编辑vi redis.conf

bind 0.0.0.0
port 6379
logfile "6379.log"
daemonize no
protected-mode no
masterauth "123456"
requirepass 123456
replicaof 10.0.1.237 6379
replica-announce-ip "10.0.1.143"
replica-announce-port 6379

创建vi docker-compose.yml文件 

version: '3'
services:
  redis:
    image: redis:6.0.6
    container_name: redis-slave
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 6379:6379
      - 16379:16379
    privileged: true
    volumes:
      - /data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - /data/redis/data:/data
    command: sh -c "redis-server /usr/local/etc/redis/redis.conf"

2.3、安装灾备一 (Slave)

创建基础目录

mkdir -p /data/redis/{conf,data}

创建配置文件

touch /data/redis/conf/redis.conf

编辑vi redis.conf

bind 0.0.0.0
port 6379
logfile "6379.log"
daemonize no
protected-mode no
masterauth "123456"
requirepass 123456
replicaof 10.0.1.237 6379
replica-announce-ip "10.0.1.198 "
replica-announce-port 6379

创建vi docker-compose.yml文件 

version: '3'
services:
  redis:
    image: redis:6.0.6
    container_name: redis-slave
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 6379:6379
      - 16379:16379
    privileged: true
    volumes:
      - /data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf
      - /data/redis/data:/data
    command: sh -c "redis-server /usr/local/etc/redis/redis.conf"

3、启动redis服务 

docker-compose up -d


docker ps

4、安装sentinel

4.1、安装正式一

创建基础目录

mkdir -p /data/sentinel/conf

创建配置文件sentinel.conf

port 26379
dir /tmp
protected-mode no
daemonize yes
sentinel monitor mymaster 10.0.1.237 6379 2
sentinel auth-pass mymaster 123456 
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000  
sentinel deny-scripts-reconfig yes
sentinel announce-ip "10.0.1.237"
sentinel announce-port 26379

创建vi docker-compose.yml文件 

version: '3'
services:
  sentinel:
    image: redis:6.0.6
    container_name: sentinel
    ports:
      - 26379:26379
    privileged: true
    volumes:
      - /data/sentinel/sentinel.conf:/usr/local/etc/redis/sentinel.conf
    command: sh -c "redis-sentinel /usr/local/etc/redis/sentinel.conf"

2.2、安装正式二

创建基础目录

mkdir -p /data/sentinel/conf

创建配置文件sentinel.conf

port 26379
dir /tmp
protected-mode no
daemonize yes
sentinel monitor mymaster 10.0.1.237 6379 2
sentinel auth-pass mymaster 123456 
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000  
sentinel deny-scripts-reconfig yes
sentinel announce-ip "10.0.1.143"
sentinel announce-port 26379

创建vi docker-compose.yml文件 

version: '3'
services:
  sentinel:
    image: redis:6.0.6
    container_name: sentinel
    ports:
      - 26379:26379
    privileged: true
    volumes:
      - /data/sentinel/sentinel.conf:/usr/local/etc/redis/sentinel.conf
    command: sh -c "redis-sentinel /usr/local/etc/redis/sentinel.conf"

4.3、安装灾备一

创建基础目录

mkdir -p /data/sentinel/conf

创建配置文件sentinel.conf

port 26379 
dir /tmp
protected-mode no
daemonize yes
sentinel monitor mymaster 10.0.1.237 6379 2
sentinel auth-pass mymaster 123456 
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000  
sentinel deny-scripts-reconfig yes
sentinel announce-ip "10.0.1.198"
sentinel announce-port 26379

创建vi docker-compose.yml文件 

version: '3'
services:
  sentinel:
    image: redis:6.0.6
    container_name: sentinel
    ports:
      - 26379:26379
    privileged: true
    volumes:
      - /data/sentinel/sentinel.conf:/usr/local/etc/redis/sentinel.conf
    command: sh -c "redis-sentinel /usr/local/etc/redis/sentinel.conf"

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值