美文网首页
05.`Ubuntu18.04`下`docker-compose

05.`Ubuntu18.04`下`docker-compose

作者: 风安峻_ | 来源:发表于2020-09-15 00:54 被阅读0次
    1. 部署三主三从
    1. 编辑redis.conf文件,并复制5
      1. 创建 6 个文件夹

        mkdir -p redis-cluster-mode/redis/
        
        cd redis-cluster-mode/redis/
        
        mkdir -p master1/conf/ master2/ master3/ slave1/ slave2/ slave3/
        
      2. 获取redis.conf配置文件

        
        cd master1/conf/
        
        wget http://download.redis.io/redis-stable/redis.conf
        
      3. 修改配置文件

        1. vim redis.conf

        2. 命令模式下命令输入那里/关键字可以快速查找

          • 命令模式下u撤销
          • 命令模式下Ctrl + r回复被撤销的操作
        3. 注释掉bind 127.0.0.1

        4. # requirepass foobared撤销注释,并修改密码,6个redis密码要一致

        5. # masterauth <master-password>撤销注释,并将<master-password>改为设置的密码。开启验证

        6. # cluster-enabled yes撤销注释,开启集群模式

        7. # cluster-config-file nodes-6379.conf撤销注释,nodes-6379.conf集群信息的记录文件

      4. 复制文件

        # 返回到 master1 同级目录
        cd ../../
        
        # 复制
        cp -rf master1/conf/ master2/
        
        cp -rf master1/conf/ master3/
        
        cp -rf master1/conf/ slave1/
        
        cp -rf master1/conf/ slave2/
        
        cp -rf master1/conf/ slave3/
        
    1. 编辑docker-compose.yml文件
      1. 回到reids/同级目录

        cd ../
        
      2. vim docker-compose.yml

        version: "3.7"
        services:
          redis-master-1:
            image: redis
            volumes:
              - ./redis/master1/conf/redis.conf:/etc/redis/redis.conf
              - ./redis/master1/conf/nodes-6379.conf:/etc/redis/nodes-6379.conf
            ports: 
              - 6381:6379
            command: ['redis-server', '/etc/redis/redis.conf']
                  
          redis-master-2:
            image: redis
            volumes:
              - ./redis/master2/conf/redis.conf:/etc/redis/redis.conf
              - ./redis/master2/conf/nodes-6379.conf:/etc/redis/nodes-6379.conf
            ports: 
              - 6382:6379
            command: ['redis-server', '/etc/redis/redis.conf']
               
          redis-master-3:
            image: redis
            volumes:
              - ./redis/master3/conf/redis.conf:/etc/redis/redis.conf
              - ./redis/master3/conf/nodes-6379.conf:/etc/redis/nodes-6379.conf
            ports: 
              - 6383:6379
            command: ['redis-server', '/etc/redis/redis.conf']
          
          redis-slave-1:
            image: redis
            volumes:
              - ./redis/slave1/conf/redis.conf:/etc/redis/redis.conf
              - ./redis/slave1/conf/nodes-6379.conf:/etc/redis/nodes-6379.conf
            ports: 
              - 6384:6379
            command: ['redis-server', '/etc/redis/redis.conf']
            
          redis-slave-2:
            image: redis
            volumes:
              - ./redis/slave2/conf/redis.conf:/etc/redis/redis.conf
              - ./redis/slave2/conf/nodes-6379.conf:/etc/redis/nodes-6379.conf
            ports: 
              - 6385:6379
            command: ['redis-server', '/etc/redis/redis.conf']
            
          redis-slave-3:
            image: redis
            volumes:
              - ./redis/slave3/conf/redis.conf:/etc/redis/redis.conf
              - ./redis/slave3/conf/nodes-6379.conf:/etc/redis/nodes-6379.conf
            ports: 
              - 6386:6379
            command: ['redis-server', '/etc/redis/redis.conf']       
        
      3. docker-compose up -d

      4. 查看容器是否启动成功

        docker ps -a
        
      5. 查看redis容器的ip

        # 这是查看的公式,将docker ps -a 查看到的 6 个的 <CONTAINER ID> 代进去
        # 根据设置的端口号 6881 - 6886 来进行查看,方便后续排序,设置主从
        docker inspect <CONTAINER ID> | grep IPA
        
      6. 进入其中一个容器

        docker exec -it <CONTAINER ID> /bin/bash
        
      7. 开启redis

        redis-cli -a <密码>
        
      8. 将其中其他的redis加入集群

        cluster meet ip 6379
        
      9. 查看集群节点

        cluster nodes
        
        # 退出 redis
        exit
        
      10. 配置三主三从

        redis-cli --cluster create <6个redis的 ip:端口> -a <密码> --cluster-replicas 1
        

    相关文章

      网友评论

          本文标题:05.`Ubuntu18.04`下`docker-compose

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