docker swarm部署minio集群

2021年11月22日 阅读数:3
这篇文章主要向大家介绍docker swarm部署minio集群,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

安装系统

php

更换软件源

  • 首先备份原来的软件源并另存:
sudo cp -v /etc/apt/sources.list /etc/apt/sources.list.backup
  • 编辑软件源文件
sudo vim /etc/apt/sources.list
  • 注释全部软件源

阿里云源:node

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

清华源nginx

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ eoan-proposed main restricted universe multiverse
  • 修改完软件源后,更新软件列表和软件:
sudo apt update
sudo apt upgrade

安装docker

sudo apt install docker.io
  • 设置docker镜像加速

编辑daemon.json文件:docker

sudo vim /etc/docker/daemon.json

添加阿里云加速镜像地址内容:json

{
"registry-mirrors": ["https://******.mirror.aliyuncs.com"]
}
  • 重启服务
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker

建立Swarm

  • 在管理节点上建立一个swarm,请运行下面的命令
docker swarm init --advertise-addr <MANAGER-IP>

一旦swarm初使化了,你能够看到下面的响应信息ubuntu

docker swarm join \
  --token  SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
  192.168.99.100:2377

你如今能够运行上述命令添加worker节点到swarm。vim

添加label标签

# 查看节点信息
sudo docker node ls
# 为节点添加标签
sudo docker node update --label-add minio1=true (node_name)

minio1=true标签是minio在stack文件中定义的,用来肯定节点部署的,因此必须添加,否则节点将不会部署。浏览器

为MinIO建立Docker secret

sudo echo "AKIAIOSFODNN7EXAMPLE" | sudo docker secret create access_key -
sudo echo "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | sudo docker secret create secret_key -

access_key和secret_key能够自定义,尽可能不要相同。bash

部署分布式minio服务

  • 在你的Swarm master上下载Docker Compose file ,而后运行下面的命令
sudo docker stack deploy --compose-file=docker-compose-secrets.yaml minio_stack
  • 查看节点部署信息
sudo docker service ls
服务列表

确认每一个节点都起来了。服务器

  • 查看节点日志
sudo docker service logs (节点ID)

确认每一个节点都运行正常

配置nginx负载均衡

  • 建立nginx配置文件minio.conf

内容以下

upstream  minio-server {
       server    10.168.1.136:9003;
       server    10.168.1.136:9004;
       server    10.168.1.131:9001;
       server    10.168.1.131:9002;
}


server {
    listen              80;
    server_name 10.168.1.136;
    location / {
        proxy_buffering off;
        proxy_set_header Host $http_host;
        proxy_pass http://minio-server;
        proxy_redirect off;
    }
}

  • 建立nginx相关文件夹
sudo mkdir -p /home/nginx/logs /home/nginx/conf
  • 部署nginx
sudo docker run -d -p 80:80 --name nginx \
  -v /home/nginx/conf/:/etc/nginx/conf.d/ \
  -v /home/nginx/logs:/var/log/nginx \
  nginx

在浏览器中输入服务器ip进行访问


登陆界面

若是如今为初始化,请重试,请检查每一个节点是否正常运行,以及每一个节点是否能连通。
检查每一个节点的磁盘空间是否大于1G。

附:docker-compose-secrets.yaml文件内容

version: '3.7'

services:
  minio1:
    image: minio/minio:RELEASE.2020-07-02T00-15-09Z
    hostname: minio1
    volumes:
      - minio1-data:/export
    ports:
      - "9001:9000"
    networks:
      - minio_distributed
    deploy:
      restart_policy:
        delay: 10s
        max_attempts: 10
        window: 60s
      placement:
        constraints:
          - node.labels.minio1==true #和节点的label对应
    command: server http://minio{1...4}/export
    secrets:
      - secret_key
      - access_key
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  minio2:
    image: minio/minio:RELEASE.2020-07-02T00-15-09Z
    hostname: minio2
    volumes:
      - minio2-data:/export
    ports:
      - "9002:9000"
    networks:
      - minio_distributed
    deploy:
      restart_policy:
        delay: 10s
        max_attempts: 10
        window: 60s
      placement:
        constraints:
          - node.labels.minio2==true #和节点的label对应
    command: server http://minio{1...4}/export
    secrets:
      - secret_key
      - access_key
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  minio3:
    image: minio/minio:RELEASE.2020-07-02T00-15-09Z
    hostname: minio3
    volumes:
      - minio3-data:/export
    ports:
      - "9003:9000"
    networks:
      - minio_distributed
    deploy:
      restart_policy:
        delay: 10s
        max_attempts: 10
        window: 60s
      placement:
        constraints:
          - node.labels.minio3==true #和节点的label对应
    command: server http://minio{1...4}/export
    secrets:
      - secret_key
      - access_key
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  minio4:
    image: minio/minio:RELEASE.2020-07-02T00-15-09Z
    hostname: minio4
    volumes:
      - minio4-data:/export
    ports:
      - "9004:9000"
    networks:
      - minio_distributed
    deploy:
      restart_policy:
        delay: 10s
        max_attempts: 10
        window: 60s
      placement:
        constraints:
          - node.labels.minio4==true #和节点的label对应
    command: server http://minio{1...4}/export
    secrets:
      - secret_key
      - access_key
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

volumes:
  minio1-data:
  minio2-data:
  minio3-data:
  minio4-data:

networks:
  minio_distributed:
    driver: overlay

secrets:
  secret_key:
    external: true
  access_key:
    external: true

本文同步分享在 博客“吟风者”(JianShu)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。