docker-compose配置redis集群


创建文件夹

在 /usr/local/docker/下创建,方便管理

cd /usr/local/docker
mkdir reids-cluster # 创建redis-1~redis-6文件夹 mkdir redis-cluster/redis-1 / redis-cluster/redis-2 / redis-cluster/redis-3 / redis-cluster/redis-4 / redis-cluster/redis-5 / redis-cluster/redis-6

新建配置文件

cd redis-cluster

cat > redis-1/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6379 # redis监听端口 EOF cat > redis-2/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6380 # redis监听端口 EOF cat > redis-3/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6381 # redis监听端口 EOF cat > redis-4/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6382 # redis监听端口 EOF cat > redis-5/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6383 # redis监听端口 EOF cat > redis-6/redis.conf << EOF cluster-enabled yes # 开启集群 cluster-config-file nodes.conf # 集群配置文件 cluster-node-timeout 5000 # 集群节点多少时间未响应视为该节点丢失 appendonly yes port 6384 # redis监听端口 EOF

docker-compose.yaml文件配置 (复制有问题可以用 cat > docker-compose.yaml << EOF)

version: '3'
services:
  # redis1配置
  redis1:
    image: redis:6.0.16
    container_name: redis-1
    restart: always
    network_mode: "host"
    volumes:
      - ./redis-1/redis.conf:/usr/local/etc/redis/redis.conf
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
  # redis2配置
  redis2:
    image: redis:6.0.16
    container_name: redis-2
    restart: always
    network_mode: "host"
    volumes:
      - ./redis-2/redis.conf:/usr/local/etc/redis/redis.conf
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
  # redis3配置
  redis3:
    image: redis:6.0.16
    container_name: redis-3
    restart: always
    network_mode: "host"
    volumes:
      - ./redis-3/redis.conf:/usr/local/etc/redis/redis.conf
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
  # redis4配置
  redis4:
    image: redis:6.0.16
    container_name: redis-4
    restart: always
    network_mode: "host"
    volumes:
      - ./redis-4/redis.conf:/usr/local/etc/redis/redis.conf
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
  # redis5配置
  redis5:
    image: redis:6.0.16
    container_name: redis-5
    restart: always
    network_mode: "host"
    volumes:
      - ./redis-5/redis.conf:/usr/local/etc/redis/redis.conf
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
  # redis6配置
  redis6:
    image: redis:6.0.16
    container_name: redis-6
    restart: always
    network_mode: "host"
    volumes:
      - ./redis-6/redis.conf:/usr/local/etc/redis/redis.conf
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]

启动容器

docker-compose up -d

 

原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/273183.html

(0)
上一篇 2022年7月10日
下一篇 2022年7月10日

相关推荐

发表回复

登录后才能评论