侧边栏壁纸
  • 累计撰写 39 篇文章
  • 累计创建 51 个标签
  • 累计收到 2 条评论

目 录CONTENT

文章目录

docker-compose快速部署redis-cluster

叶子
2024-08-05 / 0 评论 / 0 点赞 / 86 阅读 / 607 字

docker-compose.yml

version: "3.3"

# 定义服务
services:
  redis-6380: # 服务名称
    image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:5.0.14-alpine # 容器镜像
    container_name: redis-6380 # 容器名称
    network_mode: "host" # host 网络模式
    ports: # 映射端口
      - 6380:6380
    volumes: # 目录挂载
      - /root/docker/redis-cluster/6380/conf/redis.conf:/usr/local/redis/redis.conf
      - /root/docker/redis-cluster/6380/data:/data
    command: redis-server /usr/local/redis/redis.conf # 服务启动命令

  redis-6381:
    image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:5.0.14-alpine
    container_name: redis-6381
    network_mode: "host"
    ports:
      - 6381:6381
    volumes:
      - /root/docker/redis-cluster/6381/conf/redis.conf:/usr/local/redis/redis.conf
      - /root/docker/redis-cluster/6381/data:/data
    command: redis-server /usr/local/redis/redis.conf

  redis-6382:
    image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:5.0.14-alpine
    container_name: redis-6382
    network_mode: "host"
    ports:
      - 6382:6382
    volumes:
      - /root/docker/redis-cluster/6382/conf/redis.conf:/usr/local/redis/redis.conf
      - /root/docker/redis-cluster/6382/data:/data
    command: redis-server /usr/local/redis/redis.conf

  redis-6383:
    image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:5.0.14-alpine
    container_name: redis-6383
    network_mode: "host"
    ports:
      - 6383:6383
    volumes:
      - /root/docker/redis-cluster/6383/conf/redis.conf:/usr/local/redis/redis.conf
      - /root/docker/redis-cluster/6383/data:/data
    command: redis-server /usr/local/redis/redis.conf

  redis-6384:
    image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:5.0.14-alpine
    container_name: redis-6384
    network_mode: "host"
    ports:
      - 6384:6384
    volumes:
      - /root/docker/redis-cluster/6384/conf/redis.conf:/usr/local/redis/redis.conf
      - /root/docker/redis-cluster/6384/data:/data
    command: redis-server /usr/local/redis/redis.conf

  redis-6385:
    image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/redis:5.0.14-alpine
    container_name: redis-6385
    network_mode: "host"
    ports:
      - 6385:6385
    volumes:
      - /root/docker/redis-cluster/6385/conf/redis.conf:/usr/local/redis/redis.conf
      - /root/docker/redis-cluster/6385/data:/data
    command: redis-server /usr/local/redis/redis.conf

redis-cluster.tmpl

# 端口号
port ${PORT}
# 绑定ip
bind 0.0.0.0
# redis-cli访问密码
requirepass EZ5jAAao3u0CvmN1
# 访问主节点密码
masterauth EZ5jAAao3u0CvmN1
# 保护模式,默认是yes,开启保护模式
protected-mode no
# 是否守护模式,docker方式不需要
daemonize no
# 是否开启AOF持久化模式
appendonly yes
# 是否开启集群模式
cluster-enabled yes
# 集群节点信息文件
cluster-config-file nodes.conf
# 集群节点连接超时时间
cluster-node-timeout 15000
# 集群节点宿主机IP
cluster-announce-ip 192.168.88.128
# 集群节点映射端口
cluster-announce-port ${PORT}
# 集群节点总线端口
cluster-announce-bus-port 1${PORT}
redis-cli -a bingo --cluster create 192.168.88.128:6380 192.168.88.128:6381 192.168.88.128:6382 192.168.88.128:6383 192.168.88.128:6384 192.168.88.128:6385 --cluster-replicas 1

参考链接

https://blog.csdn.net/rulaixiong/article/details/135822024

0

评论区