MinIO is a high-performance, cloud-native object store that runs anywhere (public cloud, private cloud, colo, onprem).
The code in this story is for educational purposes. The readers are solely responsible for whatever they build with it.
This writer has a vested interest be it monetary, business, or otherwise, with 1 or more of the products or companies mentioned within.
Walkthroughs, tutorials, guides, and tips. This story will teach you how to do something new or how to do something better.
MinIO 是应用最广泛的对象存储之一,因为它提供高性能、大规模可扩展性、高可用性并遵守行业标准 S3 协议。 MinIO 具有惊人的性能 - 最近的基准测试在 GET 上实现了 325 GiB/s (349 GB/s),在 PUT 上实现了 165 GiB/s (177 GB/s),仅使用 32 个现成 NVMe SSD 节点。无论您在何处运行 MinIO(裸机、虚拟实例还是 Kubernetes),MinIO 的性能和可扩展性都为数据湖、分析、AI/ML 等云原生应用程序提供了良好的基础。
除了 Kubernetes 之外,客户还在虚拟实例和裸机上运行 MinIO,经常依赖数据中心和AWS 、 GCP和Azure等云中的Supermicro 硬件。 Linux 占用空间小,加上高效的资源利用,使其成为运行 MinIO 的通用且灵活的选择。然而,越来越多的 Linux 机器和实例需要自动化来减轻管理负担。需要使用 SystemD 将 MinIO 服务器作为 init 服务进行管理,因为它有助于自动化服务生命周期,特别是在启动、关闭和重新启动期间。
SystemD是一个服务管理器,在启动、关闭、初始化等过程中维护 Linux 系统中的服务。将其视为初始化脚本的后继者,您必须从头开始编写整个脚本,但使用 SystemD,您只需填写一些参数,并且命令和日志记录都是标准化的。
使用较旧的 init.d 服务管理的几个挑战之一是您必须从头开始编写整个文件。每个 init.d 文件都是唯一的,并且具有不同的管理服务生命周期的方式。 SystemD 汲取了 init.d 的经验教训并将其标准化。例如,SystemD 服务文件将适用于任何服务,只要它被写入运行 - 只是路径、名称和语义不同 - 但基本结构、如何重新启动服务、读取日志、优雅地卸载文件系统、等待除其他事项外,网络连接现在在所有服务中都很常见,因此无论您运行哪个服务,您都知道在哪里查找其日志。
SystemD 不仅在不同的服务之间具有通用性,而且您还可以采用相同的 SystemD 服务文件并在多个操作系统中使用它,只要操作系统也使用 SystemD 来管理其服务的生命周期。这简化了自动化,因为您可以在创建初始文件时在 Ubuntu 上工作,但只要路径和其他内容保持不变(在大多数情况下),相同的文件就可以部署到 CentOS/RedHat 操作系统。
SystemD 有几个主要组件,但您会更经常遇到的一些组件是:
systemctl
:这是用来控制进程的,主要是是否停止、启动和重新启动。最常用的命令是: systemctl start <service>
systemctl stop <service>
systemctl restart <service>
journalctl -e -u <service>
要运行本指南中的大部分命令,您需要具有“sudo”或 root 访问权限,因为 SystemD 配置文件需要获得 root 权限。
您还可以在我们的存储库中找到有关 MinIO 和 SystemD 的其他说明。
# wget https://dl.min.io/server/minio/release/linux-amd64/minio --2022-07-24 11:31:33-- https://dl.min.io/server/minio/release/linux-amd64/minio Resolving dl.min.io (dl.min.io)... 132.68.11.115, 138.118.66.212 Connecting to dl.min.io (dl.min.io)|132.68.11.115|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 96649216 (92M) [application/octet-stream] Saving to: 'minio' minio 100%[==========================================>] 92.17M 50.2MB/s in 1.8s 2022-07-24 11:31:35 (50.2 MB/s) - 'minio' saved [96649216/96649216]
# chmod +x minio
# mv minio /usr/local/bin/
根据操作系统的不同,MinIO 可以通过几种不同的方式在 Linux 上安装。 RedHat/CentOS 及其衍生版本依赖 .rpm 包,Debian/Ubuntu 使用 .deb 包。在这两种情况下,安装包中都包含以下 SystemD 服务文件。
但是,我们手动从上游获取 MinIO 二进制文件,因此我们将手动创建 SystemD 服务文件。
/etc/systemd/system/minio.service
中创建包含以下内容的 SystemD 文件。
[Unit] Description=MinIO Documentation=https://docs.min.io Wants=network-online.target After=network-online.target AssertFileIsExecutable=/usr/local/bin/minio [Service] WorkingDirectory=/usr/local User=minio-user Group=minio-user ProtectProc=invisible EnvironmentFile=-/etc/default/minio ExecStartPre=/bin/bash -c "if [ -z \"${MINIO_VOLUMES}\" ]; then echo \"Variable MINIO_VOLUMES not set in /etc/default/minio\"; exit 1; fi" ExecStart=/usr/local/bin/minio server $MINIO_OPTS $MINIO_VOLUMES # Let systemd restart this service always Restart=always # Specifies the maximum file descriptor number that can be opened by this process LimitNOFILE=65536 # Specifies the maximum number of threads this process can create TasksMax=infinity # Disable timeout logic and wait until process is stopped TimeoutStopSec=infinity SendSIGKILL=no [Install] WantedBy=multi-user.target # Built for ${project.name}-${project.version} (${project.name})
Group=minio-user
:Minio 守护程序将作为其运行的 Linux 系统组。使用以下命令创建它:
groupadd -r minio-user
User=minio-user
:MinIO 守护程序将作为 Linux 系统用户运行。使用以下命令创建用户:
useradd -M -r -g minio-user minio-user
-M
:这可以防止为用户创建主目录,因为这是一项服务。-r
:系统用户有一个单独的 UID/GID 范围用于跟踪目的,此标志将从预定范围创建用户。-g <group_name>
:要在其下添加用户的组。
在启动 MinIO 服务之前,需要在裸机节点上设置几个先决条件。
Error: Disk /mnt/disk1/minio is part of root disk, will not be used
/mnt/data
:
mkdir -p /mnt/data/disk1 \ mkdir -p /mnt/data/disk2 \ mkdir -p /mnt/data/disk3 \ mkdir -p /mnt/data/disk4
chown
目录chown minio-user:minio-user /mnt/data/disk1 /mnt/data/disk2 /mnt/data/disk3 /mnt/data/disk4
/etc/default/minio
# Set the hosts and volumes MinIO uses at startup # The command uses MinIO expansion notation {x...y} to denote a # sequential series. # # The following example covers four MinIO hosts # with 4 drives each at the specified hostname and drive locations. # The command includes the port that each MinIO server listens on # (default 9000) MINIO_VOLUMES="https://minio1.example.com:9000/mnt/data/disk{1...4}/minio" # Set all MinIO server options # # The following explicitly sets the MinIO Console listen address to # port 9001 on all network interfaces. The default behavior is dynamic # port selection. MINIO_OPTS="--console-address :9001" # Set the root username. This user has unrestricted permissions to # perform S3 and administrative API operations on any resource in the # deployment. # # Defer to your organizations requirements for superadmin user name. MINIO_ROOT_USER=minioadmin # Set the root password # # Use a long, random, unique string that meets your organizations # requirements for passwords. MINIO_ROOT_PASSWORD=minioadmin # Set to the URL of the load balancer for the MinIO deployment # This value *must* match across all MinIO servers. If you do # not have a load balancer, set this value to to any *one* of the # MinIO hosts in the deployment as a temporary measure. MINIO_SERVER_URL="https://minio.example.net:9000"
# systemctl enable minio.service # systemctl start minio.service
# systemctl status minio.service # journalctl -e -u minio.service
Aug 01 13:27:06 aj-test-3 systemd[1]: Starting MinIO... Aug 01 13:27:06 aj-test-3 systemd[1]: Started MinIO. Aug 01 13:27:07 aj-test-3 minio[3241]: Formatting 1st pool, 1 set(s), 4 drives per set. Aug 01 13:27:07 aj-test-3 minio[3241]: WARNING: Host minio1.example.com:9000 has more than 2 drives of set. A host fai> Aug 01 13:27:07 aj-test-3 minio[3241]: You are running an older version of MinIO released 4 days ago Aug 01 13:27:07 aj-test-3 minio[3241]: Update: Run `mc admin update` Aug 01 13:27:07 aj-test-3 minio[3241]: MinIO Object Storage Server Aug 01 13:27:07 aj-test-3 minio[3241]: Copyright: 2015-2022 MinIO, Inc. Aug 01 13:27:07 aj-test-3 minio[3241]: License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl-3.0.html> Aug 01 13:27:07 aj-test-3 minio[3241]: Version: RELEASE.2022-07-26T00-53-03Z (go1.18.4 linux/amd64) Aug 01 13:27:07 aj-test-3 minio[3241]: Status: 4 Online, 0 Offline. Aug 01 13:27:07 aj-test-3 minio[3241]: API: https://minio.example.net:9000 Aug 01 13:27:07 aj-test-3 minio[3241]: Console: http://10.128.0.4:9001 http://127.0.0.1:9001 Aug 01 13:27:07 aj-test-3 minio[3241]: Documentation: https://docs.min.io
使用浏览器,使用我们之前配置中的MINIO_ROOT_USER
和MINIO_ROOT_PASSWORD
登录 MinIO 控制台。
http://<server_host_ip>:9001/
请注意,上述设置是为了让您快速启动并运行 MinIO。您可以从单节点扩展到多节点分布式配置以进行其他测试。如果您想在生产环境中部署和配置 MinIO,请参阅文档。
与 SystemD 的集成非常通用。
所有服务的服务文件的语法都是相同的
相同的服务文件可以在任何支持 SystemD 的操作系统上运行
您可以将 SystemD 与裸机或任何云中的虚拟机(例如 AWS、GCP 和 Azure)一起使用。
这可以通过标准化格式并简化自动化部署来帮助实现 DevOps 自动化。
在运行对象存储等关键任务服务时,自动化对于维持可用性大有帮助。自动化是跨多个云和环境进行大规模操作的要求。借助 SystemD 和 MinIO,您可以自动化云对象存储部署,并确保服务生命周期顺利、成功地管理。
有疑问吗?想开始吗?通过Slack联系我们。
也发布在这里。
使用 MinIO 和 SystemD 自动化云存储部署 | HackerNoon