improve systemd relation config

This commit is contained in:
houseme
2025-04-10 18:57:48 +08:00
parent f5a97b63b9
commit 6a4fffaae7
15 changed files with 170 additions and 18 deletions

35
deploy/README.md Normal file
View File

@@ -0,0 +1,35 @@
# RustFS Deploy
This directory contains the deployment scripts and configurations for the project.
The deployment process is divided into two main parts: the RustFS binary and the RustFS console. The RustFS binary is
responsible for the core functionality of the system, while the RustFS console provides a web-based interface for
managing and monitoring the system.
# Directory Structure
```text
|--data // data directory
| |--vol1 // volume 1 not created
| |--vol2 // volume 2 not created
| |--vol3 // volume 3 not created
| |--vol4 // volume 4 not created
| |--README.md // data directory readme
|--logs // log directory
| |--rustfs.log // RustFS log
| |--README.md // logs directory readme
|--build
| |--rustfs.run.md // deployment script for RustFS
| |--rustfs.run-zh.md // deployment script for RustFS in Chinese
| |--rustfs.service // systemd service file
| |--rustfs-zh.service.md // systemd service file in Chinese
|--certs
| |--README.md // certs readme
| |--rustfs_tls_cert.pem // API cert.pem
| |--rustfs_tls_key.pem // API key.pem
| |--rustfs_console_tls_cert.pem // console cert.pem
| |--rustfs_console_tls_key.pem // console key.pem
|--config
| |--obs.example.yaml // example config
| |--rustfs.env // env config
| |--rustfs-zh.env // env config in Chinese
```

View File

@@ -0,0 +1,101 @@
[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 配合使用。
# working directory
WorkingDirectory=/opt/rustfs
# 设置服务的工作目录为 /opt/rustfs影响相对路径的解析。
# 定义环境变量配置,用于传递给服务程序。
Environment=RUSTFS_ACCESS_KEY=rustfsadmin
# 设置访问密钥为 rustfsadmin用于 RustFS 的认证。
Environment=RUSTFS_SECRET_KEY=rustfsadmin
# 设置秘密密钥为 rustfsadmin与访问密钥配套使用。
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 端口。
# 定义环境变量配置,用于传递给服务程序,推荐使用且简洁
EnvironmentFile=-/etc/default/rustfs
ExecStart=/usr/local/bin/rustfs $RUSTFS_VOLUMES $RUSTFS_OPTS
# 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 使用。

View File

@@ -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
```

View File

@@ -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
```

View File

@@ -0,0 +1,61 @@
[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
# working directory
WorkingDirectory=/opt/rustfs
# environment variable configuration and main program (Option 1: Directly specify arguments)
Environment=RUSTFS_ACCESS_KEY=rustfsadmin
Environment=RUSTFS_SECRET_KEY=rustfsadmin
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
# environment variable configuration (Option 2: Use environment variables)
EnvironmentFile=-/etc/default/rustfs
ExecStart=/usr/local/bin/rustfs $RUSTFS_VOLUMES $RUSTFS_OPTS
# 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

44
deploy/certs/README.md Normal file
View File

@@ -0,0 +1,44 @@
## Certs
### Generate a self-signed certificate
```bash
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
```
### Generate a self-signed certificate with a specific subject
```bash
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/C=US/ST=California/L=San Francisco/O=My Company/CN=mydomain.com"
```
### Generate a self-signed certificate with a specific subject and SAN
```bash
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/C=US/ST=California/L=San Francisco/O=My Company/CN=mydomain.com" \
-addext "subjectAltName=DNS:mydomain.com,DNS:www.mydomain.com"
```
### Generate a self-signed certificate with a specific subject and SAN (multiple SANs)
```bash
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/C=US/ST=California/L=San Francisco/O=My Company/CN=mydomain.com" \
-addext "subjectAltName=DNS:mydomain.com,DNS:www.mydomain.com,DNS:api.mydomain.com"
```
### TLS File
```text
rustfs_tls_cert.pem api cert.pem
rustfs_tls_key.pem api key.pem
rustfs_console_tls_cert.pem console cert.pem
rustfs_console_tls_key.pem console key.pem
```

View File

@@ -0,0 +1,33 @@
[observability]
endpoint = "http://localhost:4317" # 可观测性数据上报的终端地址,默认为"http://localhost:4317"
use_stdout = true # 是否将日志输出到标准输出
sample_ratio = 2.0 # 采样率,表示每 2 条数据采样 1 条
meter_interval = 30 # 指标收集间隔,单位为秒
service_name = "rustfs" # 服务名称,用于标识当前服务
service_version = "0.1.0" # 服务版本号
environments = "develop" # 运行环境,如开发环境 (develop)
logger_level = "debug" # 日志级别,可选 debug/info/warn/error 等
[sinks]
[sinks.kafka] # Kafka 接收器配置
enabled = false # 是否启用 Kafka 接收器,默认禁用
bootstrap_servers = "localhost:9092" # Kafka 服务器地址
topic = "logs" # Kafka 主题名称
batch_size = 100 # 批处理大小,每次发送的消息数量
batch_timeout_ms = 1000 # 批处理超时时间,单位为毫秒
[sinks.webhook] # Webhook 接收器配置
enabled = false # 是否启用 Webhook 接收器
endpoint = "http://localhost:8080/webhook" # Webhook 接收地址
auth_token = "" # 认证令牌
batch_size = 100 # 批处理大小
batch_timeout_ms = 1000 # 批处理超时时间,单位为毫秒
[sinks.file] # 文件接收器配置
enabled = true # 是否启用文件接收器
path = "/Users/qun/Documents/rust/rustfs/s3-rustfs/logs/app.log" # 日志文件路径
batch_size = 10 # 批处理大小
batch_timeout_ms = 1000 # 批处理超时时间,单位为毫秒
[logger] # 日志器配置
queue_capacity = 10 # 日志队列容量,表示可以缓存的日志条数

View File

@@ -0,0 +1,33 @@
[observability]
endpoint = "http://localhost:4317" # Default is "http://localhost:4317" if not specified
use_stdout = false # Output with stdout, true output, false no output
sample_ratio = 2.0
meter_interval = 30
service_name = "rustfs"
service_version = "0.1.0"
environment = "develop"
looger_level = "info"
[sinks]
[sinks.kafka] # Kafka sink is disabled by default
enabled = false
bootstrap_servers = "localhost:9092"
topic = "logs"
batch_size = 100 # Default is 100 if not specified
batch_timeout_ms = 1000 # Default is 1000ms if not specified
[sinks.webhook]
enabled = false
endpoint = "http://localhost:8080/webhook"
auth_token = ""
batch_size = 100 # Default is 3 if not specified
batch_timeout_ms = 1000 # Default is 100ms if not specified
[sinks.file]
enabled = true
path = "logs/app.log"
batch_size = 100
batch_timeout_ms = 1000 # Default is 8192 bytes if not specified
[logger]
queue_capacity = 10000

View File

@@ -0,0 +1,26 @@
# RustFS 管理员用户名
RUSTFS_ROOT_USER=rustfsadmin
# RustFS 管理员密码
RUSTFS_ROOT_PASSWORD=rustfsadmin
# 数据卷配置示例路径deploy/data/rustfs.env
# RustFS 数据卷存储路径支持多卷配置vol1 到 vol4
RUSTFS_VOLUMES="./deploy/deploy/vol{1...4}"
# RustFS 服务启动参数,指定监听地址和端口
RUSTFS_OPTS="--address 0.0.0.0:9000"
# RustFS 服务监听地址和端口
RUSTFS_ADDRESS="0.0.0.0:9000"
# 是否启用 RustFS 控制台功能
RUSTFS_CONSOLE_ENABLE=true
# RustFS 控制台监听地址和端口
RUSTFS_CONSOLE_ADDRESS="0.0.0.0:9002"
# RustFS 服务端点地址,用于客户端访问
RUSTFS_SERVER_ENDPOINT="http://127.0.0.1:9000"
# RustFS 服务域名配置
RUSTFS_SERVER_DOMAINS=127.0.0.1:9002
# RustFS 许可证内容
RUSTFS_LICENSE="license content"
# 可观测性配置文件路径deploy/config/obs.example.toml
RUSTFS_OBS_CONFIG=/etc/default/obs.toml
# TLS 证书目录路径deploy/certs
RUSTFS_TLS_PATH=/etc/default/tls

26
deploy/config/rustfs.env Normal file
View File

@@ -0,0 +1,26 @@
# RustFS administrator username
RUSTFS_ROOT_USER=rustfsadmin
# RustFS administrator password
RUSTFS_ROOT_PASSWORD=rustfsadmin
# Data volume configuration example path: deploy/data/rustfs.env
# RustFS data volume storage paths, supports multiple volumes from vol1 to vol4
RUSTFS_VOLUMES="./deploy/deploy/vol{1...4}"
# RustFS service startup parameters, specifying listen address and port
RUSTFS_OPTS="--address 0.0.0.0:9000"
# RustFS service listen address and port
RUSTFS_ADDRESS="0.0.0.0:9000"
# Enable RustFS console functionality
RUSTFS_CONSOLE_ENABLE=true
# RustFS console listen address and port
RUSTFS_CONSOLE_ADDRESS="0.0.0.0:9002"
# RustFS service endpoint for client access
RUSTFS_SERVER_ENDPOINT="http://127.0.0.1:9000"
# RustFS service domain configuration
RUSTFS_SERVER_DOMAINS=127.0.0.1:9002
# RustFS license content
RUSTFS_LICENSE="license content"
# Observability configuration file path: deploy/config/obs.example.toml
RUSTFS_OBS_CONFIG=/etc/default/obs.toml
# TLS certificates directory path: deploy/certs
RUSTFS_TLS_PATH=/etc/default/tls

1
deploy/data/README.md Normal file
View File

@@ -0,0 +1 @@
# Data Volumes

1
deploy/logs/README.md Normal file
View File

@@ -0,0 +1 @@
# RustFS Logs