Skip to main content

MinIO 集群部署

初始化 Docker Swarm 环境

  1. 在 MinIO Node01 第一台节点上执行 swarm 初始化命令

    docker swarm init

    # 初始化命令执行后会输出 join 命令,后面需要在其他三节点上运行
    # 当服务器上有多个IP地址时,可以使用 --advertise-addr 参数指定其他节点用来连接到当前管理节点的IP和端口
    # docker swarm init --advertise-addr 192.168.1.11
  2. 分别在 MinIO Node02、3、4 上运行 join 命令,加入 swarm 集群

    docker swarm join --token xxxxxxxx

    # 如遗忘 token ,可在 File Node01 上通过以下命令查看:
    # docker swarm join-token worker
  3. 查看节点并记录下来各节点ID

    docker node ls

部署 MinIO 集群

以下步骤四台服务器都需要操作

  1. 下载镜像

    docker pull registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-minio:RELEASE.2024-02-17T01-15-57Z
  2. 创建数据存储目录

    mkdir -p /data/minio/volume

以下所有步骤仅需在 MinIO Node01 第一台节点操作

  1. 创建配置文件存储目录

    mkdir -p /usr/local/minio
  2. 创建 minio 配置文件

    version: '3'
    services:
    minio1:
    hostname: minio1
    image: registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-minio:RELEASE.2024-02-17T01-15-57Z
    environment:
    MINIO_ROOT_USER: "mingdao"
    MINIO_ROOT_PASSWORD: "123456789"
    volumes:
    - /usr/share/zoneinfo/Etc/GMT-8:/etc/localtime
    - /data/minio/volume:/data/storage
    ports:
    - "9011:9000"
    # - "19111:9001" # minio console 的访问端口,有访问需求时可打开注释
    command: minio server http://minio{1...4}/data/storage/data --console-address ":9001"
    deploy:
    placement:
    constraints:
    - node.id == xxxxxxxxxxxxxxxx # MinIO Node01的 docker node.id 值


    minio2:
    hostname: minio2
    image: registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-minio:RELEASE.2024-02-17T01-15-57Z
    environment:
    MINIO_ROOT_USER: "mingdao"
    MINIO_ROOT_PASSWORD: "123456789"
    volumes:
    - /usr/share/zoneinfo/Etc/GMT-8:/etc/localtime
    - /data/minio/volume:/data/storage
    ports:
    - "9012:9000"
    command: minio server http://minio{1...4}/data/storage/data --console-address ":9001"
    deploy:
    placement:
    constraints:
    - node.id == xxxxxxxxxxxxxxxx # MinIO Node02的 docker node.id 值

    minio3:
    hostname: minio3
    image: registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-minio:RELEASE.2024-02-17T01-15-57Z
    environment:
    MINIO_ROOT_USER: "mingdao"
    MINIO_ROOT_PASSWORD: "123456789"
    volumes:
    - /usr/share/zoneinfo/Etc/GMT-8:/etc/localtime
    - /data/minio/volume:/data/storage
    ports:
    - "9013:9000"
    command: minio server http://minio{1...4}/data/storage/data --console-address ":9001"
    deploy:
    placement:
    constraints:
    - node.id == xxxxxxxxxxxxxxxx # MinIO Node03的 docker node.id 值

    minio4:
    hostname: minio4
    image: registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-minio:RELEASE.2024-02-17T01-15-57Z
    environment:
    MINIO_ROOT_USER: "mingdao"
    MINIO_ROOT_PASSWORD: "123456789"
    volumes:
    - /usr/share/zoneinfo/Etc/GMT-8:/etc/localtime
    - /data/minio/volume:/data/storage
    ports:
    - "9014:9000"
    command: minio server http://minio{1...4}/data/storage/data --console-address ":9001"
    deploy:
    placement:
    constraints:
    - node.id == xxxxxxxxxxxxxxxx # MinIO Node04的 docker node.id 值
    • MINIO_ROOT_USER 变量值即为对象存储的 accessKey
    • MINIO_ROOT_PASSWORD 变量值即为对象存储的 secretKey
  3. 配置启停脚本

    cat > /usr/local/minio/start.sh <<EOF
    docker stack deploy -c /usr/local/minio/minio.yaml minio
    EOF

    cat > /usr/local/minio/stop.sh <<EOF
    docker stack rm minio
    EOF

    chmod +x /usr/local/minio/start.sh
    chmod +x /usr/local/minio/stop.sh
  4. 启动 minio 服务

    bash /usr/local/minio/start.sh