• 使用docker-compose部署,宿主机可链接使用的redis cluster


    使用宿主机ip:port 搭建外部可用集群
    构建目录

     -- data
     -- config
        -- redis1.conf
        -- redis2.conf
        -- redis3.conf
        -- redis4.conf
        -- redis5.conf
        -- redis6.conf
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    docker-compose.yml

    version: "3"
    
    services:
      redis1:
        image: redis:latest
        restart: "no"
        container_name: redis1
        command: redis-server /etc/redis/redis.conf
        volumes:
          - ./data/data1:/data
          - ./config/redis1.conf:/etc/redis/redis.conf
        network_mode: "host"
    
      redis2:
        image: redis:latest
        restart: "no"
        container_name: redis2
        command: redis-server /etc/redis/redis.conf
        volumes:
          - ./data/data2:/data
          - ./config/redis2.conf:/etc/redis/redis.conf
        network_mode: "host"
    
      redis3:
        image: redis:latest
        restart: "no"
        container_name: redis3
        command: redis-server /etc/redis/redis.conf
        volumes:
          - ./data/data3:/data
          - ./config/redis3.conf:/etc/redis/redis.conf
        network_mode: "host"
    
      redis4:
        image: redis:latest
        restart: "no"
        container_name: redis4
        command: redis-server /etc/redis/redis.conf
        volumes:
          - ./data/data4:/data
          - ./config/redis4.conf:/etc/redis/redis.conf
        network_mode: "host"
    
      redis5:
        image: redis:latest
        restart: "no"
        container_name: redis5
        command: redis-server /etc/redis/redis.conf
        volumes:
          - ./data/data5:/data
          - ./config/redis5.conf:/etc/redis/redis.conf
        network_mode: "host"
    
      redis6:
        image: redis:latest
        restart: "no"
        container_name: redis6
        command: redis-server /etc/redis/redis.conf
        volumes:
          - ./data/data6:/data
          - ./config/redis6.conf:/etc/redis/redis.conf
        network_mode: "host"
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63

    redis.conf

    #端口号,写文件夹对映的端口 每个文件的端口配置都不一样 6370 - 6375
    port 6370
    #开启集群
    cluster-enabled yes
    cluster-config-file nodes.conf
    cluster-node-timeout 15000
    #开启aof存储
    appendonly yes
    #设置登录密码
    requirepass 123456
    #设置节点密码,集群必设
    masterauth 123456
    # 关闭保护,外网可直接访问
    protected-mode no
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    配置集群

    宿主机ip 192.168.56.102

    docker exec -ti redis1 bash -c 'redis-cli --cluster create --cluster-replicas 1 -a 123456 192.168.56.102:6370 192.168.56.102:6371 192.168.56.102:6372 192.168.56.102:6373 192.168.56.102:6374 192.168.56.102:6375'
    
    
    • 1
    • 2

    使用

    在宿主机上链接

     redis-cli -h 192.168.56.102 -p 6370 -a 123456 -c
    
    
    • 1
    • 2
  • 相关阅读:
    Python特征选择
    【数学知识】—— 快速幂 / 扩展欧几里得算法
    FFplay文档解读-38-视频过滤器十三
    数据结构初阶--顺序表(讲解+C++类模板实现)
    nginx发布vue项目
    libigl 网格harmonic参数化
    【Proteus仿真】【Arduino单片机】简易计算器设计
    使用springmvc来实现Excel文件导入导出
    使用 Python 的基于边缘和基于区域的分割
    ubuntu20环境搭建+Qt6安装
  • 原文地址:https://blog.csdn.net/shui0527/article/details/134499954