Minio entry series [3] Detailed explanation of using MinIO Client

1 Introduction

MC, referred to as mc, is the client of the minio server. It provides an alternative to UNIX commands such as ls, cat, cp, mirror, diff, find, etc. It supports file systems and cloud storage services compatible with Amazon S3 (AWS Signature v2 and v4 ).

ls       列出文件和文件夹。
mb       创建一个存储桶或一个文件夹。
cat      显示文件和对象内容。
pipe     将一个STDIN重定向到一个对象或者文件或者STDOUT。
share    生成用于共享的URL。
cp       拷贝文件和对象。
mirror   给存储桶和文件夹做镜像。
find     基于参数查找文件。
diff     对两个文件夹或者存储桶比较差异。
rm       删除文件和对象。
events   管理对象通知。
watch    监听文件和对象的事件。
policy   管理访问策略。
session  为cp命令管理保存的会话。
config   管理mc配置文件。
update   检查软件更新。
version  输出版本信息。

2 Centos 7 install mc

[root@hadoop001 MinIOClient]# wget http://dl.minio.org.cn/client/mc/release/linux-amd64/mc
[root@hadoop001 MinIOClient]# chmod +x mc 
[root@hadoop001 MinIOClient]# mv mc /usr/bin/
# 查看帮助
[root@hadoop001 MinIOClient]# mc -h

Insert image description here

Add server node:

[root@hadoop001 MinIOClient]# mc config host add s3 http://192.168.58.201:9000  admin  admin123  --api s3v4
[root@hadoop001 MinIOClient]# mc config host ls
# 查看s3下的所有存储桶
[root@hadoop001 MinIOClient]# mc ls s3

You can see that we are currently adding a node named s3 and all buckets under this node:
Insert image description here

3 Commonly used commands

3.1 ls lists buckets and objects

The ls command lists files, objects, and buckets. Use the –incomplete flag to list incomplete copies.

用法:
   mc ls [FLAGS] TARGET [TARGET ...]

FLAGS:
  --help, -h                       显示帮助。
  --recursive, -r          递归。
  --incomplete, -I         列出未完整上传的对象。

Example: List all buckets on s3.

[root@hadoop001 MinIOClient]# mc ls s3

Example: List all files under the bucket mall4cloud on s3.

[root@hadoop001 MinIOClient]# mc ls s3/mall4cloud

Insert image description here

3.2 mb command - create bucket

The mb command creates a new bucket on object storage. In the file system, it is the same as the mkdir -p command. A bucket is equivalent to a disk or mount point in a file system and should not be considered a folder. MinIO has no limit on the number of buckets created per user. On Amazon S3, each account is limited to 100 buckets.

用法:
   mc mb [FLAGS] TARGET [TARGET...]

FLAGS:
  --help, -h                       显示帮助。
  --region "us-east-1"         指定存储桶的region,默认是‘us-east-1’.

Example: Create a bucket named "bucket" on s3.

[root@hadoop001 MinIOClient]# mc mb s3/bucket

Insert image description here

3.3 cat command - merge objects

The cat command merges the contents of one file or object into another. You can also use it to output the contents of an object to stdout.

用法:
   mc cat [FLAGS] SOURCE [SOURCE...]

FLAGS:
  --help, -h                       显示帮助。

Example: Display the contents of the 2a10430fc3134e2196fa06eadfe25b23 file

[root@hadoop001 MinIOClient]# mc cat s3/mall4cloud/2023/09/08/2a10430fc3134e2196fa06eadfe25b23

Insert image description here

3.4 pipe command - Pipe to object

The pipe command copies the contents of stdin to the target output. If no target output is specified, the output is output to stdout.

用法:
   mc pipe [FLAGS] [TARGET]

FLAGS:
  --help, -h                    显示帮助。

Example: Output MySQL database dump file to Amazon S3.

mysqldump -u root -p ******* accountsdb | mc pipe s3/sql-backups/backups/accountsdb-oct-9-2015.sql

3.5 cp command - copy object

The cp command copies one or more source files to target output. All copy operations to object storage are verified by MD4SUM checkSUM. Interrupted or failed replication operations can be resumed from the point of failure.

用法:
   mc cp [FLAGS] SOURCE [SOURCE...] TARGET
FLAGS:
  --help, -h                       显示帮助。
  --recursive, -r          递归拷贝。

Example: Copy a local text file to object storage s3/aaaa.

[root@hadoop001 MinIOClient]# mc cp starh.sh s3/aaaa

3.6 rm command - delete buckets and objects.

Use the rm command to delete file objects or buckets.

用法:
   mc rm [FLAGS] TARGET [TARGET ...]

FLAGS:
  --help, -h                       显示帮助。
  --recursive, -r              递归删除。
  --force              强制执行删除操作。
  --prefix             删除批配这个前缀的对象。
  --incomplete, -I      删除未完整上传的对象。
  --fake               模拟一个假的删除操作。
  --stdin              从STDIN中读对象列表。
  --older-than value               删除N天前的对象(默认是0天)。

Example 1: Delete an object.

[root@hadoop001 MinIOClient]# mc rm s3/aaaa/starh.sh

Example 2: Delete a bucket and delete all contents recursively. Since this operation is too dangerous, you must pass the --force parameter to specify forced deletion.

[root@hadoop001 MinIOClient]# mc rm --recursive --force s3/qqqqq

Example 3: Delete all incompletely uploaded objects from mybucket.

[root@hadoop001 MinIOClient]# mc rm  --incomplete --recursive --force s3/bucket

Example 4: Delete objects older than one day.

[root@hadoop001 MinIOClient]# mc rm --force --older-than=1 s3/bucket/oldsongs

3.7 share command - sharing

The share command securely grants upload or download permissions. This access is temporary only and is securely shared with remote users and applications. If you want to grant permanent access, you can take a look at the mc policy command.

The generated URL contains encoded access authentication information, and any attempt to tamper with the URL will invalidate the access. To understand how this mechanism works, please refer to Pre-Signed URL technology.

用法:
   mc share [FLAGS] COMMAND

FLAGS:
  --help, -h                       显示帮助。

COMMANDS:
   download   生成有下载权限的URL。
   upload     生成有上传权限的URL。
   list       列出先前共享的对象和文件夹。

3.8 Subcommand share download - share download

The share download command generates a URL that can be downloaded without access key and secret key. The expiration parameter is set to the maximum validity period (not more than 7 days). After expiration, the permission is automatically recycled.

用法:
   mc share download [FLAGS] TARGET [TARGET...]

FLAGS:
  --help, -h                       显示帮助。
  --recursive, -r          递归共享所有对象。
  --expire, -E "168h"          设置过期时限,NN[h|m|s]

Example: Generate a URL with 4 hours of access to an object.

[root@hadoop001 MinIOClient]# mc share download --expire 4h s3/aaaa/aa.txt

3.9 Subcommand share upload - share upload

The share upload command generates a URL that can be uploaded without access key and secret key. The expiration parameter is set to the maximum validity period (no more than 7 days), and the permissions are automatically recycled after expiration. The Content-type parameter restricts the uploading of files of the specified type.

用法:
   mc share upload [FLAGS] TARGET [TARGET...]

FLAGS:
  --help, -h                       显示帮助。
  --recursive, -r              递归共享所有对象。
  --expire, -E "168h"          设置过期时限,NN[h|m|s].

Example: Generate a curl command to give permission to upload to play/mybucket/myotherobject.txt.

[root@hadoop001 MinIOClient]# mc share upload s3/bucket/myotherobject.txt

3.10 Subcommand share list - list previous shares

The share list lists all shared URLs that have not expired.

用法:
   mc share list COMMAND

COMMAND:
   upload:   列出先前共享的有上传权限的URL。
   download: 列出先前共享的有下载权限的URL。

3.11 mirror command - bucket mirroring

The mirror command is similar to rsync, except that it synchronizes between the file system and object storage.

用法:
   mc mirror [FLAGS] SOURCE TARGET

FLAGS:
  --help, -h                       显示帮助。
  --force              强制覆盖已经存在的目标。
  --fake               模拟一个假的操作。
  --watch, -w                      监听改变并执行镜像操作。
  --remove             删除目标上的外部的文件。

Example: Mirror a local folder minio to the 'bucket' bucket on https://play.min.io.

[root@hadoop001 MinIOClient]# mc mirror …/minio/MinIOClient/bucket

3.12 find command - find files and objects

The find command searches files by specifying parameters, and it only lists data that meets the conditions.

用法:
  mc find PATH [FLAGS]

FLAGS:
  --help, -h                       显示帮助。
  --exec value                     为每个匹配对象生成一个外部进程(请参阅FORMAT)
  --name value                     查找匹配通配符模式的对象。
  ...
  ...

Example: Continuously find all jpeg images from s3 bucket and copy to minio "minio/MinIOClient/bucket" bucket

[root@hadoop001 MinIOClient]# mc find s3/bucket --name "*.jpg" --watch --exec "mc cp {} minio/MinIOClient/bucket"

3.13 diff command - show differences

The diff command calculates the difference between two directories. It only lists content that is missing or of a different size.

It does not compare contents, so it is possible that objects with the same name and size but different contents are not detected. This way, it allows for quick comparison across different sites or large amounts of data.

用法:
  mc diff [FLAGS] FIRST SECOND

FLAGS:
  --help, -h                       显示帮助。

Example: Compare a local folder to a remote object storage service

[root@hadoop001 minio]# mc diff localdir minio/MinIOClient/bucket

4 others

Other commands are not listed one by one, please read in detail on the official website

https://minio.org.cn/docs/minio/linux/reference/minio-mc.html?ref=docs

Guess you like

Origin blog.csdn.net/qq_37284798/article/details/132900357