MinIO客户端快速入门指南
官方文档地址:http://docs.minio.org.cn/docs/master/minio-client-quickstart-guide
MinIO Client (mc)为ls,cat,cp,mirror,diff,find等UNIX命令提供了一种替代方案。它支持文件系统和兼容Amazon S3的云存储服务(AWS Signature v2和v4)。
ls 列出文件和文件夹。
mb 创建一个存储桶或一个文件夹。
cat 显示文件和对象内容。
pipe 将一个STDIN重定向到一个对象或者文件或者STDOUT。
share 生成用于共享的URL。
cp 拷贝文件和对象。
mirror 给存储桶和文件夹做镜像。
find 基于参数查找文件。
diff 对两个文件夹或者存储桶比较差异。
rm 删除文件和对象。
events 管理对象通知。
watch 监听文件和对象的事件。
policy 管理访问策略。
session 为cp命令管理保存的会话。
config 管理mc配置文件。
update 检查软件更新。
version 输出版本信息。
GNU/Linux 二进制文件
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
./mc --help
添加一个云存储服务
添加一个或多个S3兼容的服务,请参考下面说明。mc将所有的配置信息都存储在~/.mc/config.json
文件中。
mc config host add <ALIAS> <YOUR-S3-ENDPOINT> <YOUR-ACCESS-KEY> <YOUR-SECRET-KEY> [--api API-SIGNATURE]
别名就是给你的云存储服务起了一个短点的外号。S3 endpoint,access key和secret key是你的云存储服务提供的。API签名是可选参数,默认情况下,它被设置为"S3v4"。
示例-MinIO云存储
从MinIO服务获得URL、access key和secret key。
URL需要指定端口
access key和secret key在新版里是指用户名和密码
# ./mc config host add minio https://192.168.20.102:9000 admin 12345678 --api s3v4
Added `minio` successfully.
说明:
根据实际启动后的MinIO服务端地址来定
- https: 自定义生成的证书,需要在服务器中进行有关设置,否则会报错:Get "https://192.168.20.102:9001/": x509: certificate signed by unknown authority
# cp /root/.minio/certs/public.crt /etc/pki/ca-trust/source/anchors/
cp /usr/local/minio/etc/certs/public.crt /etc/pki/ca-trust/source/anchors/ # 配置路径目录下的certs目录下的证书,参考Minio配置TLS访问
ln -s /etc/pki/ca-trust/source/anchors/public.crt /etc/ssl/certs/public.crt
update-ca-trust
- 不加端口号,表示使用的是https默认的443端口号,可以添加成功,但是访问服务端则会报错:Get "https://192.168.20.102/": dial tcp 192.168.20.102:443: connect: connection refused
- 使用9001端口,可以添加成功,但是访问服务端则会报错:S3 API Request made to Console port. S3 Requests should be sent to API port.
- admin 12345678
web页面访问使用的用户名和密码
mc配置信息:
# cat ~/.mc/config.json
{
"version": "10",
"aliases": {
"minio": {
"url": "https://192.168.20.102:9000",
"accessKey": "admin",
"secretKey": "12345678",
"api": "s3v4",
"path": "auto"
},
"gcs": {
"url": "https://storage.googleapis.com",
"accessKey": "YOUR-ACCESS-KEY-HERE",
"secretKey": "YOUR-SECRET-KEY-HERE",
"api": "S3v2",
"path": "dns"
},
"local": {
"url": "http://localhost:9000",
"accessKey": "",
"secretKey": "",
"api": "S3v4",
"path": "auto"
},
"play": {
"url": "https://play.min.io",
"accessKey": "Q3AM3UQ867SPQQA43P2F",
"secretKey": "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
"api": "S3v4",
"path": "auto"
},
"s3": {
"url": "https://s3.amazonaws.com",
"accessKey": "YOUR-ACCESS-KEY-HERE",
"secretKey": "YOUR-SECRET-KEY-HERE",
"api": "S3v4",
"path": "dns"
}
}
}
Shell别名
可以添加shell别名来覆盖默认的Unix工具命令。
alias ls='mc ls'
alias cp='mc cp'
alias cat='mc cat'
alias mkdir='mc mb'
alias pipe='mc pipe'
alias find='mc find'
Shell自动补全
下载autocomplete/bash_autocomplete到/etc/bash_completion.d/,然后将其重命名为mc。别忘了在这个文件运行source命令让其在你的当前shell上可用。
sudo wget https://raw.githubusercontent.com/minio/mc/master/autocomplete/bash_autocomplete -O /etc/bash_completion.d/mc
source /etc/bash_completion.d/mc
mc <TAB>
admin config diff ls mirror policy session update watch
cat cp events mb pipe rm share version
mc命令参数
NAME:
mc - MinIO Client for cloud storage and filesystems.
USAGE:
mc [FLAGS] COMMAND [COMMAND FLAGS | -h] [ARGUMENTS...]
COMMANDS:
alias manage server credentials in configuration file
ls list buckets and objects
mb make a bucket
rb remove a bucket
cp copy objects
mv move objects
rm remove object(s)
mirror synchronize object(s) to a remote site
cat display object contents
head display first 'n' lines of an object
pipe stream STDIN to an object
find search for objects
sql run sql queries on objects
stat show object metadata
tree list buckets and objects in a tree format
du summarize disk usage recursively
retention set retention for object(s)
legalhold manage legal hold for object(s)
support support related commands
share generate URL for temporary access to an object
version manage bucket versioning
ilm manage bucket lifecycle
encrypt manage bucket encryption config
event manage object notifications
watch listen for object notification events
undo undo PUT/DELETE operations
anonymous manage anonymous access to buckets and objects
tag manage tags for bucket and object(s)
diff list differences in object name, size, and date between two buckets
replicate configure server side bucket replication
admin manage MinIO servers
update update mc to latest release
GLOBAL FLAGS:
--autocompletion install auto-completion for your shell
--config-dir value, -C value path to configuration folder (default: "/root/.mc")
--quiet, -q disable progress bar display
--no-color disable color theme
--json enable JSON lines formatted output
--debug enable debug output
--insecure disable SSL certificate verification
--help, -h show help
--version, -v print the version
TIP:
Use 'mc --autocompletion' to enable shell autocompletion
VERSION:
RELEASE.2022-03-09T02-08-36Z