From f73bc6a82b9077dc6b12f7f20e6a7fe8574f2a80 Mon Sep 17 00:00:00 2001 From: houseme Date: Wed, 9 Apr 2025 19:11:56 +0800 Subject: [PATCH] add rsutfs.service and run.md --- rustfs-zh.service | 102 ++++++++++++++++++++++++++++++++++++++++++++++ rustfs.run-zh.md | 90 ++++++++++++++++++++++++++++++++++++++++ rustfs.run.md | 90 ++++++++++++++++++++++++++++++++++++++++ rustfs.service | 60 +++++++++++++++++++++++++++ 4 files changed, 342 insertions(+) create mode 100644 rustfs-zh.service create mode 100644 rustfs.run-zh.md create mode 100644 rustfs.run.md create mode 100644 rustfs.service diff --git a/rustfs-zh.service b/rustfs-zh.service new file mode 100644 index 000000000..2541ec77c --- /dev/null +++ b/rustfs-zh.service @@ -0,0 +1,102 @@ +[Unit] +Description=RustFS Object Storage Server +# 定义服务的描述,说明这是一个 RustFS 对象存储服务器,显示在 systemctl status 中。 +Documentation=https://rustfs.com/docs/ +# 提供服务的官方文档链接,方便管理员查阅,占位符需替换为实际 URL。 +After=network-online.target +# 指定服务在 network-online.target(网络就绪)之后启动,确保网络可用。 +Wants=network-online.target +# 表示服务希望依赖 network-online.target,但不是强依赖,即使网络未就绪也尝试启动。 +# If you're using a database, you'll need to add the corresponding dependencies +# 如果服务依赖数据库,可以添加数据库相关的依赖项(当前为注释,未启用)。 +# After=postgresql.service +# 示例:若依赖 PostgreSQL,则在 PostgreSQL 服务后启动(当前未启用)。 +# Requires=postgresql.service +# 示例:若强制依赖 PostgreSQL,则要求其启动成功(当前未启用)。 + +[Service] +Type=notify +# 服务类型为 notify,表示服务通过 sd_notify 通知 systemd 其状态(如就绪)。 +NotifyAccess=main +# 指定只有主进程可以发送通知给 systemd,避免子进程干扰。 +User=rustfs +# 以 rustfs 用户身份运行服务,需预先创建此用户,提升安全性。 +Group=rustfs +# 以 rustfs 组身份运行服务,与 User 配合使用。 + +# environment variable configuration +# 定义环境变量配置,用于传递给服务程序。 +Environment=RUST_LOG=info +# 设置日志级别为 info,控制服务日志输出(需服务支持此变量)。 +Environment=RUSTFS_ACCESS_KEY=rustfsadmin +# 设置访问密钥为 rustfsadmin,用于 RustFS 的认证。 +Environment=RUSTFS_SECRET_KEY=rustfsadmin +# 设置秘密密钥为 rustfsadmin,与访问密钥配套使用。 + +# working directory +WorkingDirectory=/opt/rustfs +# 设置服务的工作目录为 /opt/rustfs,影响相对路径的解析。 + +# main program +ExecStart=/usr/local/bin/rustfs \ + --address 0.0.0.0:9000 \ + --volumes /data/rustfs/vol1,/data/rustfs/vol2 \ + --obs-config /etc/rustfs/obs.yaml \ + --console-enable \ + --console-address 0.0.0.0:9002 +# 定义启动命令,运行 /usr/local/bin/rustfs,带参数: +# --address 0.0.0.0:9000:服务监听所有接口的 9000 端口。 +# --volumes:指定存储卷路径为 /data/rustfs/vol1 和 /data/rustfs/vol2。 +# --obs-config:指定配置文件路径为 /etc/rustfs/obs.yaml。 +# --console-enable:启用控制台功能。 +# --console-address 0.0.0.0:9002:控制台监听所有接口的 9002 端口。 + +# resource constraints +LimitNOFILE=1048576 +# 设置文件描述符上限为 1048576,支持高并发连接。 +LimitNPROC=32768 +# 设置进程数上限为 32768,限制子进程数量。 +TasksMax=infinity +# 允许服务创建无限数量的线程(谨慎使用,可能耗尽资源)。 + +# restart the policy +Restart=always +# 服务异常退出时总是重启,提高可用性。 +RestartSec=10s +# 重启前等待 10 秒,避免频繁重启导致资源浪费。 + +# graceful exit configuration +TimeoutStartSec=30s +# 启动超时时间为 30 秒,若超时则认为启动失败。 +TimeoutStopSec=30s +# 停止超时时间为 30 秒,若超时则强制停止。 + +# security settings +NoNewPrivileges=true +# 禁止服务提升权限,增强安全性。 +ProtectSystem=full +# 保护系统目录(如 /usr、/boot、/etc)为只读,防止服务修改。 +ProtectHome=true +# 保护用户主目录(如 /home、/root),禁止服务访问。 +PrivateTmp=true +# 为服务提供私有 /tmp 目录,隔离临时文件。 +PrivateDevices=true +# 禁止服务访问硬件设备(如 /dev),提升安全性。 +ProtectClock=true +# 保护系统时钟,禁止服务修改时间。 +ProtectKernelTunables=true +# 保护内核参数(/proc/sys),禁止服务修改。 +ProtectKernelModules=true +# 禁止服务加载或卸载内核模块。 +ProtectControlGroups=true +# 保护控制组(cgroups),禁止服务修改。 +RestrictSUIDSGID=true +# 禁止服务使用 SUID/SGID 文件,提升安全性。 +RestrictRealtime=true +# 禁止服务使用实时调度,防止资源滥用。 +ReadWritePaths=/data/rustfs +# 允许服务对 /data/rustfs 目录读写,限制其他路径访问。 + +[Install] +WantedBy=multi-user.target +# 服务在多用户模式下自动启动,配合 systemctl enable 使用。 \ No newline at end of file diff --git a/rustfs.run-zh.md b/rustfs.run-zh.md new file mode 100644 index 000000000..85def56e7 --- /dev/null +++ b/rustfs.run-zh.md @@ -0,0 +1,90 @@ +# RustFS 服务安装配置教程 + +## 1. 准备工作 + +### 1.1 创建系统用户 + +```bash +# 创建 rustfs 系统用户和用户组,禁止登录shell +sudo useradd -r -s /sbin/nologin rustfs +``` + +### 1.2 创建必要目录 + +```bash +# 创建程序目录 +sudo mkdir -p /opt/rustfs + +# 创建数据目录 +sudo mkdir -p /data/rustfs/{vol1,vol2} + +# 创建配置目录 +sudo mkdir -p /etc/rustfs + +# 设置目录权限 +sudo chown -R rustfs:rustfs /opt/rustfs /data/rustfs +sudo chmod 755 /opt/rustfs /data/rustfs +``` + +## 2. 安装 RustFS + +```bash +# 复制 RustFS 二进制文件 +sudo cp rustfs /usr/local/bin/ +sudo chmod +x /usr/local/bin/rustfs + +# 复制配置文件 +sudo cp obs.yaml /etc/rustfs/ +sudo chown -R rustfs:rustfs /etc/rustfs +``` + +## 3. 配置 Systemd 服务 + +```bash +# 复制服务单元文件 +sudo cp rustfs.service /etc/systemd/system/ + +# 重新加载 systemd 配置 +sudo systemctl daemon-reload +``` + +## 4. 服务管理 + +### 4.1 启动服务 + +```bash +sudo systemctl start rustfs +``` + +### 4.2 查看服务状态 + +```bash +sudo systemctl status rustfs +``` + +### 4.3 启用开机自启 + +```bash +sudo systemctl enable rustfs +``` + +### 4.4 查看服务日志 + +```bash +# 查看实时日志 +sudo journalctl -u rustfs -f + +# 查看今天的日志 +sudo journalctl -u rustfs --since today +``` + +## 5. 验证安装 + +```bash +# 检查服务端口 +ss -tunlp | grep 9000 +ss -tunlp | grep 9002 + +# 测试服务可用性 +curl -I http://localhost:9000 +``` diff --git a/rustfs.run.md b/rustfs.run.md new file mode 100644 index 000000000..2e26ea31a --- /dev/null +++ b/rustfs.run.md @@ -0,0 +1,90 @@ +# RustFS Service Installation Guide + +## 1. Prerequisites + +### 1.1 Create System User + +```bash +# Create rustfs system user and group without login shell +sudo useradd -r -s /sbin/nologin rustfs +``` + +### 1.2 Create Required Directories + +```bash +# Create program directory +sudo mkdir -p /opt/rustfs + +# Create data directories +sudo mkdir -p /data/rustfs/{vol1,vol2} + +# Create configuration directory +sudo mkdir -p /etc/rustfs + +# Set directory permissions +sudo chown -R rustfs:rustfs /opt/rustfs /data/rustfs +sudo chmod 755 /opt/rustfs /data/rustfs +``` + +## 2. Install RustFS + +```bash +# Copy RustFS binary +sudo cp rustfs /usr/local/bin/ +sudo chmod +x /usr/local/bin/rustfs + +# Copy configuration file +sudo cp obs.yaml /etc/rustfs/ +sudo chown -R rustfs:rustfs /etc/rustfs +``` + +## 3. Configure Systemd Service + +```bash +# Copy service unit file +sudo cp rustfs.service /etc/systemd/system/ + +# Reload systemd configuration +sudo systemctl daemon-reload +``` + +## 4. Service Management + +### 4.1 Start Service + +```bash +sudo systemctl start rustfs +``` + +### 4.2 Check Service Status + +```bash +sudo systemctl status rustfs +``` + +### 4.3 Enable Auto-start + +```bash +sudo systemctl enable rustfs +``` + +### 4.4 View Service Logs + +```bash +# View real-time logs +sudo journalctl -u rustfs -f + +# View today's logs +sudo journalctl -u rustfs --since today +``` + +## 5. Verify Installation + +```bash +# Check service ports +ss -tunlp | grep 9000 +ss -tunlp | grep 9002 + +# Test service availability +curl -I http://localhost:9000 +``` diff --git a/rustfs.service b/rustfs.service new file mode 100644 index 000000000..53db8a64a --- /dev/null +++ b/rustfs.service @@ -0,0 +1,60 @@ +[Unit] +Description=RustFS Object Storage Server +Documentation=https://rustfs.com/docs/ +After=network-online.target +Wants=network-online.target +# If you're using a database, you'll need to add the corresponding dependencies +# After=postgresql.service +# Requires=postgresql.service + +[Service] +Type=notify +NotifyAccess=main +User=rustfs +Group=rustfs + +# environment variable configuration +Environment=RUST_LOG=info +Environment=RUSTFS_ACCESS_KEY=rustfsadmin +Environment=RUSTFS_SECRET_KEY=rustfsadmin + +# working directory +WorkingDirectory=/opt/rustfs + +# main program +ExecStart=/usr/local/bin/rustfs \ + --address 0.0.0.0:9000 \ + --volumes /data/rustfs/vol1,/data/rustfs/vol2 \ + --obs-config /etc/rustfs/obs.yaml \ + --console-enable \ + --console-address 0.0.0.0:9002 + +# resource constraints +LimitNOFILE=1048576 +LimitNPROC=32768 +TasksMax=infinity + +# restart the policy +Restart=always +RestartSec=10s + +# graceful exit configuration +TimeoutStartSec=30s +TimeoutStopSec=30s + +# security settings +NoNewPrivileges=true +ProtectSystem=full +ProtectHome=true +PrivateTmp=true +PrivateDevices=true +ProtectClock=true +ProtectKernelTunables=true +ProtectKernelModules=true +ProtectControlGroups=true +RestrictSUIDSGID=true +RestrictRealtime=true +ReadWritePaths=/data/rustfs + +[Install] +WantedBy=multi-user.target \ No newline at end of file