eMinIo 介绍

MinIO 是一种高性能、S3 兼容的对象存储。 它专为大规模 AI/ML、数据湖和数据库工作负载而构建,并且它是由软件定义的存储,不需要购买任何专有硬件,就可以在云上和普通硬件上拥有分布式对象存储。 MinIO拥有开源 GNU AGPL v3 和商业企业许可证的双重许可。

下面是MinIO中的几个核心概念,这些概念在所有的对象存储服务中也都是通用的。

  • 对象(Object)

    对象是实际的数据单元,例如我们上传的一个图片。

  • 存储桶(Bucket)

    存储桶是用于组织对象的命名空间,类似于文件夹。每个存储桶可以包含多个对象。

  • 端点(Endpoint)

    端点是MinIO服务器的网络地址,用于访问存储桶和对象,例如http://192.168.10.101:9000

    注意:

    9000为MinIO的API的默认端口,前边配置的9001以为管理页面端口。

  • Access Key 和 Secret Key

    Access Key是用于标识和验证访问者身份的唯一标识符,相当于用户名。

    Secret Key是与Access Key关联的密码,用于验证访问者的身份。

使用Docker 部署MinIo

*-

说明

系统基于centos7

解决国内无法拉取镜像

1
docker pull docker.211678.top/minio/minio
  1. 使用docker拉取minIo镜像

    1
    docker pull minio/minio
  2. 启动MinIO

    说明: /opt/module/minio/data 为宿主机数据存储目录

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    docker run -p 9000:9000 -p 9001:9001 \
    --name minio -d \
    --restart=always \
    -e "MINIO_ROOT_USER=minio" \
    -e "MINIO_ROOT_PASSWORD=123456" \
    -v /opt/module/minio/data:/data \
    -v /opt/module/minio/config:/root/.minio minio/minio server /data \
    --console-address ":9000" --address ":9001"

    docker run -p 9000:9000 -p 9001:9001 --name minio -d --restart=always -e "MINIO_ACCESS_KEY=minio" -e "MINIO_SECRET_KEY=123456.." -v /opt/module/minio/data:/data -v /opt/module/minio/config:/root/.minio minio/minio server /data --console-address ":9000" --address ":9001"
  3. 查看启动容器, 并查看日志, 检查是否正常启动

    1
    2
    3
    4
    5
    6
    7
    8
    # 查看启动容器
    docker ps

    # 查看日志
    docker logs minio

    # 查看minio版本
    docker exec -it minio minio --version

HTTPS配置

使用FRP配置minio HTTPS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[minio-https]                       
type = https
local_ip = 127.0.0.1
local_port = 9000
custom_domains = minio.xiaoguiyu.cn
plugin = https2http
plugin_local_addr = 127.0.0.1:9000

plugin_crt_path = /opt/module/frp_client/cert/public.crt
plugin_key_path = /opt/module/frp_client/cert/private.pem
plugin_host_header_rewrite = 127.0.0.1
plugin_header_X-From-Where = frp


[minio-https]
type = https
local_ip = 127.0.0.1
local_port = 9001
custom_domains = img.xiaoguiyu.cn
plugin = https2http
plugin_local_addr = 127.0.0.1:9001

plugin_crt_path = /opt/module/frp_client/cert/public.crt
plugin_key_path = /opt/module/frp_client/cert/private.pem
plugin_host_header_rewrite = 127.0.0.1
plugin_header_X-From-Where = frp

MinIO 配置

  1. 使用浏览器访问 MinIO 用户名: minio password: 123456..

    若不能访问MinIO Web服务, 检查是否放行云服务器 9000 90001端口

  2. 进入minio的控制台,并点击左侧菜单的Buckets

    image-20240726210657647
  3. 点击createBucket, 创建桶, 进行下述操作

    image-20240726210838342
  4. 更改访问权限为 public

    image-20240726210935179

  5. 设置Access Keys

image-20240727133548121

使用FRP 反向代理实现MinIo的 HTTPS

配置前准备:

  1. 一台具有公网IP 的服务器
  2. 内网设备
  3. SSL 证书

原理

当访问页面的时候,通过Nginx监听80端口(http)和443端口(https),所有http请求将重定向https请求。接着Nginx将请求转发给frp的http虚拟端口,然后最后将请求发给frp客户端。

Seriver 配置

nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
client_max_body_size 50m;
client_body_buffer_size 10m;
client_header_timeout 1m;
client_body_timeout 1m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 4;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;

server {
listen 443 ssl;
server_name *.xiaoguiyu.cn xiaoguiyu.cn;
ssl_certificate /etc/nginx/ssl/fullchain1.pem;
ssl_certificate_key /etc/nginx/ssl/privkey1.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://172.16.0.3:6666; #本机ip + frp设置的端口
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 240s;
}
}

server {
listen 80;
server_name *.xiaoguiyu.cn xiaoguiyu.cn;
return 301 https://$server_name$request_uri;
}
}

运行时开放端口

1
2
3
4
5
6
docker run --name nginx --restart=always \
-p 443:443 -p 80:80 -d \
-v /opt/module/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /etc/letsencrypt/archive/xiaoguiyu.cn/:/etc/nginx/ssl \
-v /opt/module/vue:/opt/module/vue \
--privileged=true nginx

frps配置

1
2
3
4
5
[common]
bind_addr = 0.0.0.0
bind_port = 7000
vhost_http_port = 6666 #http端口,被代理端与代理端进行http通讯
vhost_https_port = 6667

Client配置

frpc配置

1
2
3
4
5
6
7
8
9
10
11
[minio-http]
type = http
local_ip = 127.0.0.1
local_port = 9000
custom_domains = minio.xiaoguiyu.cn

[img-http]
type = http
local_ip = 127.0.0.1
local_port = 9001
custom_domains = img.xiaoguiyu.cn

PicGo配置MinIO

PicGo下载: https://github.com/Molunerfinn/picgo/releases

  1. 在PicGo中下载MinIO插件

  2. 配置如下:

  3. 配置说明:

  4. 上传图片测试

Java 整合 MInIO

  1. 创建一个Maven项目

  2. 引入如下依赖

    1
    2
    3
    4
    5
    <dependency>
    <groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
    <version>8.5.3</version>
    </dependency>
  3. 编写如下内容

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    public class TestMInIO {

    @Test
    public void testCreateBucket() throws Exception{
    String endPoint = "http://192.168.126.130:9000";
    String accessKey = "minioadmin";
    String secretKey = "minioadmin";
    //1.创建minio的链接对象
    MinioClient minioClient = MinioClient.builder()
    .endpoint(endPoint)
    .credentials(accessKey,secretKey)
    .build();
    //System.out.println("minIO对象创建成功");

    //2.创建bucket桶 hello-minio
    String bucketName = "hello-minio";
    //3校验bucket是否存在
    BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder().bucket(bucketName).build();
    boolean flag = minioClient.bucketExists(bucketExistsArgs);

    if(!flag){
    //创建bucket
    MakeBucketArgs makeBucketArgs = MakeBucketArgs.builder().bucket(bucketName).build();
    minioClient.makeBucket(makeBucketArgs);
    System.out.println("创建成功");


    // %s 字符串 %d 整数
    String config =
    """
    {
    "Statement" : [ {
    "Action" : "s3:GetObject",
    "Effect" : "Allow",
    "Principal" : "*",
    "Resource" : "arn:aws:s3:::%s/*"
    } ],
    "Version" : "2012-10-17"
    }
    """.formatted(bucketName);
    SetBucketPolicyArgs policyArgs = SetBucketPolicyArgs.builder().bucket(bucketName).config(config).build();
    minioClient.setBucketPolicy(policyArgs);
    System.out.println("策略定义成功");

    //4.上传文件
    String resource = "F:\\students\\231113\\adminSpace\\springboot_1\\src\\main\\resources\\static\\image\\web.jpg";
    UploadObjectArgs uploadObjectArgs = UploadObjectArgs.builder()
    .bucket(bucketName)
    .object("流程图.jpg")
    .filename(resource).build();
    minioClient.uploadObject(uploadObjectArgs);
    System.out.println("文件上传成功");
    }else{

    //删除minIO中的文件
    RemoveObjectArgs removeObjectArgs = RemoveObjectArgs.builder().bucket(bucketName).object("流程图.jpg").build();
    minioClient.removeObject(removeObjectArgs);
    System.out.println("删除图片成功!!!");

    //删除minIO中的bucket
    RemoveBucketArgs removeBucketArgs = RemoveBucketArgs.builder().bucket(bucketName).build();
    minioClient.removeBucket(removeBucketArgs);
    System.out.println("bucket已存在-删除bucket");
    }
    }
    }
  4. 运行测试

    运行上述代码,然后查看MinIO管理页面,观察是否上传成功。

    关于文本字符串中的转义字符

    image-20240128154235471