之前一直用docker的方式搭建Minio对象存储的方式使用,这次心血来潮想要自己在VPS上进行搭建。发现minio就一个可执行文件就完事了,不得不佩服golang大法静态编译就是好啊。那么剩下的就是写个systemd启动脚本来配置自动启动了。

搭建minio服务

下载minio的可执行文件

wget https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x minio

先通过命令行运行

./minio server --console-address ":9090" --address ":9000" /root/minio/data

可以看到如下输出

root@instance-jw4aEb7i:~/minio/app# ./minio server --console-address ":9090" --address ":9000" /root/minio/data
Formatting 1st pool, 1 set(s), 1 drives per set.
WARNING: Host local has more than 0 drives of set. A host failure will result in data becoming unavailable.
WARNING: Detected default credentials 'minioadmin:minioadmin', we recommend that you change these values with 'MINIO_ROOT_USER' and 'MINIO_ROOT_PASSWORD' environment variables
MinIO Object Storage Server
Copyright: 2015-2023 MinIO, Inc.
License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html>
Version: RELEASE.2023-12-02T10-51-33Z (go1.21.4 linux/amd64)

Status:         1 Online, 0 Offline.
S3-API: http://172.16.10.133:9000  http://127.0.0.1:9000
RootUser: minioadmin
RootPass: minioadmin

Console: http://172.16.10.133:9090 http://127.0.0.1:9090
RootUser: minioadmin
RootPass: minioadmin

Command-line: https://min.io/docs/minio/linux/reference/minio-mc.html#quickstart
   $ mc alias set 'myminio' 'http://172.16.10.133:9000' 'minioadmin' 'minioadmin'

Documentation: https://min.io/docs/minio/linux/index.html
Warning: The standard parity is set to 0. This can lead to data loss.

Cz7WHnh5dG7B7JOVUq5n4b-kkgNo-27cOTjJ_cBodHQ.png

接下来我们简单体验一下MINIO

由于我们没有设置用户密码,所以从运行信息中找到如下登录信息

luIMPEBwx8mGFLnX8E3FjX3Y2OsfJkQ29X4JO1sMTbU.png
成功登录将看到如下画面

9pqId-n_u08NmN4xqTEAMz_Z9tBTAQBIH6v6INPqGxQ.png

我们按照提示创建存储桶并且随便传点东西上去

jo4iJ4ZHtNPTqAS91MF0dxqWEi54jdRiuEE7fVomXVU.png

修改存储桶的访问策略,使得上传的文件可以被公网访问

UaGHIR0Pueh41iusfUgncOE2URiaqtZCrdFRU7r835Q.png

创建一个Access Keys通过客户端访问数据

k0_L5DR0zO7fTtOsNYqy3Lpc-sbBeuFb1mRzL6dEWjs.png

通过客户端上传一张图片

0CHThlVGkrjTzdkYH7R5vH7YwVR8uTjl0KWVfwORTN8.png

接下来去公网访问,输入MINIO的访问服务地址+存储桶和文件名称,就可以访问到刚上传的文件

pkk0EvC9BQF5P5Y4vYTnYJsvHfZbdApGrHev5-fKDTk.png

可以看到刚刚上传的图片
z39c82EzLTO-i_n_CVRkONaiJaahVG2Mi6ER-S_OFgA.png

编写systemd的service

将minio的目录移动到/opt/minio

编写一个配置文件存储到/etc/minio/minio.conf ,后续的启动脚本中会用到

MINIO_VOLUMES="/opt/minio/data"
MINIO_OPTS="--console-address :9090 --address :9000"
MINIO_ROOT_PASSWORD="minioadmin"
MINIO_ROOT_USER="minioadmin"

编写minio.service存储到/etc/systemd/system

[Unit]
Description=MINIO
Document=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/opt/minio/app/minio

[Service]
PermissionsStartOnly=true
EnvironmentFile=/etc/minio/minio.conf
ExecStartPre=/bin/bash -c "[ -n "${MINIO_VOLUMES}" ] || echo "Variable MINIO_VOLUMES not set in /etc/minio/minio.conf""
ExecStart=/opt/minio/app/minio server $MINIO_OPTS $MINIO_VOLUMES
Restart=always
LimitNOFILE=65536
TimeoutStopSec=infinity
SekndSIGKILL=no
StandardOutput=journal
StandardError=inherit


[Install]
WantedBy=multi-user.target

然后更新systemd配置缓存

systemctl daemon-reload

启动/停止/查询状态

systemctl [start|stop|status] minio.service

设置开机启动

systemctl enable minio.service

参考链接

https://blog.csdn.net/liu\_51com/article/details/122475877

https://www.cnblogs.com/revol/p/14561389.html