RustFS 非 Docker 部署完整指南:从单机到生产集群
- [RustFS 非 Docker 部署完整指南:从单机到生产集群](#RustFS 非 Docker 部署完整指南:从单机到生产集群)
-
- [一、非 Docker 部署的优势与适用场景](#一、非 Docker 部署的优势与适用场景)
- 二、环境准备与系统要求
- 三、二进制安装:两种推荐方式
- 四、单节点配置与启动
- [五、Systemd 服务配置(生产环境必备)](#五、Systemd 服务配置(生产环境必备))
- 六、多节点集群部署(4节点生产示例)
-
- 集群架构规划
- 步骤1:在所有节点准备存储
- 步骤2:配置集群启动脚本
- [步骤3:配置集群版 systemd 服务](#步骤3:配置集群版 systemd 服务)
- 步骤4:启动集群并验证
- 七、生产环境高级配置
-
- [1. TLS/SSL 配置](#1. TLS/SSL 配置)
- [2. 纠删码配置](#2. 纠删码配置)
- [3. 监控与日志](#3. 监控与日志)
- 八、验证与测试
- 九、故障排查与维护
- [十、总结:非 Docker 部署的关键要点](#十、总结:非 Docker 部署的关键要点)
- 关联文章
RustFS 非 Docker 部署完整指南:从单机到生产集群
作为资深开发工程师,选择非 Docker 部署 RustFS 能获得更直接的资源控制、更低的性能开销和更灵活的运维能力。以下是基于 Linux 环境的完整部署方案。
一、非 Docker 部署的优势与适用场景
| 优势 | 说明 | 适用场景 |
|---|---|---|
| 性能最优 | 直接运行二进制,无容器层开销,I/O 路径最短 | 高性能要求的生产环境 |
| 资源控制精细 | 直接管理进程、文件描述符、内存映射 | 资源敏感的边缘计算 |
| 故障排查直接 | 无容器网络、存储卷抽象层,问题定位更直接 | 需要深度调试的系统 |
| 部署灵活 | 可集成到现有 init 系统(systemd/sysvinit) | 传统服务器环境、混合云 |
| 安全可控 | 无需容器运行时,攻击面更小 | 高安全要求的金融、政务场景 |
二、环境准备与系统要求
硬件与操作系统
bash
# 1. 操作系统要求(64位)
# - Linux 内核 5.4+(推荐 5.10+ 以支持完整 io_uring 特性)
# - 支持发行版:Ubuntu 20.04+/22.04+、CentOS 8+/Stream、RHEL 8+、openEuler 22.03+
# 2. 检查内核版本
uname -r # 应显示 5.4 或更高
# 3. 硬件建议(生产环境)
# - CPU:4核+(推荐 8核+)
# - 内存:8GB+(推荐 16GB+,大数据场景 64GB+)
# - 磁盘:XFS 文件系统,SSD/NVMe 优先
# - 网络:千兆+(集群部署推荐万兆)
系统优化配置
bash
# 1. 内核参数优化(/etc/sysctl.conf)
cat >> /etc/sysctl.conf << EOF
# 网络优化
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_slow_start_after_idle = 0
# 文件系统优化
fs.file-max = 2097152
vm.swappiness = 10
EOF
sysctl -p
# 2. 禁用干扰服务(避免 I/O 冲突)
systemctl stop mlocate updatedb auditd 2>/dev/null || true
systemctl disable mlocate updatedb auditd 2>/dev/null || true
# 3. 设置文件描述符限制(/etc/security/limits.conf)
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 65536" >> /etc/security/limits.conf
三、二进制安装:两种推荐方式
方式一:官方安装脚本(推荐新手/快速部署)
bash
# 1. 下载并执行安装脚本
curl -O https://rustfs.com/install_rustfs.sh
chmod +x install_rustfs.sh
# 2. 交互式安装(会提示配置端口、数据目录等)
sudo ./install_rustfs.sh
# 脚本会自动:
# - 检测系统架构并下载对应二进制
# - 询问服务端口(默认9000)
# - 询问数据存储目录(默认/var/lib/rustfs)
# - 设置管理员账号密码
# - 配置 systemd 服务
# 3. 验证安装
rustfs --version
# 输出示例:rustfs 1.0.0-alpha.87
方式二:手动二进制部署(推荐生产环境)
bash
# 1. 创建专用目录结构
sudo mkdir -p /opt/rustfs/{bin,data,logs,config}
sudo chown -R $USER:$USER /opt/rustfs
# 2. 下载最新二进制(以 x86_64 Linux 为例)
cd /opt/rustfs/bin
# 方法A:从 GitHub Releases 下载
wget https://github.com/rustfs/rustfs/releases/latest/download/rustfs-linux-x86_64-musl-latest.zip
unzip rustfs-linux-x86_64-musl-latest.zip
chmod +x rustfs
# 方法B:使用官方下载器
curl --progress-bar -O https://dl.rustfs.com/artifacts/rustfs/release/rustfs-linux-x86_64-latest.zip
unzip rustfs-linux-x86_64-latest.zip
chmod +x rustfs
# 3. 创建软链接到系统 PATH
sudo ln -sf /opt/rustfs/bin/rustfs /usr/local/bin/rustfs
# 4. 验证版本
rustfs --version
四、单节点配置与启动
基础启动(开发测试)
bash
# 1. 创建数据目录
mkdir -p /opt/rustfs/data
# 2. 前台启动(Ctrl+C 停止)
rustfs server \
--address :9000 \
--console-address :9001 \
--access-key admin \
--secret-key YourStrongPassword123! \
/opt/rustfs/data
# 3. 访问验证
# - API端点:http://localhost:9000
# - 控制台:http://localhost:9001
# - 使用上面设置的 access-key/secret-key 登录
生产环境后台启动
bash
# 1. 创建启动脚本 /opt/rustfs/start.sh
cat > /opt/rustfs/start.sh << 'EOF'
#!/bin/bash
export RUSTFS_ACCESS_KEY="admin"
export RUSTFS_SECRET_KEY="YourStrongPassword123!"
export RUSTFS_ADDRESS=":9000"
export RUSTFS_CONSOLE_ADDRESS=":9001"
export RUSTFS_DATA_DIR="/opt/rustfs/data"
exec /opt/rustfs/bin/rustfs server \
--address "$RUSTFS_ADDRESS" \
--console-address "$RUSTFS_CONSOLE_ADDRESS" \
--access-key "$RUSTFS_ACCESS_KEY" \
--secret-key "$RUSTFS_SECRET_KEY" \
"$RUSTFS_DATA_DIR"
EOF
chmod +x /opt/rustfs/start.sh
# 2. 使用 nohup 后台运行
nohup /opt/rustfs/start.sh > /opt/rustfs/logs/rustfs.log 2>&1 &
# 3. 检查进程
ps aux | grep rustfs
netstat -tlnp | grep 9000
五、Systemd 服务配置(生产环境必备)
bash
# 1. 创建 systemd 服务文件
sudo tee /etc/systemd/system/rustfs.service << 'EOF'
[Unit]
Description=RustFS High Performance Object Storage
Documentation=https://docs.rustfs.com.cn
After=network.target
Requires=network.target
[Service]
Type=simple
User=rustfs
Group=rustfs
Environment="RUSTFS_ACCESS_KEY=admin"
Environment="RUSTFS_SECRET_KEY=YourStrongPassword123!"
Environment="RUSTFS_ADDRESS=:9000"
Environment="RUSTFS_CONSOLE_ADDRESS=:9001"
# 重要:设置正确的数据目录
ExecStart=/opt/rustfs/bin/rustfs server \
--address ${RUSTFS_ADDRESS} \
--console-address ${RUSTFS_CONSOLE_ADDRESS} \
--access-key ${RUSTFS_ACCESS_KEY} \
--secret-key ${RUSTFS_SECRET_KEY} \
/opt/rustfs/data
# 安全限制
NoNewPrivileges=yes
LimitNOFILE=65536
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
# 重启策略
Restart=on-failure
RestartSec=5
TimeoutStopSec=30
# 日志配置
StandardOutput=journal
StandardError=journal
SyslogIdentifier=rustfs
[Install]
WantedBy=multi-user.target
EOF
# 2. 创建专用系统用户
sudo useradd -r -s /bin/false -M rustfs
sudo chown -R rustfs:rustfs /opt/rustfs
# 3. 重载 systemd 并启动服务
sudo systemctl daemon-reload
sudo systemctl enable rustfs
sudo systemctl start rustfs
# 4. 检查服务状态
sudo systemctl status rustfs
sudo journalctl -u rustfs -f # 查看实时日志
六、多节点集群部署(4节点生产示例)
集群架构规划
节点1 (node1): 192.168.1.101
节点2 (node2): 192.168.1.102
节点3 (node3): 192.168.1.103
节点4 (node4): 192.168.1.104
每个节点:
- 4块数据盘:/data/disk1, /data/disk2, /data/disk3, /data/disk4
- 服务端口:9000 (API), 9001 (Console)
- 内部通信端口:9000 (默认复用)
步骤1:在所有节点准备存储
bash
# 在每个节点执行
sudo mkdir -p /data/disk{1..4}
sudo chown -R rustfs:rustfs /data/disk*
# 格式化磁盘为 XFS(如果是新盘)
for i in {1..4}; do
sudo mkfs.xfs -f /dev/sd$((98+i)) # 假设磁盘为 /dev/sdb, /dev/sdc...
echo "/dev/sd$((98+i)) /data/disk$i xfs defaults,noatime 0 0" | sudo tee -a /etc/fstab
done
sudo mount -a
步骤2:配置集群启动脚本
在每个节点创建 /opt/rustfs/start-cluster.sh,注意修改 NODE_IP 和 PEERS:
bash
#!/bin/bash
# 节点1的配置(192.168.1.101)
NODE_IP="192.168.1.101"
NODE_NAME="rustfs-node1"
PEERS="rustfs-node1:9000,rustfs-node2:9000,rustfs-node3:9000,rustfs-node4:9000"
export RUSTFS_ACCESS_KEY="admin"
export RUSTFS_SECRET_KEY="YourStrongPassword123!"
export RUSTFS_ADDRESS=":9000"
export RUSTFS_CONSOLE_ADDRESS=":9001"
export RUSTFS_SERVER_URL="http://${NODE_IP}:9000"
export RUSTFS_PEERS="${PEERS}"
exec /opt/rustfs/bin/rustfs server \
--address "${RUSTFS_ADDRESS}" \
--console-address "${RUSTFS_CONSOLE_ADDRESS}" \
--access-key "${RUSTFS_ACCESS_KEY}" \
--secret-key "${RUSTFS_SECRET_KEY}" \
/data/disk{1...4}
步骤3:配置集群版 systemd 服务
bash
sudo tee /etc/systemd/system/rustfs-cluster.service << EOF
[Unit]
Description=RustFS Cluster Node
After=network.target
Wants=network.target
[Service]
Type=simple
User=rustfs
Group=rustfs
EnvironmentFile=/opt/rustfs/cluster.env # 环境变量文件
ExecStart=/opt/rustfs/bin/rustfs server \
--address \${RUSTFS_ADDRESS} \
--console-address \${RUSTFS_CONSOLE_ADDRESS} \
--access-key \${RUSTFS_ACCESS_KEY} \
--secret-key \${RUSTFS_SECRET_KEY} \
/data/disk{1...4}
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
# 创建环境变量文件 /opt/rustfs/cluster.env(节点1示例)
cat > /opt/rustfs/cluster.env << EOF
RUSTFS_ACCESS_KEY=admin
RUSTFS_SECRET_KEY=YourStrongPassword123!
RUSTFS_ADDRESS=:9000
RUSTFS_CONSOLE_ADDRESS=:9001
RUSTFS_SERVER_URL=http://192.168.1.101:9000
RUSTFS_PEERS=rustfs-node1:9000,rustfs-node2:9000,rustfs-node3:9000,rustfs-node4:9000
EOF
sudo chown rustfs:rustfs /opt/rustfs/cluster.env
sudo chmod 600 /opt/rustfs/cluster.env
步骤4:启动集群并验证
bash
# 在所有节点启动服务
sudo systemctl daemon-reload
sudo systemctl enable rustfs-cluster
sudo systemctl start rustfs-cluster
# 检查集群状态
curl http://192.168.1.101:9000/minio/health/cluster
# 预期输出:{"status":"ok"}
# 通过任一节点的控制台查看集群状态
# 访问 http://192.168.1.101:9001 → 仪表板应显示4个节点 Online
七、生产环境高级配置
1. TLS/SSL 配置
bash
# 启动时添加 TLS 参数
rustfs server \
--address :9000 \
--console-address :9001 \
--certs-dir /etc/ssl/rustfs \
--access-key admin \
--secret-key YourStrongPassword123! \
/data/disk{1...4}
# 证书目录结构
/etc/ssl/rustfs/
├── private.key # 私钥
├── public.crt # 证书
└── ca.crt # CA证书(可选)
2. 纠删码配置
bash
# 通过环境变量设置纠删码集大小
export RUSTFS_ERASURE_SET_SIZE="4:2" # 4个数据块,2个校验块
# 或启动时指定
rustfs server \
--erasure-set "4:2" \
# ...其他参数
3. 监控与日志
bash
# 1. 启用详细日志
export RUSTFS_LOG_LEVEL="debug" # 可选:error, warn, info, debug
# 2. Prometheus 监控端点(默认启用)
# 访问 http://node-ip:9000/minio/prometheus/metrics
# 3. 日志轮转配置(logrotate)
sudo tee /etc/logrotate.d/rustfs << EOF
/opt/rustfs/logs/*.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
create 644 rustfs rustfs
postrotate
systemctl reload rustfs-cluster > /dev/null 2>&1 || true
endscript
}
EOF
八、验证与测试
功能验证脚本
bash
#!/bin/bash
# test_rustfs.sh
API_ENDPOINT="http://localhost:9000"
ACCESS_KEY="admin"
SECRET_KEY="YourStrongPassword123!"
BUCKET="test-bucket-$(date +%s)"
# 1. 创建桶
aws --endpoint-url=$API_ENDPOINT s3 mb s3://$BUCKET \
--profile rustfs
# 2. 上传测试文件
echo "RustFS test content" > test.txt
aws --endpoint-url=$API_ENDPOINT s3 cp test.txt s3://$BUCKET/ \
--profile rustfs
# 3. 列出对象
aws --endpoint-url=$API_ENDPOINT s3 ls s3://$BUCKET/ \
--profile rustfs
# 4. 下载验证
aws --endpoint-url=$API_ENDPOINT s3 cp s3://$BUCKET/test.txt downloaded.txt \
--profile rustfs
diff test.txt downloaded.txt && echo "✓ 数据一致性验证通过"
# 5. 清理
aws --endpoint-url=$API_ENDPOINT s3 rb s3://$BUCKET --force \
--profile rustfs
rm -f test.txt downloaded.txt
# 配置 AWS CLI profile
cat > ~/.aws/config << EOF
[profile rustfs]
aws_access_key_id = $ACCESS_KEY
aws_secret_access_key = $SECRET_KEY
region = us-east-1
EOF
性能基准测试
bash
# 使用 warp 进行 S3 基准测试
docker run --rm -it \
--network host \
minio/warp \
mixed --host=localhost:9000 \
--access-key=admin \
--secret-key=YourStrongPassword123! \
--duration=1m \
--obj.size=1MiB \
--concurrent=16
九、故障排查与维护
常见问题解决
-
服务无法启动
bash# 检查端口占用 sudo lsof -i :9000 # 检查权限 sudo -u rustfs ls -la /data/disk1 # 查看详细日志 sudo journalctl -u rustfs-cluster -n 50 --no-pager -
节点无法加入集群
bash# 检查网络连通性 ping rustfs-node2 nc -zv rustfs-node2 9000 # 检查防火墙 sudo firewall-cmd --list-all # CentOS/RHEL sudo ufw status verbose # Ubuntu -
磁盘空间不足
bash# 设置磁盘配额 sudo xfs_quota -x -c 'limit bsoft=100g bhard=110g rustfs' /data/disk1 # 监控磁盘使用 df -h /data/disk*
日常维护命令
bash
# 1. 查看集群健康状态
rustfs admin info
# 2. 查看节点拓扑
rustfs admin topology
# 3. 服务启停
sudo systemctl stop rustfs-cluster
sudo systemctl start rustfs-cluster
sudo systemctl restart rustfs-cluster
# 4. 版本升级
# 备份配置 → 下载新二进制 → 替换 → 重启服务
sudo systemctl stop rustfs-cluster
cp /opt/rustfs/bin/rustfs /opt/rustfs/bin/rustfs.backup.$(date +%Y%m%d)
wget -O /opt/rustfs/bin/rustfs.new <新版本URL>
mv /opt/rustfs/bin/rustfs.new /opt/rustfs/bin/rustfs
chmod +x /opt/rustfs/bin/rustfs
sudo systemctl start rustfs-cluster
十、总结:非 Docker 部署的关键要点
- 性能优先:直接二进制部署避免了容器层的性能开销,特别适合高 I/O 场景。
- 系统集成:通过 systemd 集成,获得完整的服务管理能力(监控、日志、自启)。
- 资源控制:直接管理进程资源,便于精细化调优。
- 安全加固:专用系统用户、文件权限控制、TLS 加密缺一不可。
- 集群可靠:多节点部署时,确保网络低延迟、时钟同步(NTP)、存储冗余。