部署MinIO,并使用s3fs测试挂载s3存储。

1.使用Docker部署MinIO

2.配置MinIO,创建桶,创建用户

3.使用s3fs挂载s3存储

1.部署MinIO

1.1docker启动

docker run -p 9000:9000 -p 9001:9001 quay.io/minio/minio server /minio --console-address ":9001"

持久化存储部署

docker run -itd --name minio -p 9000:9000 -p 9001:9001 -v /opt/minio/data:/data quay.io/minio/minio server /data --console-address ":9001"

server /data为您希望 MinIO 存储数据的驱动器或目录的路径

--console-address ":9001"默认情况下,MinIO会在随机端口上运行console,如果您希望选择特定的端口,请使用--console-address来选择特定的接口和端口。

用户名:密码

minioadmin:minioadmin
[root@pangu minio]# docker run -p 9000:9000 -p 9001:9001 quay.io/minio/minio server /minio --console-address ":9001"
WARNING: Detected Linux kernel version older than 4.0.0 release, there are some known potential performance problems with this kernel version. MinIO recommends a minimum of 4.x.x linux kernel version for best performance
API: http://172.17.0.2:9000  http://127.0.0.1:9000 

Console: http://172.17.0.2:9001 http://127.0.0.1:9001 

Documentation: https://docs.min.io
Finished loading IAM sub-system (took 0.0s of 0.0s to load data).

1.2访问WEB服务

通过:http://localhost:9001/

1.3创建桶

Buckets -> Create Bucket -> Bucket Name(自定义名称) -> Create Bucket

在桶中,上传文件,新建目录

1.4创建用户

(授予读写权限)

Identity -> Users -> Create User -> 输入ACCESS_KEY_ID和SECRET_ACCESS_KEY(自定义) -> Policies -> readwrite(选择读写权限) -> Save
ACCESS_KEY_ID: admin
SECRET_ACCESS_KEY: admin@123456

用户状态为Enabled,否则挂载报错

User Status: Enabled

2022-04-14T05:07:28.177Z [ERR] curl.cpp:RequestPerform(2371): HTTP response code 403, returning EPERM. Body Text: <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidAccessKeyId</Code><Message>Your account is disabled; please contact your administrator.</Message><BucketName>test</BucketName><Resource>/test/</Resource><RequestId>16E5AAFE6A2EF22D</RequestId><HostId>7a3f6114-d1bf-41c5-8e97-856574810713</HostId></Error>
2022-04-14T05:07:28.177Z [ERR] curl.cpp:CheckBucket(3515): Check bucket failed, S3 response: <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidAccessKeyId</Code><Message>Your account is disabled; please contact your administrator.</Message><BucketName>test</BucketName><Resource>/test/</Resource><RequestId>16E5AAFE6A2EF22D</RequestId><HostId>7a3f6114-d1bf-41c5-8e97-856574810713</HostId></Error>
2022-04-14T05:07:28.177Z [CRT] s3fs.cpp:s3fs_check_service(3587): invalid credentials(host=http://192.168.0.160:9000) - result of checking service.
2022-04-14T05:07:28.177Z [ERR] s3fs.cpp:s3fs_exit_fuseloop(3383): Exiting FUSE event loop due to errors

2022-04-14T05:07:28.182Z [INF] s3fs.cpp:s3fs_destroy(3437): destroy

用户不是读写权限,挂载时报错

# 使用参数-d -f查看实时日志
s3fs test /data -o passwd_file=${HOME}/.passwd-s3fs -o url=http://192.168.0.160:9000 -o use_path_request_style -d -f


2022-04-14T05:08:41.128Z [ERR] curl.cpp:RequestPerform(2371): HTTP response code 403, returning EPERM. Body Text: <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied.</Message><BucketName>test</BucketName><Resource>/test/</Resource><RequestId>16E5AB0F66725CE4</RequestId><HostId>7a3f6114-d1bf-41c5-8e97-856574810713</HostId></Error>
2022-04-14T05:08:41.128Z [ERR] curl.cpp:CheckBucket(3515): Check bucket failed, S3 response: <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied.</Message><BucketName>test</BucketName><Resource>/test/</Resource><RequestId>16E5AB0F66725CE4</RequestId><HostId>7a3f6114-d1bf-41c5-8e97-856574810713</HostId></Error>
2022-04-14T05:08:41.128Z [CRT] s3fs.cpp:s3fs_check_service(3587): invalid credentials(host=http://192.168.0.160:9000) - result of checking service.
2022-04-14T05:08:41.129Z [ERR] s3fs.cpp:s3fs_exit_fuseloop(3383): Exiting FUSE event loop due to errors

2022-04-14T05:08:41.137Z [INF] s3fs.cpp:s3fs_destroy(3437): destroy

2.使用s3fs挂载s3存储

2.1安装s3fs

https://github.com/s3fs-fuse/s3fs-fuse

rhel/centos

sudo yum install epel-release
sudo yum install s3fs-fuse

Ubuntu

sudo apt install s3fs

2.2创建密码文件

echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs
chmod 600 ${HOME}/.passwd-s3fs

需要修改文件权限为600,否则挂载报错

[root@pangu-test ~]# s3fs s3fs-mount-bucket /data -o passwd_file=${HOME}/.passwd-s3fs -o url=http://192.168.0.160:9000 -o use_path_request_style
s3fs: credentials file /root/.passwd-s3fs should not have others permissions.

2.3使用s3fs挂载非 Amazon S3

# 命令 桶名 挂载路径 密码文件 访问地址 use_path_request_style使用路径访问方式,使用自己的存储,必须添加,否则报错
s3fs mybucket /path/to/mountpoint -o passwd_file=${HOME}/.passwd-s3fs -o url=https://url.to.s3/ -o use_path_request_style

/etc/fstab中挂载配置

mybucket /path/to/mountpoint fuse.s3fs _netdev,allow_other,use_path_request_style,url=https://url.to.s3/ 0 0

实例

s3fs test /data -o passwd_file=${HOME}/.passwd-s3fs -o url=http://192.168.0.160:9000 -o use_path_request_style

df -h查看会有一个s3fs的挂载信息

[root@pangu-test 研报]# df  -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 3.9G     0  3.9G    0% /dev
tmpfs                    3.9G     0  3.9G    0% /dev/shm
tmpfs                    3.9G  8.9M  3.9G    1% /run
tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
/dev/mapper/centos-root   44G   35G  9.2G   80% /
/dev/sda1               1014M  150M  865M   15% /boot
tmpfs                    783M     0  783M    0% /run/user/0
s3fs                      16E     0   16E    0% /data

查看/data

[root@pangu-test data]# ll /data/
总用量 773
drwxr-x--- 1 root root      0 1月   1 1970 kkkkkkk
drwxr-x--- 1 root root      0 4月  14 13:10 lllll
-rw-r----- 1 root root 790061 4月  14 13:01 xxxxxxx.pdf

挂载有问题的话,加参数-d -f,实时查看日志,也可以加参数-d -d -f -o f2 -o curldbg输出日志

s3fs test /data -o passwd_file=${HOME}/.passwd-s3fs -o url=http://192.168.0.160:9000 -o use_path_request_style -d -f

df -h查看是否挂载成功,如果不成功,可以加参数-d -d -f -o f2 -o curldbg输出日志,客户端与minio服务器系统时间要同步

标签: MinIO

添加新评论