minio搭建及基础使用

环境信息

4 节点,每个节点 4块盘,挂载目录 /mnt/minio{1..4}

1
2
3
4
5
6
192.168.2.144 minio1
192.168.2.145 minio2
192.168.2.146 minio3
192.168.2.147 minio4

192.168.2.143 registry.harbor.com # 使用 harbor 对接 minio

每台机器上均安装了 docker 和 docker-compose

安装 minio

因为要垮节点,使用 host 网络

docker-compose.yml 所有节点相同

192.168.2.144:8998 可以写成 minio1:8998, 我图方便没有去各个节点修改 /etc/hosts

所有节点均相同

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
services:
minio:
image: quay.io/minio/minio:latest
network_mode: "host"
volumes:
- /mnt/minio1:/minio1
- /mnt/minio2:/minio2
- /mnt/minio3:/minio3
- /mnt/minio4:/minio4
environment:
MINIO_ROOT_USER: "minio"
MINIO_ROOT_PASSWORD: "minioadmin"
MINIO_OPTS: "--console-address :9001"
MINIO_PORT: "8998"
command: server --address ":8998" --console-address ":9001" http://192.168.2.144:8998/minio{1...4} http://192.168.2.145:8998/minio{1...4} http://192.168.2.146:8998/minio{1...4} http://192.168.2.147:8998/minio{1...4}

docker-compose -d 启动

使用 nginx 代理

192.168.2.143 机器上

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
upstream minio{
server 192.168.2.144:8998;
server 192.168.2.145:8998;
server 192.168.2.146:8998;
server 192.168.2.147:8998;
}



server {
listen 9000;
server_name minio;
location / {
proxy_pass http://minio;
proxy_set_header Host $http_host;
client_max_body_size 1000m;
}


}

测试

192.168.2.143 上测试

下载 mc, 加入到 PATH 中,并添加 minio-server host

1
2
3
4
5
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
mv mc /usr/local/bin/

mc config host add minio-server http://192.168.2.143:8998 minio minioadmin

创建桶 harbor

1
mc mb minio-server/harbor

对接

1
2
3
4
5
6
7
8
9
10
11
12
data_volume: /data

# 新增部分
storage_service:
s3:
accesskey: minio
secretkey: minioadmin
region: us-west-1
regionendpoint: http://192.168.2.143:9000
bucket: harbor
secure: false
v4auth: true

启动后推送查看

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
mc tree minio-server/harbor
minio-server/harbor
└─ docker
└─ registry
└─ v2
├─ blobs
│ └─ sha256
│ ├─ 1b
│ │ └─ 1bbcb9df2c93e03db739f7e49ce73eda0325b8087ef8e88386d303d883c357ab
│ ├─ 53
│ │ └─ 537a6cfe3404285310129c72dfc3f352e7c5db1a5f296e514d739322bab5a998
│ ├─ 76
│ │ └─ 767bff2cc03ef46478039907c5bca487eb27d5f43a38571985e4ed4dc0403d5a
│ ├─ ad
│ │ └─ adc73cb74f2591613c7c88f7f6a313c3373bbfa3bda0983677bb233668b4033a
│ ├─ c6
│ │ └─ c6b156574604a095a5847d3b34cf36d484bb49862365e996b391d0ba0f345034
│ ├─ c9
│ │ └─ c94f3436f3bfcb467e9723bdb4957e2e86c00cc5f21e38a40d668c1a4c324696
│ ├─ ea
│ │ └─ ea5d7144c337402f813ea7c05c11dab58b7841f4c41fb5f5058abefbc2451ec5
│ ├─ f1
│ │ └─ f11c1adaa26e078479ccdd45312ea3b88476441b91be0ec898a7e07bfd05badc
│ └─ ff
│ └─ fffffc90d343cbcb01a5032edac86db5998c536cd0a366514121a45c6723765c
└─ repositories
└─ library
└─ nginx
├─ _layers
│ └─ sha256
│ ├─ 1bbcb9df2c93e03db739f7e49ce73eda0325b8087ef8e88386d303d883c357ab
│ ├─ 537a6cfe3404285310129c72dfc3f352e7c5db1a5f296e514d739322bab5a998
│ ├─ 767bff2cc03ef46478039907c5bca487eb27d5f43a38571985e4ed4dc0403d5a
│ ├─ adc73cb74f2591613c7c88f7f6a313c3373bbfa3bda0983677bb233668b4033a
│ ├─ c6b156574604a095a5847d3b34cf36d484bb49862365e996b391d0ba0f345034
│ ├─ ea5d7144c337402f813ea7c05c11dab58b7841f4c41fb5f5058abefbc2451ec5
│ ├─ f11c1adaa26e078479ccdd45312ea3b88476441b91be0ec898a7e07bfd05badc
│ └─ fffffc90d343cbcb01a5032edac86db5998c536cd0a366514121a45c6723765c
└─ _manifests
├─ revisions
│ └─ sha256
│ └─ c94f3436f3bfcb467e9723bdb4957e2e86c00cc5f21e38a40d668c1a4c324696
└─ tags
└─ latest
├─ current
└─ index
└─ sha256
└─ c94f3436f3bfcb467e9723bdb4957e2e86c00cc5f21e38a40d668c1a4c324696

下载整个 bucket

1
2
3
4
5
6
7
mc mirror minio-server/harbor ./local-harbor

root@ubuntu:~# ls
local-harbor
root@ubuntu:~# cd local-harbor/
root@ubuntu:~/local-harbor# ls
docker

上传到新的 bucket test

1
2
3
4
5
6
7
8
9
10
root@ubuntu:~/# mc mb minio-server/test
Bucket created successfully `minio-server/test`.
root@ubuntu:~/# mc ls minio-server
[2024-07-13 06:04:26 UTC] 0B harbor/
[2024-07-13 06:50:03 UTC] 0B test/

root@ubuntu:~# mc mirror ./local-harbor minio-server/test
...40d668c1a4c324696/link: 67.69 MiB / 67.69 MiB ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 158.75 MiB/s 0sroot@ubuntu:~# mc ls minio-server/test
[2024-07-13 06:51:56 UTC] 0B docker/
root@ubuntu:~#

其他 操作基本与 linux 下类似

网页

查看

minio网页

使用 velero minio 备份k8s

先创建认证文件 credentials-velero

1
2
3
[default]   
aws_access_key_id = minio
aws_secret_access_key = minio123

安装

1
2
3
4
5
6
7
8
9
./velero install \
--image velero/velero:v1.15.0 \
--provider aws \
--bucket velero \
--namespace velero \
--plugins velero/velero-plugin-for-aws:main \
--secret-file ./credentials-velero \
--use-volume-snapshots=false \
--backup-location-config region=minio,s3ForcePathStyle="true",s3Url=http://10.68.219.99:9000

简单备份

1
2
3
4
velero backup create backupk8s
velero backup get
velero backup describe backupk8s
velero backup logs backupk8s

velero-minio-备份k8s

连接公有云的oss

连接 oracle cloud 对象存储

oracleCloud对象存储填写信息

oracleCloud创建客户密钥

mc 连接

1
2
3
4
5
6
7
# us-phoenix-1 为所在区域,按需修改
# xxxx 为命名空间
mc alias set oracle https://xxxx.compat.objectstorage.us-phoenix-1.oraclecloud.com xxxxxx xxxxxxxxx
Added `oracle` successfully.

mc cp opt.tar.gz oracle/bucket-imwl/
...opt.tar.gz: 445.08 MiB / 445.08 MiB ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃

python 简单测试

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
import boto3
from botocore.client import Config

def init_s3(end_point, access_key, secret_key, region_name):
return boto3.client(
's3',
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
use_ssl=True,
region_name=region_name,
endpoint_url=end_point,
config=Config(s3={"addressing_style": "path"})
)

# 示例调用
region_name = 'us-phoenix-1'
ns='xxxxxx'
s3_endpoint = f"https://{ns}.compat.objectstorage.{region_name}.oraclecloud.com"
s3_access_key = "xxxxxxx"
s3_secret_key = "xxxxxxxxxx"


s3 = init_s3(s3_endpoint, s3_access_key, s3_secret_key, region_name)

try:
# 列出所有存储桶
response = s3.list_buckets()
for bucket in response.get('Buckets', []):
print(f"Bucket Name: {bucket['Name']}")
except Exception as e:
print(f"Error: {e}")

运行

1
2
3
$ python client.py
Bucket Name: bucket-imwl
Bucket Name: bucket-public

连接 阿里云

遇到的问题

1
2
3
4
5
AccessDenied
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint
问题原因:访问Bucket时使用的Endpoint不正确。

解决方案:确保使用正确的Endpoint访问Bucket。例如Bucket所在地域为oss-cn-hangzhou,则外网Endpoint为oss-cn-hangzhou.aliyuncs.com

一般使用

1
2
mc alias set aliyunoss https://oss-cn-hongkong.aliyuncs.com <AccessKey> <SecretKey> --api S3v4
mc ls aliyunoss

连接火山引擎

当前无法使用 mc

https://www.volcengine.com/docs/6349/1288493

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
问题描述
使用 PathStyle 的请求方式访问 TOS 时,报错 Forbidden path to access server 或 InvalidPathAccess。

问题原因
TOS 不支持路径样式(即 PathStyle)的请求方式,仅支持使用虚拟主机(即 VirtualHostStyle)的请求方式。

解决方案
Path 和 VirtualHost 的区别主要在于 HTTP URL 中存储桶名称的位置,如下所示:

# Path 访问方式
https://tos-s3-cn-beijing.volces.com/{bucketname}

# VirtualHost 访问方式
https://{bucketname}.tos-s3-cn-beijing.volces.com
使用各种支持 S3 协议的 SDK 和工具访问 TOS 时,请务必确保配置了 VirtualHostStyle 的请求方式。例如:

使用 AWS S3 Java SDK 时,需要在客户端初始化时确保设置了禁用 PathStyle 的配置参数:AmazonS3Builder.withPathStyleAccessEnabled(false)。
使用 AWS CLI 工具访问 TOS 时,需要在 ~/.aws/config 文件中添加 addressing_style = virtual 内容,确保请求方式为 VirtualHostStyle。

使用 s3cmd, 需要做如下修改

cn-shanghai 是区域

1
2
host_base = tos-s3-cn-shanghai.volces.com
host_bucket = %(bucket)s.tos-s3-cn-shanghai.volces.com