背景
本次项目涉及20+台服务器的部署,技术包括 Nacos 注册中心集群、 GateWay 网关服务集群、 达梦8 关系型数据库服务集群、 MinIO 分布式文件存储服务集群、 Redis 缓存服务集群、 WebSocket 服务端消息推送集群、 Quartz 定时任务服务集群、 Nginx+KeepAlived 反向代理高可用集群、监控服务集群等。这里主要记录下分布式文件存储服务集群以及缓存服务集群的搭建过程。
云服务资源
- 172.27.204.115
- 172.27.204.101
- 172.27.204.110
- 172.27.204.151
系统信息
[root@sx-std-oss-220420-0001 opt]
Linux sx-std-oss-220420-0001.novalocal 4.19.90-17.ky10.aarch64
[root@sx-std-oss-220420-0001 opt]
NAME="Kylin Linux Advanced Server"
VERSION="V10 (Tercel)"
ID="kylin"
VERSION_ID="V10"
PRETTY_NAME="Kylin Linux Advanced Server V10 (Tercel)"
ANSI_COLOR="0;31"
Note:以下所有操作分别在4台主机上操作,文件传输: scp minio root@172.27.204.151:/opt/
挂载
在4台主机上创建目录并挂载。
mkdir -p /data/minio
mount /dev/vda1 /data/minio
编写启动脚本
cd /opt
vi start-minio.sh
export MINIO_ACCESS_KEY=Hello
export MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLE
/opt/minio server \
http://172.27.204.115/data/minio http://172.27.204.101/data/minio \
http://172.27.204.110/data/minio http://172.27.204.151/data/minio
chmod +x start-minio.sh
chmod +x minio
编写服务脚本
vi /lib/systemd/system/minio.service
[Unit]
Description=Minio service
Documentation=https://docs.minio.io/
[Service]
WorkingDirectory=/opt/
ExecStart=/opt/start-minio.sh
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
systemctl list-unit-files | grep minio
systemctl enable minio
systemctl list-unit-files | grep minio
systemctl status minio
systemctl start minio
关闭防火墙
由于四台主机之间需要进行通信,这里直接关掉了防火墙。
systemctl status firewalld
systemctl stop firewalld
配置桶权限
可以直接登录 MinIO 提供的控制台进行可视化的配置,不过由于我们在信创环境下没有申请开放对应端口,所有通过 mc 命令行客户端进行配置。
这里记录一个实际中因开放了匿名下载文件权限之后,可以遍历所有对象存储目录的问题的解决方法。
MinIO 的权限其实就是关于文件、桶的 CRUD 的配置,基于AWS的对象存储规则,配置文件为 JSON 格式。
[root@sx-std-oss-220420-0001 opt]
[root@sx-std-oss-220420-0001 minio_policy]
{
"Statement": [
{
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::local"
]
},
{
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::local/*"
]
}
],
"Version": "2012-10-17"
}
可以看到,默认的 download 可以列出桶里的文件列表: GetBucketLocation ,我们把这个权限去掉。
新建一个 custom-local.json ,写入以下内容(与默认生成的配置相比,仅去掉了 GetBucketLocation )。
{
"Statement": [
{
"Action": [
"s3:GetBucketLocation"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::local"
]
},
{
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Principal": {
"AWS": [
"*"
]
},
"Resource": [
"arn:aws:s3:::local/*"
]
}
],
"Version": "2012-10-17"
}
使用我们自定义的权限 JSON 文件。
[root@sx-std-oss-220420-0001 minio_policy]
mc常用命令
mc 命令行客户端的使用可参考官方文档,这里附上之前华为云上操作 MinIO 时 mc 客户端常用的命令。
mc常用命令清单
[root@ecs-c8ee-0011 ~]
[root@ecs-c8ee-0011 minio]
[root@ecs-c8ee-0011 minio]
[root@ecs-c8ee-0011 minio]
-bash: /usr/local/bin/mc: 权限不够
[root@ecs-c8ee-0011 minio]
[root@ecs-c8ee-0011 bin]
mc config host ls
mc config host add name-it http://localhost:9000 HelloWorld wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLE
Added name-it successfully.
mc config host add name-it http://localhost:9000 HelloWorld
mc config host remove name-it
mc admin info name-it
mc ls name-it
mc ls name-it/bucketname
mc cp name-it/bucketname/filename /tmp
mc rm name-it/bucketname/filename
mc cp test.txt name-it/bucketname
mc ls name-it/bucketname
mc mb name-it/new-bucketname
mc ls name-it
mc rb name-it/new-bucketname
mc ls name-it
mc rb --force name-it/new-bucketname
mc ls name-it
mc du name-it
mc du name-it/bucketname
mc admin user add name-it user1
mc admin user add name-it user2 12345678
mc admin user list name-it
mc admin user disable name-it user2
mc admin user list name-it
mc admin user enable name-it user2
mc admin user list name-it
mc admin user info name-it user2
mc admin user remove name-it user2
mc admin policy list name-it
mc admin policy info name-it readonly
mc admin policy info name-it writeonly
mc admin policy info name-it readwrite
mc admin policy add name-it bucket2-admin-role your-config.json
mc admin policy list name-it
mc admin user info name-it user2
mc admin policy set name-it bucket2-admin-role user=user2
mc admin user info name-it user2
mc admin policy unset name-it bucket2-admin-role user=user2
mc admin user info name-it user2
帮助
关于 mc 客户端的使用,当遇到不会用的命令时,可通过 --help 参数,查看帮助文档。
Reference
https://docs.min.io/minio/baremetal/reference/minio-mc.html
If you have any questions or any bugs are found, please feel free to contact me.
Your comments and suggestions are welcome!
|