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"

你可能感兴趣的:(笔记)