简介
MinIO 是一个基于Apache License v2.0开源协议的对象存储服务。它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片、视频、日志文件、备份数据和容器/虚拟机镜像等,而 一个对象文件可以是任意大小,从几kb到最大5T不等。
MinIO是一个非常轻量的服务,可以很简单的和其他应用的结合,类似 NodeJS, Redis 或者 MySQL。 官网:https://min.io/ http://www.minio.org.cn/
对象存储服务(Object Storage Service,OSS)是一种海量、安全、低成本、高可靠的云存储服 务,适合存放任意类型的文件。容量和处理能力弹性扩展,多种存储类型供选择,全面优化存储成 本。 对于中小型企业,如果不选择存储上云,那么 Minio 是个不错的选择,麻雀虽小,五脏俱全。当然 Minio 除了直接作为对象存储使用,还可以作为云上对象存储服务的网关层,无缝对接到 Amazon S3、 MicroSoft Azure。 在中国:阿里巴巴、腾讯、百度、中国联通、华为、中国移动等等9000多家企业也都在使用MinIO产品。
Minio优点 部署简单:
- 一个single二进制文件即是一切,还可支持各种平台。
- minio支持海量存储,可按zone扩展(原zone不受任何影响),支持单个对象最大5TB;
- 兼容Amazon S3接口,充分考虑开发人员的需求和体验;
- 低冗余且磁盘损坏高容忍,标准且最高的数据冗余系数为2(即存储一个1M的数据对象,实际占用 磁盘空间为2M)。但在任意n/2块disk损坏的情况下依然可以读出数据(n为一个纠删码集合(Erasure Coding Set)中的disk数量)。并且这种损坏恢复是基于单个对象的,而不是基于整个存储卷的。
- 读写性能优异
基础概念:
- Object:存储到 Minio 的基本对象,如文件、字节流,Anything… Bucket:用来存储 Object 的逻辑空间。每个 Bucket 之间的数据是相互隔离的。对于客户端而言,就相当于一个存放文件的顶层文件夹。
- Drive:即存储数据的磁盘,在 MinIO 启动时,以参数的方式传入。Minio 中所有的对象数据都会 存储在 Drive 里。
- Set :即一组 Drive 的集合,分布式部署根据集群规模自动划分一个或多个 Set ,每个 Set 中的 Drive 分布在不同位置。一个对象存储在一个 Set 上。(For example: {1…64} is divided into 4 sets each of size 16.)
- 一个对象存储在一个Set上
- 一个集群划分为多个Set
- 一个Set包含的Drive数量是固定的,默认由系统根据集群规模自动计算得出
- 一个SET中的Drive尽可能分布在不同的节点上
实施
1.启动
minio.exe server D:\OSSDY\minio --console-address :9090 --address :9000
minio.exe server D:\OSSDY\minio2 --console-address :9091 --address :9001
单机多挂载启动 driver 4个以上的时候 自动启动纠删码模式 EC =<5:2 6-7:3 >=8:4 (测试小于等于5个的时候 摘除剩余数量不可小于EC规定数量)
https://min.io/docs/minio/container/operations/concepts/erasure-coding.html#id3
minio server D:\OSSDY\minio{3...6} --console-address :9093 --address :9003
- 设置副本集
需注意两个服务器的服务器时间相差不能少于3s,可使用NTP来保证时间一致
mc alias set minio2 http://127.0.0.1:9000 minioadmin minioadmin
mc alias set minio2 http://127.0.0.1:9001 minioadmin minioadmin
mc admin replicate add minio1 minio2
# 查看站点复制信息
mc admin replicate info minio1
经过测试 单机挂掉之后 另外一个服务可正常使用,且挂掉的服务重新启动之后数据会自动同步。
- 数据迁移 备份
# 只可迁移数据 用户相关无法迁移
mc mirror minio1 minio2
# 备份
mc mirror --overwrite minio1 D:\OSSDY\backup
# 恢复
mc mirror --overwrite D:\OSSDY\backup minio1
- 常用命令
# https://juejin.cn/post/7132852449244610574
# https://www.hxstrive.com/subject/minio.htm?id=601&p=597
# 命令方式上传下载
mc cp 测试OSS.txt minio2/test
# 查看当前mc配置 例如对应host配置
mc config host list
# 添加host
mc alias set minio2 http://127.0.0.1:9000 minioadmin minioadmin
# 测试相关(目前只有商业客户可用)
# https://developer.aliyun.com/article/1006775
mc license register minio1
mc support perf minio1
- docker-compose
#https://github.com/minio/minio/blob/master/docs/orchestration/docker-compose/docker-compose.yaml
version: '3.7'
# Settings and configurations that are common for all containers
x-minio-common: &minio-common
image: quay.io/minio/minio:RELEASE.2023-06-29T05-12-28Z
command: server --console-address ":9001" http://minio1/data{1...4}
expose:
- "9000"
- "9001"
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: "go8#m#7nPcxQ6yu"
MINIO_HTTP_TRACE: /var/log/minio/minio.log
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
services:
minio1:
<<: *minio-common
hostname: minio1
volumes:
- $PWD/minio/data1:/data1
- $PWD/minio/data2:/data2
- $PWD/minio/data3:/data3
- $PWD/minio/data4:/data4
- $PWD/minio/log1:/var/log/minio
- /etc/localtime:/etc/localtime
nginx:
image: nginx:1.19.2-alpine
hostname: nginx
volumes:
- $PWD/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "192.168.102.95:9003:9000"
- "192.168.102.95:9004:9001"
depends_on:
- minio1
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;
}
upstream console {
ip_hash;
server minio1:9001;
}
server {
# endpoint
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 30M;
# 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;
}
}
server {
# console address 控制台
listen 9001;
listen [::]:9001;
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 30M;
# 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_set_header X-NginX-Proxy true;
# This is necessary to pass the correct IP to be hashed
real_ip_header X-Real-IP;
proxy_connect_timeout 300;
# To support websocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
chunked_transfer_encoding off;
proxy_pass http://console;
}
}
}
6.扩展磁盘
#例如 将(1)中的磁盘 再扩展5个磁盘
minio server D:\OSSDY\minio{3...6} D:\OSSDY\minio{6...10} --console-address :9094 --address :9004
- nginx直接转发到minio
server {
listen 443 ssl;
server_name ttt.ttt.com;
ssl_certificate /etc/nginx/conf.d/ssl/ttt.ttt.com.pem;
ssl_certificate_key /etc/nginx/conf.d/ssl/ttt.ttt.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
#自定义设置使用的TLS协议的类型以及加密套件(以下为配置示例,请您自行评估是否需要配置)
#TLS协议版本越高,HTTPS通信的安全性越高,但是相较于低版本TLS协议,高版本TLS协议对浏览器的兼容性较差。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
location ~* ^/default/.*\.(gif|jpg|jpeg|png|docx|doc|xlsx|xls|apk|wgt)$ {
proxy_intercept_errors on;
proxy_http_version 1.1;
client_max_body_size 2048m;
client_body_buffer_size 10m;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 1024m; # 设置的小的话 无法下载大文件
proxy_buffers 32 1024m;
proxy_busy_buffers_size 1024m;
proxy_temp_file_write_size 2048m; # 这个要大于 proxy_buffer_size
proxy_set_header Connection "";
chunked_transfer_encoding off;
proxy_pass http://127.0.0.1:9000;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
expires 1d;
add_header XCDN-Cache "$upstream_cache_status";
}
location ~ .*\.(gif|jpg|jpeg|png|docx|doc|xlsx|xls)$ {
limit_except GET { deny all; }
expires 24h;
root /home/fileDir/;#指定图片存放路径
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path /home/fileDir/;#图片访问路径
proxy_redirect off;
proxy_set_header Host 120.0.0.1; #
client_max_body_size 10m;
client_body_buffer_size 1280k;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 40k;
proxy_buffers 40 320k;
proxy_busy_buffers_size 640k;
proxy_temp_file_write_size 640k;
if ( !-e $request_filename){
proxy_pass http://120.0.0.1;#默认80端口
}
}
}
参考doc : https://min.io/docs/minio/kubernetes/upstream/index.html