最近研究minio分布式集群部署,发现网上大部分都是单服务器部署,而minio官方在github上现在也只提供了k8s和docker-compose的方式,网上有关与swarm启动minio集群的文章都不完整,这里我研究了近一周时间,终于是成功使用swarm部署minio集群,并用nginx统一入口

环境准备

四台虚拟机

  • 192.168.2.38(管理节点)
  • 192.168.2.81(工作节点)
  • 192.168.2.100(工作节点)
  • 192.168.2.102(工作节点)

时间同步

yum install -y ntp
cat <<EOF>>/var/spool/cron/root
00 12 * * * /usr/sbin/ntpdate -u ntp1.aliyun.com && /usr/sbin/hwclock -w
EOF
##查看计划任务
crontab -l
##手动执行
/usr/sbin/ntpdate -u ntp1.aliyun.com && /usr/sbin/hwclock -w

Docker

安装Docker

curl -sSL https://get.daocloud.io/docker | sh

启动docker

sudo systemctl start docker
sudo systemctl enable docker

搭建Swarm集群

打开防火墙(Swarm需要)

  • 管理节点打开2377

    # manager
    firewall-cmd --zone=public --add-port=2377/tcp --permanent
  • 所有节点打开以下端口

    # 所有node
    firewall-cmd --zone=public --add-port=7946/tcp --permanent
    firewall-cmd --zone=public --add-port=7946/udp --permanent
    firewall-cmd --zone=public --add-port=4789/tcp --permanent
    firewall-cmd --zone=public --add-port=4789/udp --permanent
  • 所有节点重启防火墙

    # 所有node
    firewall-cmd --reload
    systemctl restart docker
  • 图个方便可以直接关闭防火墙

创建Swarm

docker swarm init --advertise-addr your_manager_ip

加入Swarm

docker swarm join --token SWMTKN-1-
51b7t8whxn8j6mdjt5perjmec9u8qguxq8tern9nill737pra2-ejc5nw5f90oz6xldcbmrl2ztu
192.168.2.38:2377
#查看节点
docker node ls

服务约束

添加label

sudo docker node update --label-add minio1=true 管理节点名称
sudo docker node update --label-add minio2=true 工作节点名称
sudo docker node update --label-add minio3=true 工作节点名称
sudo docker node update --label-add minio4=true 工作节点名称

为MinIO创建Docker secret

echo "minioadmin" | docker secret create access_key -
echo "12345678" | docker secret create secret_key -

Minio集群部署文件

创建文件存放目录

管理节点执行

cd /root
mkdir minio-swarm
vi docker-compose-nginx.yml

Docker-Compose.yml

version: '3.7'

services:

  nginx:
image: nginx
hostname: minionginx
volumes:
- /root/minio-swarm/conf/swarm-nginx.conf:/etc/nginx/nginx.conf
ports:
- "9090:80"
- "9000:9000"
deploy:
replicas: 1
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
placement:
constraints:
- node.labels.minio1==true
resources:
limits:
# cpus: '0.001'
memory: 1024M
reservations:
# cpus: '0.001'
memory: 64M
resources:
limits:
memory: 2048M
reservations:
memory: 512M
networks:
- minio_distributed
depends_on:
- minio1
- minio2
- minio3
- minio4 minio1:
image: quay.io/minio/minio:RELEASE.2022-02-12T00-51-25Z
hostname: minio1
volumes:
- data1-1:/data1
- data1-2:/data2
deploy:
replicas: 1
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
placement:
constraints:
- node.labels.minio1==true
resources:
limits:
memory: 2048M
reservations:
memory: 512M
command: server --console-address ":9001" http://minio{1...4}/data{1...2}
networks:
- minio_distributed
secrets:
- secret_key
- access_key
healthcheck:
test:
[
"CMD",
"curl",
"-f",
"http://localhost:9000/minio/health/live"
]
interval: 30s
timeout: 20s
retries: 3 minio2:
image: quay.io/minio/minio:RELEASE.2022-02-12T00-51-25Z
hostname: minio2
volumes:
- data2-1:/data1
- data2-2:/data2
deploy:
replicas: 1
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
placement:
constraints:
- node.labels.minio2==true
resources:
limits:
memory: 2048M
reservations:
memory: 512M
command: server --console-address ":9001" http://minio{1...4}/data{1...2}
networks:
- minio_distributed
secrets:
- secret_key
- access_key
healthcheck:
test:
[
"CMD",
"curl",
"-f",
"http://localhost:9000/minio/health/live"
]
interval: 30s
timeout: 20s
retries: 3 minio3:
image: quay.io/minio/minio:RELEASE.2022-02-12T00-51-25Z
hostname: minio3
volumes:
- data3-1:/data1
- data3-2:/data2
deploy:
replicas: 1
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
placement:
constraints:
- node.labels.minio3==true
resources:
limits:
memory: 2048M
reservations:
memory: 512M
command: server --console-address ":9001" http://minio{1...4}/data{1...2}
networks:
- minio_distributed
secrets:
- secret_key
- access_key
healthcheck:
test:
[
"CMD",
"curl",
"-f",
"http://localhost:9000/minio/health/live"
]
interval: 30s
timeout: 20s
retries: 3 minio4:
image: quay.io/minio/minio:RELEASE.2022-02-12T00-51-25Z
hostname: minio4
volumes:
- data4-1:/data1
- data4-2:/data2
deploy:
replicas: 1
restart_policy:
delay: 10s
max_attempts: 10
window: 60s
placement:
constraints:
- node.labels.minio4==true
resources:
limits:
memory: 2048M
reservations:
memory: 512M
command: server --console-address ":9001" http://minio{1...4}/data{1...2}
networks:
- minio_distributed
secrets:
- secret_key
- access_key
healthcheck:
test:
[
"CMD",
"curl",
"-f",
"http://localhost:9000/minio/health/live"
]
interval: 30s
timeout: 20s
retries: 3 volumes:
data1-1:
data1-2:
data2-1:
data2-2:
data3-1:
data3-2:
data4-1:
data4-2: networks:
minio_distributed:
driver: overlay secrets:
secret_key:
external: true
access_key:
external: true

说明:

  • secret_key和access_key由上一步通过docker secret create xxx - 创建的
  • 一个节点上只能部署一个minio服务,如果部署多个会出现磁盘被占用的情况,所以最好是增加机器再部署

nginx.conf

创建目录

cd /root/minio-swarm
mkdir conf
cd conf
vi swarm-nginx.conf

如果需要增加集群的节点,需要在Upstream中添加新节点的服务名:9001

user  nginx;
worker_processes auto; error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid; events {
worker_connections 4096;
} http {
include /etc/nginx/mime.types;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65; upstream minio {
server minio1:9000;
server minio2:9000;
server minio3:9000;
server minio4:9000;
}
server {
listen 9000;
listen [::]:9000;
server_name localhost; # To allow special characters in headers
ignore_invalid_headers off;
# Allow any size file to be uploaded.
# Set to a value such as 1000m; to restrict file size to a specific value
client_max_body_size 0;
# To disable buffering
proxy_buffering off;
proxy_request_buffering off; location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_connect_timeout 300;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off; proxy_pass http://minio;
}
}
# include /etc/nginx/conf.d/*.conf; upstream console {
server minio1:9001;
server minio2:9001;
server minio3:9001;
server minio4:9001;
} server {
listen 80;
listen [::]:80;
server_name localhost; # To allow special characters in headers
ignore_invalid_headers off;
# Allow any size file to be uploaded.
# Set to a value such as 1000m; to restrict file size to a specific value
client_max_body_size 0;
# To disable buffering
proxy_buffering off; location / {
proxy_connect_timeout 5;
proxy_send_timeout 10;
proxy_read_timeout 10; proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off; proxy_pass http://console;
}
} }

部署

cd /root/minio-swarm
docker stack deploy -c docker-compose-nginx.yaml minio-swarm

测试

浏览器访问

一个节点宕机

模拟其中一个节点宕机,看能否正常读取数据(minio集群的写入需要至少4个在线磁盘,如果是两个节点的集群,一个节点宕机,那么集群就只能读取,无法写入)

如果是一个有N块硬盘的分布式Minio,只要有N/2硬盘在线,你的数据就是可以读取的。不过你需要至少有N/2+1个硬盘来创建新的对象。

[root@test redis-swarm2]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
l317d9wc49tt minio-swarm_minio1 replicated 1/1 quay.io/minio/minio:RELEASE.2022-02-12T00-51-25Z
x2gj6ert03tj minio-swarm_minio2 replicated 1/1 quay.io/minio/minio:RELEASE.2022-02-12T00-51-25Z
z624sonlnk02 minio-swarm_minio3 replicated 1/1 quay.io/minio/minio:RELEASE.2022-02-12T00-51-25Z
xu0gx8mbjocm minio-swarm_minio4 replicated 1/1 quay.io/minio/minio:RELEASE.2022-02-12T00-51-25Z
53w8cpjpe7wd minio-swarm_nginx replicated 1/1 nginx:latest *:9000->9000/tcp, *:9090->80/tcp

现在将其中一台服务器停机处理,刷新浏览器

可以正常写入和读取数据

二个节点宕机

被强制退到登录界面,无法登录进去

注意: 如果要模拟节点宕机,至少需要3台机器,如果是两台,模拟宕机一台,另一台是无法写入的

Minio分布式集群部署——Swarm的更多相关文章

  1. MinIO分布式集群部署方式

    文章转载自:https://blog.51cto.com/u_10950710/4843738 关于分布式集群MinIo 单机Minio服务存在单点故障,如果是一个有N块硬盘的分布式Minio,只要有 ...

  2. 三、Linux部署MinIO分布式集群

    MinIO的官方网站非常详细,以下只是本人学习过程的整理 一.MinIO的基本概念 二.Windows安装与简单使用MinIO 三.Linux部署MinIO分布式集群 四.C#简单操作MinIO 一. ...

  3. MinIO 分布式集群搭建

    MinIO 分布式集群搭建 分布式 Minio 可以让你将多块硬盘(甚至在不同的机器上)组成一个对象存储服务.由于硬盘分布在不同的节点上,分布式 Minio 避免了单点故障. Minio 分布式模式可 ...

  4. 基于winserver的Apollo配置中心分布式&集群部署实践(正确部署姿势)

    基于winserver的Apollo配置中心分布式&集群部署实践(正确部署姿势)   前言 前几天对Apollo配置中心的demo进行一个部署试用,现公司已决定使用,这两天进行分布式部署的时候 ...

  5. 超详细从零记录Hadoop2.7.3完全分布式集群部署过程

    超详细从零记录Ubuntu16.04.1 3台服务器上Hadoop2.7.3完全分布式集群部署过程.包含,Ubuntu服务器创建.远程工具连接配置.Ubuntu服务器配置.Hadoop文件配置.Had ...

  6. Hadoop(HA)分布式集群部署

    Hadoop(HA)分布式集群部署和单节点namenode部署其实一样,只是配置文件的不同罢了. 这篇就讲解hadoop双namenode的部署,实现高可用. 系统环境: OS: CentOS 6.8 ...

  7. Hadoop分布式集群部署(单namenode节点)

    Hadoop分布式集群部署 系统系统环境: OS: CentOS 6.8 内存:2G CPU:1核 Software:jdk-8u151-linux-x64.rpm hadoop-2.7.4.tar. ...

  8. Hadoop教程(五)Hadoop分布式集群部署安装

    Hadoop教程(五)Hadoop分布式集群部署安装 1 Hadoop分布式集群部署安装 在hadoop2.0中通常由两个NameNode组成,一个处于active状态,还有一个处于standby状态 ...

  9. solr 集群(SolrCloud 分布式集群部署步骤)

    SolrCloud 分布式集群部署步骤 安装软件包准备 apache-tomcat-7.0.54 jdk1.7 solr-4.8.1 zookeeper-3.4.5 注:以上软件都是基于 Linux ...

随机推荐

  1. vs code nginx php xdebug配置

    终于把VSCODE XDEBUG配置搞定了 分享一下 1. VSCODE  安装插件 PHP Debug( Debug supprot for PHP with XDebug); 2. VSCODE ...

  2. 技术分享 | app自动化测试(Android)--App 控件定位

    原文链接 客户端的页面通过 XML 来实现 UI 的布局,页面的 UI 布局作为一个树形结构,而树叶被定义为节点.这里的节点也就对应了要定位的元素,节点的上级节点,定义了元素的布局结构.在 XML 布 ...

  3. Charles如何抓取https请求-移动端+PC端

    Charles安装完成,默认只能抓取到http请求,如果查看https请求,会显示unkonw或其它之类的响应.所以需要先进行一些配置,才能抓取到完整的https请求信息.下面针对PC端和手机端抓包的 ...

  4. 【翻译】驯服野兽:Scylla 如何利用控制理论来控制压实

    教程翻译自Seastar官方文档:https://www.scylladb.com/2018/06/12/scylla-leverages-control-theory/ 转载请注明出处:https: ...

  5. 牛亚男:基于多Domain多任务学习框架和Transformer,搭建快精排模型

    导读: 本文主要介绍了快手的精排模型实践,包括快手的推荐系统,以及结合快手业务展开的各种模型实战和探索,全文围绕以下几大方面展开: 快手推荐系统 CTR模型--PPNet 多domain多任务学习框架 ...

  6. node图片压缩的两员大将

    一.ishrink 全局安装 npm i ishrink -g 1.按url方式压缩 本地图片地址 sk -u C:\Users\admin\Desktop\images\img 网络图片地址 sk ...

  7. 重学ES系列之变量的作用范围

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Elasticsearch学习系列四(聚合搜索)

    聚合分析 聚合分析是数据库中重要的功能特性,完成对一个查询的集中数据的聚合计算.如:最大值.最小值.求和.平均值等等.对一个数据集求和,算最大最小值等等,在ES中称为指标聚合,而对数据做类似关系型数据 ...

  9. dubbox、zookeeper BUG记录

    主要错误信息: dubbo:com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method... Caused by: com.alib ...

  10. 小样本利器2.文本对抗+半监督 FGSM & VAT & FGM代码实现

    小样本利器2.文本对抗+半监督 FGSM & VAT & FGM代码实现 上一章我们聊了聊通过一致性正则的半监督方案,使用大量的未标注样本来提升小样本模型的泛化能力.这一章我们结合FG ...