Building minio object storage and commonly used mc client commands using Docker

Publish: 2021-08-02 | Modify: 2022-04-19

MinIO is an object storage service based on the Apache License v2.0 open source protocol. It is compatible with the Amazon S3 cloud storage service interface and is ideal for storing large volumes of unstructured data such as images, videos, log files, backup data, and container/virtual machine images. This article shares how to use Docker to set up a single-disk instance of the MinIO object storage service.

Setting up MinIO Server with Docker

Before you start, make sure you have Docker installed. Refer to: Install Docker and Common Docker Commands for Linux, then copy and execute the following command:

docker run -d -p 9000:9000 \
  -p 9001:9001 \
  --name minio \
  -v /data/minio:/data \
  -e "MINIO_ROOT_USER=xxx" \
  -e "MINIO_ROOT_PASSWORD=xxx" \
  -e MINIO_DOMAIN="xxx.com" \
  --restart=always \
  minio/minio server /data --console-address ":9001"

The above parameters are explained as follows:

  • 9000 is the data communication port, which you use when uploading objects via the client or API.
  • /data/minio is the local mount path.
  • MINIO_ROOT_USER sets the username.
  • MINIO_ROOT_PASSWORD sets the password.
  • MINIO_DOMAIN sets the domain name, which will be explained further below.
  • --console-address ":9001" is the web access port, which was not available in older versions but has been added recently.

The Purpose of the Domain Name

By default, if you want to access an object, the address is: http://IP:9001/bucket/xxx.txt. If you added the MINIO_DOMAIN parameter during setup and have the domain name properly resolved, you can access the object in the following way: http://bucket.xxx.com/1.txt, where bucket is mapped to the host name (domain name prefix).

Accessing and Setting Up

After the setup is complete, access it through IP:9001 (or you can use the domain name if properly resolved), and enter the username and password you set earlier.

Those who have used object storage should be familiar with the concept of buckets. In Chinese, it is translated as "桶" (bucket). Our objects (files) are stored inside these "buckets". Next, click on "Create Bucket" to create a bucket.

You can choose any name for the bucket, as long as it is not duplicated. You can also choose whether to enable object (file) versioning and set some data limitations (such as capacity or file count). However, since it is running on a single disk, it seems that these features are not supported.

Installing the mc Client

The mc client is used to operate and manage MinIO. Taking Linux as an example:

# Download the mc client
wget https://dl.min.io/client/mc/release/linux-amd64/mc
# Add execute permissions
chmod +x mc
# Move it to the /usr/bin directory
mv mc /usr/bin/
# View the help
./mc --help

Before using it, we need to set it up. Execute the following command to add a MinIO storage:

mc config host add minio http://192.168.1.51 BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12 --api s3v4
  • http://192.168.1.51 is the IP address of the MinIO server (note that you need to include the port number; if you installed it using the Docker method mentioned above, it should include the 9000 port).
  • BKIKJAA5BMMU2RHO6IBB corresponds to the username (AccessKeyID) mentioned earlier.
  • V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12 corresponds to the password (SecretAccessKey) mentioned earlier.

After adding, it will be written to a configuration file located at /root/.mc/config.json. If you need to remove a storage, you can directly edit the JSON file or use the following command:

# Remove the storage named "minio"
mc config host remove minio

Here are some commonly used commands:

ls       List files and folders.
mb       Create a bucket or folder.
cat      Display the content of a file or object.
pipe     Redirect STDIN to an object, file, or STDOUT.
share    Generate a URL for sharing.
cp       Copy a file or object to a target host.
mirror   Mirror a bucket or folder.
find     Find files based on parameters.
diff     Compare differences between two folders or buckets.
rm       Delete a file or object.
events   Manage object notifications.
watch    Watch events for files and objects.
policy   Manage access policies.
session  Manage saved sessions for the cp command.
config   Manage mc configuration files.
update   Check for software updates.
version  Output version information.

Examples of Common mc Commands

# View the list of added hosts
mc config host list
# View the files in a specified bucket
mc ls host/bucket/
# Copy a file (object) to the target host
mc cp local_file host/bucket/
# Copy a file from MinIO to the local machine
mc cp host/bucket/file_name ./
# Set the anonymous access policy for MinIO; possible values are none, download, upload, public
mc policy set upload host/bucket/
# View the anonymous policy
mc policy list host/bucket/
  • host: the name you set when using mc config host add.
  • bucket: the name of the bucket.

Note: It is generally not recommended to set the anonymous access policy to public, as it allows anyone to upload, download, and delete files, which is a very dangerous operation. If you want to make a file publicly accessible, it is usually sufficient to set it to download.

Further Operations

You can refer to my other article: Use Nginx Reverse Proxy for MinIO to Provide Public File Access.

Conclusion

The above content provides a simple introduction to the installation of the MinIO server and basic usage of the mc client. MinIO has many more features and capabilities. This article only covers the quick setup and demonstration of a single-disk instance. For production purposes, it is recommended to set up a distributed solution with multiple disks. MinIO, as an enterprise-level self-built object storage solution, is already quite mature and complete, and it is relatively easy to get started with. If your organization has object storage needs, MinIO is worth a try.


Comments