• docker 搭建 redis 集群(哨兵模式)


    文件结构

    1. redis-sentinel

     1-1.  docker-compose.yml
    

    1-2. sentinel

       1-2-1 docker-compose.yml
       
      1-2-2 sentinel.conf
       
      1-2-3 sentinel1.conf
      
      1-2-4 sentinel2.conf
      
      1-2-5 sentinel3.conf
    

    1、docker-compose 文件实现一主两从

    编写docker-compose.yml文件,内容如下:

    version: '3.7'
    services:
      master:
        image: redis
        container_name: redis-master
        restart: always
        command: redis-server --requirepass GaosiDev --masterauth GaosiDev  
        ports:
          - 6380:6379
    
      slave1:
        image: redis
        container_name: redis-slave-1
        restart: always
        command: redis-server --slaveof redis-master 6379  --requirepass GaosiDev --masterauth GaosiDev  
        ports:
          - 6381:6379
    
    
      slave2:
        image: redis
        container_name: redis-slave-2
        restart: always
        command: redis-server --slaveof redis-master 6379  --requirepass GaosiDev --masterauth GaosiDev  
        ports:
          - 6382:6379
    

    docker-compose 文件实现 sentinel

    version: '2'
    services:
      sentinel1:
        image: redis       ## 镜像
        container_name: redis-sentinel-1
        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
        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-sentinel_default    ##通过(docker inspect 主节点容器id)来查看,对应 NetworkMode 
    

    编辑 sentinel.conf 文件

    port 26379
    dir /tmp
    #172.18.0.3填写自己的主节点ip,通过(docker inspect 主节点容器id)来查看,对应 IPAddress
    sentinel monitor mymaster 172.17.0.4 6379 2
    sentinel auth-pass mymaster GaosiDev 
    sentinel down-after-milliseconds mymaster 30000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 10000  
    sentinel deny-scripts-reconfig yes
    

    参考链接

    https://www.cnblogs.com/ruiyeclub/p/12355073.html

    https://www.cnblogs.com/JulianHuang/p/12650721.html

  • 相关阅读:
    [leetCode]404. 左叶子之和
    [leetCode]572. 另一个树的子树
    [leetCode]226. 翻转二叉树
    [leetCode]637. 二叉树的层平均值
    [leetCode]102. 二叉树的层序遍历
    [leetCode]590. N叉树的后序遍历
    [leetCode]589. N叉树的前序遍历
    [leetCode]145. 二叉树的后序遍历
    [leetCode]94. 二叉树的中序遍历
    [leetCode]381. O(1) 时间插入、删除和获取随机元素
  • 原文地址:https://www.cnblogs.com/daleyzou/p/docker-redis-sentinel.html
Copyright © 2020-2023  润新知