设为首页 加入收藏

TOP

docker swarm快速部署redis分布式集群(二)
2023-07-23 13:38:49 】 浏览:109
Tags:docker swarm redis

在swarm集群的Manager节点中创建

mkdir /root/redis-swarm
cd /root/redis-swarm
vi docker-compose.yml

docker compose.yml

说明:

  1. 前6个服务为redis节点,最后一个redis-start是用于创建集群,利用redis-cli客户端搭建集群,该服务搭建完redis集群后会自动停止运行。

  2. redis-start需要等待前6个redis节点的执行完毕才能创建集群,因此需要用到脚本wait-for-it.sh

  3. 由于redis-cli --cluster create不支持网络别名,所以另写脚本redis-start.sh

使用这套脚本同样可以单机部署集群,只需要在启动时不使用swarm启动就可以了,然后把docker-compose.yml中的网络模式driver: overlay给注释掉即可

version: '3.7'
services:
  redis-node1:
    image: redis
    hostname: redis-node1
    ports:
      - 6379:6379
    networks:
      - redis-swarm
    volumes:
      - "node1:/data"
    command: redis-server --cluster-enabled yes --cluster-config-file nodes-node-1.conf
    deploy:
      mode: replicated
      replicas: 1
      resources:
        limits:
          # cpus: '0.001'
          memory: 5120M
        reservations:
          # cpus: '0.001'
          memory: 512M
      placement:
        constraints:
          - node.role==manager

  redis-node2:
    image: redis
    hostname: redis-node2
    ports:
      - 6380:6379
    networks:
      - redis-swarm
    volumes:
      - "node2:/data"
    command: redis-server --cluster-enabled yes --cluster-config-file nodes-node-2.conf
    deploy:
      mode: replicated
      replicas: 1
      resources:
        limits:
          # cpus: '0.001'
          memory: 5120M
        reservations:
          # cpus: '0.001'
          memory: 512M
      placement:
        constraints:
          - node.role==manager

  redis-node3:
    image: redis
    hostname: redis-node3
    ports:
      - 6381:6379
    networks:
      - redis-swarm
    volumes:
      - "node3:/data"
    command: redis-server --cluster-enabled yes --cluster-config-file nodes-node-3.conf
    deploy:
      mode: replicated
      resources:
        limits:
          # cpus: '0.001'
          memory: 5120M
        reservations:
          # cpus: '0.001'
          memory: 512M
      replicas: 1
      placement:
        constraints:
          - node.role==manager

  redis-node4:
    image: redis
    hostname: redis-node4
    ports:
      - 6382:6379
    networks:
      - redis-swarm
    volumes:
      - "node4:/data"
    command: redis-server --cluster-enabled yes --cluster-config-file nodes-node-4.conf
    deploy:
      mode: replicated
      replicas: 1
      resources:
        limits:
          # cpus: '0.001'
          memory: 5120M
        reservations:
          # cpus: '0.001'
          memory: 512M
      placement:
        constraints:
          - node.labels.redis2==true

  redis-node5:
    image: redis
    hostname: redis-node5
    ports:
      - 6383:6379
    networks:
      - redis-swarm
    volumes:
      - "node5:/data"
    command: redis-server --cluster-enabled yes --cluster-config-file nodes-node-5.conf
    deploy:
      mode: replicated
      replicas: 1
      resources:
        limits:
          # cpus: '0.001'
          memory: 5120M
        reservations:
          # cpus: '0.001'
          memory: 512M
      placement:
        constraints:
          - node.labels.redis3==true

  redis-node6:
    image: redis
    hostname: redis-node6
    ports:
      - 6384:6379
    networks:
      - redis-swarm
    volumes:
      - "node6:/data"
    command: redis-server --cluster-enabled yes --cluster-config-file nodes-node-6.conf
    deploy:
      mode: replicated
      replicas: 1
      resources:
        limits:
          # cpus: '0.001'
          memory: 5120M
        reservations:
          # cpus: '0.001'
          memory: 512M
      placement:
        constraints:
          - node.labels.redis4==true

  redis-start:
    image: redis
    hostname: redis-start
    networks:
      - redis-swarm
    volumes:
      - "$PWD/start:/redis-start"
    depends_on:
      - redis-node1
      - redis-node2
      - redis-node3
      - redis-node4
      - redis-node5
      - redis-node6
    command: /bin/bash -c "chmod 777 /redis-start/redis-start.sh && chmod 777 /redis-start/wait-for-it.sh && /redis-start/redis-start.sh"
    deploy:
      resta
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 2/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Docker在windows系统以及Linux系.. 下一篇Linux LVS的四种工作模式

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目