下载官网
wget https://dl.min.io/server/minio/release/linux-amd64/minio
简介
MinIO 是一个基于Apache License v2.0开源协议的对象存储服务。它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片、视频、日志文件、备份数据和容器/虚拟机镜像等,而一个对象文件可以是任意大小,从几kb到最大5T不等。
MinIO是一个非常轻量的服务,可以很简单的和其他应用的结合,类似 NodeJS, Redis 或者 MySQL。
version: '3'
services:
minio:
image: minio/minio
hostname: "minio"
ports:
- 9000:9000 # api 端口
- 9001:9001 # 控制台端口
environment:
MINIO_ACCESS_KEY: admin #管理后台用户名
MINIO_SECRET_KEY: admin123 #管理后台密码,最小8个字符
volumes:
- /docker/minio/data:/data #映射当前目录下的data目录至容器内/data目录
- /docker/minio/config:/root/.minio/ #映射配置目录
command: server --console-address ':9001' /data #指定容器中的目录 /data
privileged: true
restart: always
拉取镜像运行容器
docker-compose pull
docker-compose up -d
官方推荐docker-compose.yaml
:下载地址
vim docker-compose.yml
version: '3.7'
# 所有容器通用的设置和配置
x-minio-common: &minio-common
image: minio/minio
command: server --console-address ":9001" http://minio{1...4}/data
expose:
- "9000"
# environment:
# MINIO_ROOT_USER: minioadmin
# MINIO_ROOT_PASSWORD: minioadmin
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
# 启动4个docker容器运行minio服务器实例
# 使用nginx反向代理9000端口,负载均衡, 你可以通过9001、9002、9003、9004端口访问它们的web console
services:
minio1:
<<: *minio-common
hostname: minio1
ports:
- "9001:9001"
volumes:
- ./data/data1:/data
minio2:
<<: *minio-common
hostname: minio2
ports:
- "9002:9001"
volumes:
- ./data/data2:/data
minio3:
<<: *minio-common
hostname: minio3
ports:
- "9003:9001"
volumes:
- ./data/data3:/data
minio4:
<<: *minio-common
hostname: minio4
ports:
- "9004:9001"
volumes:
- ./data/data4:/data
nginx:
image: nginx:1.19.2-alpine
hostname: nginx
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "9000:9000"
depends_on:
- minio1
- minio2
- minio3
- minio4
mkdir config
vim config/nginx.conf
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;
# include /etc/nginx/conf.d/*.conf;
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;
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;
}
}
}
执行启动命令,看到各个节点healthy
状态即成功
docker-compose up -d
浏览器访问任意节点web console
,进行简单配置,配置会自动在节点间同步
创建桶(Buckets)后,选择管理(Manage),在总结(Summary)中可以进行访问策略(Access Policy)配置
选择菜单设置(Settings)-配置( Configuration),选择扫描器(Scanner),配置Max Wait
和Cycle
为1s,可以大大加快节点间的同步效率
准备3个节点,每个节点创建2个挂载点,由于集群模式下不能使用根磁盘,这里使用docker卷作为挂载点。 3节点的集群,故障一个节点时不影响对集群的读写操作。
cat >> /etc/hosts << EOF
192.168.2.205 minio-1
192.168.2.242 minio-2
192.168.2.241 minio-3
EOF
docker pull minio/minio
docker images |grep minio
docker run -d --name minio \
--restart=always --net=host \
-e MINIO_ACCESS_KEY=minio \
-e MINIO_SECRET_KEY=minio123 \
-v minio-data1:/data1 \
-v minio-data2:/data2 \
minio/minio server \
--address 192.168.2.242:9000 \
http://minio-{1...3}/data{1...2}
docker run -d --name minio \
--restart=always --net=host \
-e MINIO_ACCESS_KEY=minio \
-e MINIO_SECRET_KEY=minio123 \
-v minio-data1:/data1 \
-v minio-data2:/data2 \
minio/minio server \
--address 192.168.2.64:9000 \
http://minio-{1...3}/data{1...2}
docker run -d --name minio \
--restart=always --net=host \
-e MINIO_ACCESS_KEY=minio \
-e MINIO_SECRET_KEY=minio123 \
-v minio-data1:/data1 \
-v minio-data2:/data2 \
minio/minio server \
--address 192.168.2.241:9000 \
http://minio-{1...3}/data{1...2}
说明:docker部署集群模式时必须指定–net=host参数,使用主机网络,使用端口映射无法创建集群。
查看容器日志,创建1个zone、1个set以及6个在线的drivers:
[root@minio-1 ~]# docker logs -f minio
......
Waiting for all other servers to be online to format the disks.
Formatting 1st zone, 1 set(s), 6 drives per set.
Waiting for all MinIO sub-systems to be initialized.. lock acquired
Attempting encryption of all config, IAM users and policies on MinIO backend
All MinIO sub-systems initialized successfully
Status: 6 Online, 0 Offline.
Endpoint: http://192.168.92.10:9000
Browser Access:
http://192.168.92.10:9000
Object API (Amazon S3 compatible):
Go: https://docs.min.io/docs/golang-client-quickstart-guide
Java: https://docs.min.io/docs/java-client-quickstart-guide
Python: https://docs.min.io/docs/python-client-quickstart-guide
JavaScript: https://docs.min.io/docs/javascript-client-quickstart-guide
.NET: https://docs.min.io/docs/dotnet-client-quickstart-guide
Waiting for all MinIO IAM sub-system to be initialized.. lock acquired
故障场景:
场景1:模拟一个节点故障,上传数据验证minio能够正常读写,节点重新上线后集群自动恢复正常:
[root@minio-3 ~]# docker stop minio
场景2:模拟一个节点彻底故障无法恢复,在一个节点上使用下面清理容器集群命令彻底删除数据,只需在准备一个节点,配置好hosts解析,然后执行启动集群命令即可。
docker stop minio
docker rm minio
docker volume rm minio-data1 minio-data2
使用nginx和keepalived部署负载均衡,实际部署需要额外准备2个节点,这里作为测试复用minio集群前2个节点。
在192.168.92.241及192.168.92.242节点执行以下操作: 负载均衡配置一个就可以了
mkdir -p /etc/nginx/conf.d
cat > /etc/nginx/conf.d/minio-lb.conf << 'EOF'
upstream minio_server {
server 192.168.2.64:9000;
server 192.168.2.241:9000;
server 192.168.2.242:9000;
}
server {
listen 9001;
server_name localhost;
ignore_invalid_headers off;
client_max_body_size 0;
proxy_buffering off;
location / {
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_set_header Host $http_host;
proxy_connect_timeout 300;
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;
proxy_pass http://minio_server;
}
}
EOF
部署nginx容器,2个节点执行: 负载均衡可以只执行一个
docker run -d --name nginx \
--restart always -p 9001:9001 \
-v /etc/nginx/conf.d:/etc/nginx/conf.d \
nginx
准备keepalived配置文件,注意修改interface及virtual_ipaddress参数,2个节点执行:
mkdir /etc/keepalived
cat > /etc/keepalived/keepalived.conf < /dev/null'"
timeout 3
interval 1 # check every 1 second
fall 2 # require 2 failures for KO
rise 2 # require 2 successes for OK
}
vrrp_instance lb-minio {
state BACKUP
interface ens33
virtual_router_id 51
priority 100
virtual_ipaddress {
192.168.92.50
}
track_script {
chk_nginx
}
}
EOF
docker run -d --name keepalived \
--restart always \
--cap-add=NET_ADMIN \
--net=host \
-v /etc/keepalived/keepalived.conf:/container/service/keepalived/assets/keepalived.conf \
--detach osixia/keepalived --copy-service
查看创建的vip
[root@minio-1 ~]# ip a | grep 192.168.92
inet 192.168.92.10/24 brd 192.168.92.255 scope global noprefixroute ens33
inet 192.168.92.50/32 scope global ens33
停止vip所在节点nginx容器模拟负载均衡故障,验证vip转移
docker stop nginx
查看keepalived日志
[root@minio-1 ~]# docker logs -f keepalived
......
Tue Dec 22 01:22:06 2020: Script `chk_nginx` now returning 7
Tue Dec 22 01:22:09 2020: VRRP_Script(chk_nginx) failed (exited with status 7)
Tue Dec 22 01:22:09 2020: (lb-minio) Entering FAULT STATE
Tue Dec 22 01:22:09 2020: (lb-minio) sent 0 priority
Tue Dec 22 01:22:09 2020: (lb-minio) removing VIPs.
vip自动迁移至节点2
[root@minio-2 ~]# ip a | grep 192.168.92
inet 192.168.92.11/24 brd 192.168.92.255 scope global noprefixroute ens33
inet 192.168.92.50/32 scope global ens33
minio server的standalone模式,即要管理的磁盘都在host本地。在standalone模式下,还可以分为non-erasure code mode和erasure code mode。
non-erasure code mode
在此启动模式下,对于每一份对象数据,minio直接在data下面存储这份数据,不会建立副本,也不会
启用纠删码机制。因此,这种模式无论是服务实例还是磁盘都是“单点”,无任何高可用保障,磁盘损坏 就表示数据丢失
erasure code mode
此模式为minio server实例传入多个本地磁盘参数。一旦遇到多于一个磁盘参数,minio server会自动 启用erasure code mode。erasure code对磁盘的个数是有要求的,如不满足要求,实例启动将失 败。 erasure code启用后,要求传给minio server的endpoint(standalone模式下,即本地磁盘上的目 录)至少为4个。
#也可以使用命令下载 这里我使用官网下载(命令仅供参考)
wget -q http://dl.minio.org.cn/server/minio/release/linux-amd64/minio
#创建文件夹
sudo mkdir /usr/local/minio
#复制文件
cp minio /usr/local/minio
#使下载的Minio文件为可执行文件
chmod +x minio
#切换目录
cd /usr/local
#创建文件存放目录
sudo mkdir data
#进入安装目录
cd /usr/local/minio
#修改Minio的初始账号密码(也可以不修改)
#初始账号:minioadmin
#初始密码:minioadmin
export MINIO_ROOT_USER=minio
export MINIO_ROOT_PASSWORD=12345678 #注意密码至少八位
#启动Minio (需要进入minio存放目录下)
#50000 固定端口号 否则每次启动Minio会随机生成一个不一样的端口(控制台会有打印信息)
#/usr/local/java/etc 指定文件存放目录
./minio server --console-address ":50000" /usr/local/data
nohup ./minio server --console-address ":50000" /usr/local/data & 放在后台
#在浏览器输入 http://Ip:50000 成功打开页面可以登录说明安装成功
访问测试—登陆成功
小米控制台
# mkdir /usr/local/minio/
# cd /usr/local/minio/
# wget https://dl.min.io/server/minio/release/linux-amd64/minio
# chmod +x /usr/local/minio/minio
# mkdir -p /home/minio/data
# groupadd minio
# useradd -r -g minio minio
# chown -R minio:minio /home/minio/
# vim /home/minio/minio.conf
root@debian:/home/minio# pwd
/home/minio
内容如下
MINIO_VOLUMES="/home/minio/data"
MINIO_ACCESS_KEY="admin"
MINIO_SECRET_KEY="admin123"
# vim /etc/systemd/system/minio.service
内容如下
[Unit]
Description=MinIO
Documentation=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/minio/minio
[Service]
# User and group
User=minio
Group=minio
EnvironmentFile=/home/minio/minio.conf
ExecStart=/usr/local/minio/minio server $MINIO_VOLUMES
# Let systemd restart this service always
Restart=always
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl enable minio.service
# systemctl start minio.service
# systemctl status minio.service
查看结果
netstat -lntp | grep minio
tcp6 0 0 :::9000 :::* LISTEN 5960/minio
tcp6 0 0 :::35993 :::* LISTEN 5960/minio
访问
创建存储桶
在上传之前,提示我们需要先创建一个上传的文件夹(存储桶)
默认配置下,访问存储桶是需要请求授权的。但是在实际场景下,我们往往希望允许直接访问,此时就需要添加一条 readonly 或readwrite访问规则;或者直接在[Access Policy]直接设置public(不安全)
① 点击右上角的 [Manage] 设置图标,然后选择 [Access Rules] 菜单。
② 点击 [Add Access Rule] 按钮,添加一条 Prefix 为 /
或者*
,Access 为 readwrite
的规则。
点击 [Upload] 按钮,点击 [Upload File] 选项,选择一个文件上传
文件的访问地址的格式为
,注意是 9000 端口。比如我的是http://196.196.196.12:9000/bimuyu/577521.png
img-3zM9TPO9-1660035759394)]
尝试上传文件,或者其他东西
[外链图片转存中…(img-i0vSbNnH-1660035759395)]
[外链图片转存中…(img-3I07ZI2E-1660035759396)]
上传成功
[外链图片转存中…(img-kdjNXAga-1660035759396)]
默认配置下,访问存储桶是需要请求授权的。但是在实际场景下,我们往往希望允许直接访问,此时就需要添加一条 readonly 或readwrite访问规则;或者直接在[Access Policy]直接设置public(不安全)
① 点击右上角的 [Manage] 设置图标,然后选择 [Access Rules] 菜单。
[外链图片转存中…(img-tQ61WNKq-1660035759397)]
② 点击 [Add Access Rule] 按钮,添加一条 Prefix 为 /
或者*
,Access 为 readwrite
的规则。[外链图片转存中…(img-VmPfjQt6-1660035759398)]
点击 [Upload] 按钮,点击 [Upload File] 选项,选择一个文件上传
[外链图片转存中…(img-hganMFx5-1660035759398)]
文件的访问地址的格式为
,注意是 9000 端口。比如我的是http://196.196.196.12:9000/bimuyu/577521.png