redis 集群部署

部署方式:docker-compose

  • 以此镜像启动容器
    image.png

  • 编写docker-compose文件
    启动六个容器。三个主,三个从
    vi docker-compose.yml

version: "3.2"
services:
  redis-clu-m1:
    image: redis-ruby
    container_name: "redis-clu-m1"
    expose:
      - "6379"
    networks:
      - auto-cmdb_jumpserver-test
    tty: true

  redis-clu-m2:
    image: redis-ruby
    container_name: "redis-clu-m2"
    expose:
      - "6379"
    networks:
      - auto-cmdb_jumpserver-test
    tty: true

  redis-clu-m3:
    image: redis-ruby
    container_name: "redis-clu-m3"
    expose:
      - "6379"
    networks:
      - auto-cmdb_jumpserver-test
    tty: true

  redis-clu-s1:
    image: redis-ruby
    container_name: "redis-clu-s1"
    expose:
      - "6379"
    networks:
      - auto-cmdb_jumpserver-test
    tty: true

  redis-clu-s2:
    image: redis-ruby
    container_name: "redis-clu-s2"
    expose:
      - "6379"
    networks:
      - auto-cmdb_jumpserver-test
    tty: true

  redis-clu-s3:
    image: redis-ruby
    container_name: "redis-clu-s3"
    expose:
      - "6379"
    networks:
      - auto-cmdb_jumpserver-test
    tty: true
networks:
  auto-cmdb_jumpserver-test:
    external:
        name: auto-cmdb_jumpserver-test

  • 以之前自定义的此网络作为六个容器的网络
    image.png

redis 集群部署_第1张图片

  • 下载redis-trib.rb文件
    vi /usr/sbin/redis-trib.rb
    chmod 755 /usr/sbin/redis-trib.rb
    https://github.com/antirez/redis/blob/3.2/src/redis-trib.rb

  • 拷贝文件


docker cp redis-clu-m1:/etc/redis-cluster.conf .
docker cp redis-cluster.conf redis-clu-s3:/etc/
redis 集群部署_第2张图片

  • 以配置文件启动服务
    docker-compose exec redis-clu-s3 redis-server /etc/redis-cluster.conf
    redis 集群部署_第3张图片

  • 启动集群服务
    redis-trib.rb create --replicas 1 redis-clu-m1:6379 redis-clu-m2:6379 redis-clu-m3:6379 redis-clu-s1:6379 redis-clu-s2:6379 redis-clu-s3:6379

**注意:**如果容器名不能被解析,也可使用容器ip方式
redis-trib.rb create --replicas 1 172.22.0.6:6379 172.22.0.7:6379 172.22.0.3:6379 172.22.0.2:6379 172.22.0.5:6379 172.22.0.4:6379

redis 集群部署_第4张图片

  • 六个容器对应的ip
172.22.0.6      redis-clu-m1
172.22.0.7      redis-clu-m2
172.22.0.3      redis-clu-m3
172.22.0.2      redis-clu-s1
172.22.0.5      redis-clu-s2
172.22.0.4      redis-clu-s3
  • 如果出现如下报错,可参考文章:
    ERR Slot 741 is already busy (Redis::CommandError)

image.png

  • 解决方案:
    六个Redis集群中,flushall清空各个节点上的数据,并执行cluster reset指令
    redis 集群部署_第5张图片

  • 重启集群服务
    redis-trib.rb create --replicas 1 172.22.0.6:6379 172.22.0.7:6379 172.22.0.3:6379 172.22.0.2:6379 172.22.0.5:6379 172.22.0.4:6379
    redis 集群部署_第6张图片

redis 集群部署_第7张图片

redis 集群部署_第8张图片

你可能感兴趣的:(运维,redis,集群部署)