• 使用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
  • 相关阅读:
    【ORACLE】什么时候ROWNUM等于0和ROWNUM小于0,两个条件不等价?
    股票程序化交易如何把交易分析简单化?
    【秋招基础知识】【3】机器学习常见判别模型和生成模型
    基于github_monitor的源代码监控+自动化监控任务生成+webhook实现飞书机器人通知
    13.4 GAS与攻击
    redisson有几种分布式算法
    BSPHP 未授权访问 信息泄露
    卡尔曼及扩展卡尔曼滤波详细推导-来自DR_CAN视频
    禁用adb install 安装app功能
    Java 独占锁ReentrantLock、读(悲观读)写锁ReentrantReadWriteLock、读(乐观读/悲观读)写锁StampedLock
  • 原文地址:https://blog.csdn.net/shui0527/article/details/134499954