Docker series builds a private COS platform based on minio
本文最后更新于 362 天前,其中的信息可能已经有所发展或是发生改变,如有失效可到评论区留言。

Preface

When we usually want to share a file with friends, there are usually two ways:

1. Through the network disk

By uploading to a network disk (Baidu Netdisk, Alibaba Cloud Disk, etc.) and sharing it as a link, the recipient needs to save it to his own network disk or download it directly for playback. Both the sender and the receiver may be affected by factors such as whether they are paid members.

2. Send directly via WeChat or QQ

There is a size limit for sending files directly via WeChat. It doesn't matter for small files, but it's impossible to send large files directly via WeChat. In fact, QQ does have some advantages in sending files, but there are also restrictions on offline sending (2G or 4G, I can't remember, it seems to be related to whether you are a member). There is no limit for sending online, but both parties must be present, and the speed is hard to say.

After all the calculations, there is no perfect way to share a file normally.

At this time, the object storage (COS) solution becomes the best choice. You can share various types of files by generating an http(s) link, which can be downloaded directly or opened online. It is a little helper in daily life. In fact, all cloud server providers provide COS services, and the price is not expensive from Tencent Cloud. Individuals also have a free quota of 50GB (6 months). However, in line with the principle of building a home data center and self-built services at no cost, it is better to build a free COS yourself. Currently, the best open source free object storage is minio, and we use the simplest docker deployment method.

Deploy minio COS

The minio docker repository actually contains several components, but generally speaking, we only need one server for minimal deployment. One problem with deploying only the server is that the shared link is only valid for 7 days at most. If this time is enough for everyone, there is no need to bother with it, and one server is enough. However, if you want to set it to be permanently valid (for example, for use on a web page), you need to install a client to configure the policy for the bucket on the server.

Install minio server

Because a bridge named public-net is used below, it needs to be created in advance:

docker network create public-net

Deploy minio server:
The command is as follows:

docker run --name minioserver -d --restart=always --network=public-net -v /docker/minio/data:/data -p 9000:9000 -p 9001:9001 -e "MINIO_ROOT_USER=root" -e "MINIO_ROOT_PASSWORD=123" \ minio/minio server /data --console-address ":9001"

The parameters are explained as follows:
-v /docker/minio/data:/data Map the host's /docker/minio/data directory to the /data directory inside the container
-p 9000:9000 -p 9001:9001 Map the host's ports 9000 and 9001 to the container's ports 9000 and 9001 respectively
-e "MINIO_ROOT_USER=root" -e "MINIO_ROOT_PASSWORD=123" Specify the login username and password of minio server. If not specified, the default login username and password areminioadmin
server /data Start the server and set the /data directory as the data directory
--console-address ":9001" Specify port 9001 as the console port

After the container is started, you can log in to the console directly using http://host ip:9001.
The management unit in COS is buckets. By default, there is no bucket. You need to create one first:

image.png

Here I have created a bucket named video, as shown above. Click into the video bucket, and then click the Browse Buckets button in the upper right corner with a red frame:
image.png

At this time, you can enter the bucket. Here you can directly upload files through the Upload button in the upper right red box, or you can use the Create new path button in the lower right red box to create a category folder first and then upload the file. For example, in the figure below, I created the mtv folder:
image.png

In the mtv folder I uploaded 2 mtv:
image.png

In theory, you can start sharing now, there are two ways:
1. Select the file in the web interface and directly generate a sharing link:
image.png

image.png

The advantage of this method is that you can specify the validity period of the shared link (maximum 7 days, minimum 1 minute). The disadvantage is that the link is too long and cannot be used directly. If you want to use it on the intranet, you need to change 127.0.0.1 to the intranet IP address of the host machine; if you want to use it on the Internet, you need to change it to the reverse proxy domain name or the cloud host public IP (if it is not a standard port, such as 80 and 443, you also need to add the specific port).

2. Directly manually splice the address:
Intranet use:http://host machine intranet IP:9000/mtv/zebrazebra.mp4
Extranet use:https://reverse proxy public network IP or domain name: port/mtv/zebra zebra.mp4The port is added only when using non-standard ports, such as my home broadband. If it is port 80 or 443, it does not need to be added.

This method is obviously much more efficient and is the recommended method. However, the disadvantage is that the time cannot be customized and can only expire in the default 7 days.

Regardless of the first or second method, if you want to publish through a reverse proxy, you need to set up the reverse proxy first. There are many reverse proxy setting tutorials on the Internet, so I won’t repeat them. However, there is a key point here, which is also a very tricky point: look at the sharing link on the previous web interface:

image.png

In fact, you may not think of it just by looking at this, but after setting up the reverse proxy, it has not been successful and reported the following error:
image.png

I didn't think about the host address and port at first, but after struggling for a long time, I suddenly thought that it would not be so boring to limit the host and port, so I set the transfer domain name and port on the reverse proxy (taking the Baota Linux panel as an example):
image.png

Then it worked. . The docker of minio server actually restricted the host address and port to 127.0.0.1:9000. This really screwed me up. Who could have thought of this. . ?

In short, in fact, up to this point, it is enough for most people to use. The 7-day limit is fine under normal use, but what about abnormal environments? For example, when you want to use it on a web page or blog.

If you want to break the 7-day limit, you need to use minio client.

Install minio client:

The command is as follows:

docker run -it --name minioclient -d --restart=always --network=public-net --entrypoint=/bin/sh minio/mc

After docker is started, directly enter the command line inside the minioclient container (or use docker exec to execute, depending on your habits):
Bind the established minio server in minio client. The command format is as follows:

mc alias set [YOUR-ACCESS-KEY] [YOUR-SECRET-KEY]

Among them, alias is the alias of minio server; your-minio-endpoint is the access link of minio server. Taking my environment as an example, the IP address of the docker host is 192.168.10.130, port 9000, then the access link ishttp://192.168.10.130:9000 ; YOUR-ACCESS-KEY and YOUR-SECRET-KEY need to be generated on the minio server, as shown in the following figure:

image.png

The actual command is as follows, taking my environment as an example:

mc config host add minio http://192.168.10.130:9000 YOUR-ACCESS-KEY YOUR-SECRET-KEY --api S3v4

Normally it will display:

image.png

Use the mc ls command to view the contents of the storage just created:

mc ls minio

Normally, you will see the bucket we created earlier:

image.png

Use the mc alias ls command to view the newly created alias minio

mc alias ls minio

image.png

Using the mc anonymous command, you can see that there are four strategies, as shown in the red box below:
image.png

Among them, upload corresponds to write-only, download corresponds to read-only, we need to set the bucket video to download:

mc anonymous set download minio/video

image.png

Mission accomplished.

The content of the blog is original. Please indicate the source when reprinting! For more blog articles, you can go toSitemapUnderstand. The RSS address of the blog is:https://blog.tangwudi.com/feed, welcome to subscribe; if necessary, you can joinTelegram GroupDiscuss the problem together.
No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠(ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ°Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
Emoticons
Emoji
Little Dinosaur
flower!
Previous
Next
       
error:
en_US
Spring Festival
hapiness