我是靠谱客的博主 哭泣人生,最近开发中收集的这篇文章主要介绍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

最后

以上就是哭泣人生为你收集整理的docker-compose部署redis集群cluster的全部内容,希望文章能够帮你解决docker-compose部署redis集群cluster所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部