当前位置: 首页 > news >正文

docker-compose 搭建伪分布模式redis cluster集群

1、redis配置文件:redis.conf

port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

2、创建文件和目录

for port in `seq 7001 7006`; do \
  mkdir -p ./${port}/conf \
  && PORT=${port} envsubst < ./redis-conf.tmpl > ./${port}/conf/redis.conf \
  && mkdir -p ./${port}/data; \
done

├── 7001
│   ├── conf
│   │   └── redis.conf
│   └── data
│       ├── appendonly.aof
│       ├── dump.rdb
│       └── nodes.conf ..........
├── 7006
│   ├── conf
│   │   └── redis.conf
│   └── data
│       ├── appendonly.aof
│       ├── dump.rdb
│       └── nodes.conf

3、docker-compose.yml文件

version: "3.7"

networks:
  redis-network:
    name: redis-network
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.18.0.0/24

services:
  redis-cluster: #该容器只是执行一条命令,可以删除手动进入执行
    image: redis:6-alpine
    command: 'redis-cli --cluster create
    172.18.0.11:6379 172.18.0.12:6379 172.18.0.13:6379 172.18.0.14:6379
    172.18.0.15:6379 172.18.0.16:6379 --cluster-yes --cluster-replicas 1'
    networks:
      - redis-network
    depends_on:
      - redis1
      - redis2
      - redis3
      - redis4
      - redis5
      - redis6

  redis1:
    image: redis:6-alpine
    container_name: redis1
    command: redis-server /usr/local/etc/redis/redis.conf
    networks:
      redis-network:
        ipv4_address: 172.18.0.11
    expose:
      - 6379
    volumes:
      - /Users/上面2创建的目录/redis/7001/data:/data
      - /Users/上面2创建的目录/redis/7001/conf/redis.conf:/usr/local/etc/redis/redis.conf

  redis2:
    image: redis:6-alpine
    container_name: redis2
    command: redis-server /usr/local/etc/redis/redis.conf
    networks:
      redis-network:
        ipv4_address: 172.18.0.12
    expose:
      - 6379
    volumes:
      - /Users/上面2创建的目录/redis/7002/data:/data
      - /Users/上面2创建的目录/redis/7002/conf/redis.conf:/usr/local/etc/redis/redis.conf

  redis3:
    image: redis:6-alpine
    container_name: redis3
    command: redis-server /usr/local/etc/redis/redis.conf
    networks:
      redis-network:
        ipv4_address: 172.18.0.13
    expose:
      - 6379
    volumes:
      - /Users/上面2创建的目录/redis/7003/data:/data
      - /Users/上面2创建的目录/redis/7003/conf/redis.conf:/usr/local/etc/redis/redis.conf

  redis4:
    image: redis:6-alpine
    container_name: redis4
    command: redis-server /usr/local/etc/redis/redis.conf
    networks:
      redis-network:
        ipv4_address: 172.18.0.14
    expose:
      - 6379
    volumes:
      - /Users/上面2创建的目录/redis/7004/data:/data
      - /Users/上面2创建的目录/redis/7005/conf/redis.conf:/usr/local/etc/redis/redis.conf

  redis5:
    image: redis:6-alpine
    container_name: redis5
    command: redis-server /usr/local/etc/redis/redis.conf
    networks:
      redis-network:
        ipv4_address: 172.18.0.15
    expose:
      - 6379
    volumes:
      - /Users/上面2创建的目录/redis/7005/data:/data
      - /Users/上面2创建的目录/redis/7005/conf/redis.conf:/usr/local/etc/redis/redis.conf

  redis6:
    image: redis:6-alpine
    container_name: redis6
    command: redis-server /usr/local/etc/redis/redis.conf
    networks:
      redis-network:
        ipv4_address: 172.18.0.16
    expose:
      - 6379
    volumes:
      - /Users/上面2创建的目录/redis/7006/data:/data
      - /Users/上面2创建的目录/redis/7006/conf/redis.conf:/usr/local/etc/redis/redis.conf

相关文章:

  • JS逆向之补环境过瑞数详解
  • 【PR #5 C】和平共处(整体二分)
  • 数组、对象操作方法
  • 2023-01-16 阿里SMS短信接口使用
  • 【linux kernel】Linux设备驱动模型 | bus
  • HTML的body元素
  • Spring Boot(五十四):SpringBoot事件监听机制
  • Fastdfs分布式文件系统原理浅析
  • 3-2存储系统-主存与CPU的连接外部存储器
  • 20230116英语学习
  • 质量体系搭建
  • PAT2.7 弹球距离
  • 华为机试题:HJ13 句子逆序(python)
  • spring学习系列
  • Pytorch模型自定义数据集训练流程
  • 云原生技术学习笔记(基础版)
  • nohup + 命令实现后台不挂断地运行程序
  • 贪心算法专题
  • Android项目Gadle统一依赖管理
  • 水声功率放大器模块在圆柱壳结构声源辐射研究中的应用