美文网首页docker
docker搭建redisCluster集群

docker搭建redisCluster集群

作者: SparkOnly | 来源:发表于2020-09-24 15:56 被阅读0次

    假设当前目录为/data/db/redis

    1. 下载redis配置文件 http://download.redis.io/redis-stable/redis.conf
    2. 创建config目录,将下载的redis.conf复制到config目录,修改如下信息
    #bind 127.0.0.1               #注释掉地址绑定
    port 700*                    #3份配置文件,从7001到7003
    appendonly yes                #允许持久化
    cluster-enable yes             #启用集群
    cluster-config-file nodes-700*.conf  #存放节点配置信息的文件名,从7001到7003
    cluster-node-timeout 15000        #节点失效检测的超时时间
    

    在config目录下分别创建redis-7001.conf, redis-7002.conf, redis-7003.conf

    1. 创建7001, 7002, 7003目录
    2. 创建docker-compose.yml文件
    version: "3.8"
    services:
      redis-master1:
        image: redis:latest
        container_name: redis-7001
        #stdin_open: true
        tty: true
        restart: always
        network_mode: host  #需要为host模式
        privileged: true
        volumes:
        - /data/db/redis/config/redis-7001.conf:/usr/local/etc/redis/redis.conf
        - ./7001:/data
        command:
          redis-server /usr/local/etc/redis/redis.conf
      redis-master2:
        image: redis:latest
        container_name: redis-7002
        tty: true
        restart: always
        network_mode: host
        privileged: true
        volumes:
        - /data/db/redis/config/redis-7002.conf:/usr/local/etc/redis/redis.conf
        - ./7002:/data
        command:
          redis-server /usr/local/etc/redis/redis.conf
      redis-master3:
        image: redis:latest
        container_name: redis-7003
        tty: true
        restart: always
        network_mode: host
        privileged: true
        volumes:
        - /data/db/redis/config/redis-7003.conf:/usr/local/etc/redis/redis.conf
        - ./7003:/data
        command:
          redis-server /usr/local/etc/redis/redis.conf
    
    1. 启动redis服务
    docker-compose up -d
    
    1. 进入其中一台容器,进行集群创建
    docker exec -it redis-7001 bash
    redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 --cluster-replicas 0
    

    此时根据命令行提示输入yes,即可创建集群成功

    注:
    官方备注,网络模式需要为host


    image.png

    相关文章

      网友评论

        本文标题:docker搭建redisCluster集群

        本文链接:https://www.haomeiwen.com/subject/dkzzyktx.html