zoukankan      html  css  js  c++  java
  • 7.DockerCompose 搭建 Redis

    搭建一主两从环境,docker-compose.yml 配置如下:

    version: '3.1'
    services:
      master:
        image: redis
        container_name: redis-master
        ports:
          - 6379:6379
    
      slave1:
        image: redis
        container_name: redis-slave-1
        ports:
          - 6380:6379
        command: redis-server --slaveof redis-master 6379
    
      slave2:
        image: redis
        container_name: redis-slave-2
        ports:
          - 6381:6379
        command: redis-server --slaveof redis-master 6379

    搭建 Sentinel 集群

    我们至少需要创建三个 Sentinel 服务,docker-compose.yml 配置如下:

    version: '3.1'
    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

    修改 Sentinel 配置文件

    需要三份 sentinel.conf 配置文件,分别为 sentinel1.conf,sentinel2.conf,sentinel3.conf,配置文件内容相同
    port 26379
    dir /tmp
    # 自定义集群名,其中 127.0.0.1 为 redis-master 的 ip,6379 为 redis-master 的端口,2 为最小投票数(因为有 3 台 Sentinel 所以可以设置成 2)
    sentinel monitor mymaster 192.168.171.128 6379 2
    sentinel down-after-milliseconds mymaster 30000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 180000
    sentinel deny-scripts-reconfig yes
    查看集群是否生效
    进入 Sentinel 容器,使用 Sentinel API 查看监控情况:
    docker exec -it redis-sentinel-1 /bin/bash
    redis-cli -p 26379
    sentinel master mymaster
    sentinel slaves mymaster

    博客园:https://www.cnblogs.com/xianquan
    Copyright ©2020 l-coil
    【转载文章务必保留出处和署名,谢谢!】
查看全文
  • 相关阅读:
    UVa OJ 102 Ecological Bin Packing (生态学装箱问题)
    最小生成树 zoj1586 QS Network
    最小生成树&并查集 POJ 1861 Network
    最小生成树&并查集POJ 1287 Networking
    2012年亚洲长春区域赛:K Yukari's Birthday
    最小生成树 ZOJ 1203 Swordfish
    HDU 2639 Bone Collector II
    POJ2528 Mayor's posters(区间替换&&线段切割)
    POJ2777 Count Color(区间修改&&懒惰标记&&位运算)
    (转)有关如何入门ACM
  • 原文地址:https://www.cnblogs.com/xianquan/p/13236486.html
  • Copyright © 2011-2022 走看看