docker-compose部署redis集群cluster

docker-compose部署redis集群cluster,第1张

docker-compose部署redis集群cluster docker-compose部署redis:4.0.14-alpine集群

docker-compose.yml

version: '3'

services:
  master1:
    image: redis:4.0.14-alpine
    container_name: redis-cluster1-master
    command: redis-server /etc/redis/redis.conf
    stdin_open: true
    tty: true
    volumes:
      - /path/to/redis-cluster/cluster1/master/redis.conf:/etc/redis/redis.conf
      - /path/to/redis-cluster/cluster1/master/data:/data
    ports:
      - 6379:6379
    networks:
      redisNet:
        ipv4_address: ip1

  follow1:
    image: redis:4.0.14-alpine
    container_name: redis-cluster1-follower
    command: redis-server /etc/redis/redis.conf
    stdin_open: true
    tty: true
    volumes:
      - /path/to/redis-cluster/cluster1/follower/redis.conf:/etc/redis/redis.conf
      - /path/to/redis-cluster/cluster1/follower/data:/data
    ports:
      - 6380:6379
    networks:
      redisNet:
        ipv4_address: ip2

  master2:
    image: redis:4.0.14-alpine
    container_name: redis-cluster2-master
    command: redis-server /etc/redis/redis.conf
    stdin_open: true
    tty: true
    volumes:
      - /path/to/redis-cluster/cluster2/master/redis.conf:/etc/redis/redis.conf
      - /path/to/redis-cluster/cluster2/master/data:/data
    ports:
      - 6381:6379
    networks:
      redisNet:
        ipv4_address: ip3

  follow2:
    image: redis:4.0.14-alpine
    container_name: redis-cluster2-follower
    command: redis-server /etc/redis/redis.conf
    stdin_open: true
    tty: true
    volumes:
      - /path/to/redis-cluster/cluster2/follower/redis.conf:/etc/redis/redis.conf
      - /path/to/redis-cluster/cluster2/follower/data:/data
    ports:
      - 6382:6379
    networks:
      redisNet:
        ipv4_address: ip4

  master3:
    image: redis:4.0.14-alpine
    container_name: redis-cluster3-master
    command: redis-server /etc/redis/redis.conf
    stdin_open: true
    tty: true
    volumes:
      - /path/to/redis-cluster/cluster3/master/redis.conf:/etc/redis/redis.conf
      - /path/to/redis-cluster/cluster3/master/data:/data
    ports:
      - 6383:6379
    networks:
      redisNet:
        ipv4_address: ip5

  follow3:
    image: redis:4.0.14-alpine
    container_name: redis-cluster3-follower
    command: redis-server /etc/redis/redis.conf
    stdin_open: true
    tty: true
    volumes:
      - /path/to/redis-cluster/cluster3/follower/redis.conf:/etc/redis/redis.conf
      - /path/to/redis-cluster/cluster3/follower/data:/data
    ports:
      - 6384:6379   
    networks:
      redisNet:
        ipv4_address: ip6

networks:
  redisNet:
    external: true

使用external docker网络
启动 docker-compose up -d
停止 docker-compose down

启动成功后,通过redis-cli命令创建集群

redis-cli --cluster create --cluster-replicas 1 ip1:6379 ip2:6379 ip3:6379 ip4:6379 ip5:6379 ip6:6379

此命令默认以ip1,ip3,ip5作为master节点,ip2,ip4,ip6作为slave节点创建三个主从节点的cluster

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5624223.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存