天天看点

docker 搭建 redis sentinel

本文主要mark下redis sentinel搭建过程,本次搭建redis使用master+ slave,sentinel使用最小配置(3个)

redis sentinel 扫盲请参考 https://redis.io/topics/sentinel

DJY(management+djy+datasync) local testbed installation

文章目录

  1. 下载redis5.0 dockers镜像文件
  2. 使用下述dockers compose文件, 创建3个镜像redis (master +2 slave )
    version: '3.7'
    services:
      redis-master:
        image: redis:5
        container_name: redis-master
        restart: always
        network_mode: "host"
        volumes:
          - type: volume
            source: redis-master
            target: /data
        command: --appendonly yes --port 6379
        
      redis-slave1:
        image: redis:5
        container_name: redis-slave1
        restart: always
        depends_on:
          - redis-master
        network_mode: "host"
        volumes:
          - type: volume
            source: redis-slave1
            target: /data
        command: --appendonly yes --port 6380 --slaveof 127.0.0.1 6379 
        
      redis-slave2:
        image: redis:5
        container_name: redis-slave2
        restart: always
        depends_on:
          - redis-master
        network_mode: "host"
        volumes:
          - type: volume
            source: redis-slave2
            target: /data
        command: --appendonly yes --port 6381 --slaveof 127.0.0.1 6379
        
    volumes:
      redis-master:
      redis-slave1:
      redis-slave2:
               
    使用如下命令创建redis 容器
    docker-compose up -d
               
  3. redis sentinel 安装

    redis sentinel最小需要配置三个sentinel。

    sentinel leader 配置文件内容如下:

    port 36379
    dir "/var/redis/data"
    sentinel myid 29c0734753f7de85017a1111ce2b46a7a780ab9d
    sentinel deny-scripts-reconfig yes
    sentinel monitor redis-master 127.0.0.1 6379 2
    sentinel config-epoch redis-master 0
               
    sentinel follow1 配置文件内容如下:
    port 36380
    dir "/var/redis/data"
    sentinel myid b290690d6817d721e3872cd142e4f58f90034b22
    sentinel deny-scripts-reconfig yes
    sentinel monitor redis-master 127.0.0.1 6379 2
    sentinel config-epoch redis-master 0
               
    sentinel follow2 配置文件内容如下:
    port 36381
    dir "/var/redis/data"
    sentinel myid 2da5366952c656ccadef934b76adceee5a603e14
    sentinel deny-scripts-reconfig yes
    sentinel monitor redis-master 127.0.0.1 6379 2
    sentinel config-epoch redis-master 0
               
    sentinel使用dockers-compose 启动,compose文件内容如下:
    version: '3.7'
    services:
      redis-sentinel-leader:
        image: redis:5
        container_name: redis-sentinel-leader
        restart: always
        network_mode: "host"
        volumes:
          - type: volume
            source: redis-sentinel-leader
            target: /var/redis/data
          - type: bind
            source: ./sentinel-leader.conf  
            target: /conf/sentinel-leader.conf
        command: /conf/sentinel-leader.conf --sentinel
        
      redis-sentinel-follow1:
        image: redis:5
        container_name: redis-sentinel-follow1
        restart: always
        depends_on:
          - redis-sentinel-leader
        network_mode: "host"
        volumes:
          - type: volume
            source: redis-sentinel-follow1
            target: /var/redis/data
          - type: bind
            source: ./sentinel-follow1.conf  
            target: /conf/sentinel-follow1.conf
        command: /conf/sentinel-follow1.conf --sentinel
        
      redis-sentinel-follow2:
        image: redis:5
        container_name: redis-sentinel-follow2
        restart: always
        depends_on:
          - redis-sentinel-leader
          - redis-sentinel-follow1
        network_mode: "host"
        volumes:
          - type: volume
            source: redis-sentinel-follow2
            target: /var/redis/data
          - type: bind
            source: ./sentinel-follow2.conf  
            target: /conf/sentinel-follow2.conf
        command: /conf/sentinel-follow2.conf --sentinel
        
    volumes:
      redis-sentinel-leader:
      redis-sentinel-follow1:
      redis-sentinel-follow2:
               
    启动redis sentinel使用docker compose
    docker-compose up -d
               
    启动成功后,容器的运行状态如:
[[email protected] docker-install]# docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
710ec199db2c        redis:5             "docker-entrypoint.s鈥   41 hours ago        Up 41 hours                             redis-sentinel-follow2
d19766731096        redis:5             "docker-entrypoint.s鈥   41 hours ago        Up 41 hours                             redis-sentinel-follow1
a8e12b67c3c4        redis:5             "docker-entrypoint.s鈥   41 hours ago        Up 41 hours                             redis-sentinel-leader
99abd2a8c4f5        redis:5             "docker-entrypoint.s鈥   2 days ago          Up 2 days                               redis-slave2
c9a105ca53f2        redis:5             "docker-entrypoint.s鈥   2 days ago          Up 2 days                               redis-slave1
b636cc3475aa        redis:5             "docker-entrypoint.s鈥   2 days ago          Up 2 days                               redis-master