Skip to content

Commit 1397ffb

Browse files
authored
Merge pull request #56 from BeeThor/patch-2
添加 Docker Compose 生产环境部署示例
2 parents fc9cf80 + 8d7b5c4 commit 1397ffb

File tree

1 file changed

+257
-0
lines changed

1 file changed

+257
-0
lines changed

docs/zh/installation/docker/index.md

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,263 @@ e07121ecdd39 rustfs/rustfs:latest "/entrypoint.sh
209209

210210
不管是单独启动 `rustfs-server` 还是和可观测性的服务一起启动,对于 RustFS 实例的访问都是通过 `http://localhost:9000`,并使用默认用户名和密码(均为 `rustfsadmin`)。
211211

212+
### 部署示例
213+
214+
本节提供一个基于宝塔面板环境的生产级部署示例,采用 **双端口 + 双域名** 方案,通过 Nginx 反向代理实现 S3 API 和控制台的分离访问,并配置 SSL 证书实现 HTTPS 加密通信。
215+
216+
#### 场景说明
217+
218+
- **部署环境**:宝塔面板 + Docker Compose
219+
- **架构方案**:单独部署 RustFS(不包含可观测性服务)
220+
- **访问方式**
221+
- S3 API 端:`https://s3.example.com` (端口 9000)
222+
- 控制台端:`https://console.example.com` (端口 9001)
223+
- **特性**:支持 HTTPS、CORS、健康检查
224+
225+
#### Docker Compose 配置
226+
227+
创建 `docker-compose.yml` 文件:
228+
229+
```yaml
230+
version: "3.8"
231+
232+
services:
233+
rustfs:
234+
image: rustfs/rustfs:latest
235+
container_name: rustfs-server
236+
security_opt:
237+
- "no-new-privileges:true"
238+
ports:
239+
- "9000:9000" # S3 API 对外端口
240+
- "9001:9001" # 控制台对外端口
241+
environment:
242+
# 数据卷(多个路径用逗号分隔)
243+
- RUSTFS_VOLUMES=/data/rustfs0
244+
# API 和控制台监听地址
245+
- RUSTFS_ADDRESS=0.0.0.0:9000
246+
- RUSTFS_CONSOLE_ADDRESS=0.0.0.0:9001
247+
- RUSTFS_CONSOLE_ENABLE=true
248+
# CORS 设置,控制台与 S3 API 都放开来源
249+
- RUSTFS_CORS_ALLOWED_ORIGINS=*
250+
- RUSTFS_CONSOLE_CORS_ALLOWED_ORIGINS=*
251+
# 访问密钥(生产环境请修改为强密码)
252+
- RUSTFS_ACCESS_KEY=rustfsadmin
253+
- RUSTFS_SECRET_KEY=rustfsadmin
254+
# 日志级别
255+
- RUSTFS_LOG_LEVEL=info
256+
257+
volumes:
258+
# 存储数据卷(请根据实际情况修改路径)
259+
- ./deploy/data/pro:/data
260+
# 日志目录
261+
- ./deploy/logs:/app/logs
262+
263+
networks:
264+
- rustfs-network
265+
restart: unless-stopped
266+
healthcheck:
267+
test: ["CMD", "sh", "-c", "curl -f http://localhost:9000/health && curl -f http://localhost:9001/health"]
268+
interval: 30s
269+
timeout: 10s
270+
retries: 3
271+
start_period: 40s
272+
273+
networks:
274+
rustfs-network:
275+
driver: bridge
276+
ipam:
277+
config:
278+
- subnet: 172.20.0.0/16
279+
```
280+
281+
启动服务:
282+
283+
```bash
284+
docker compose up -d
285+
```
286+
287+
#### Nginx 反向代理配置
288+
289+
##### S3 API 端配置
290+
291+
为 S3 API 创建 Nginx 配置文件(如 `/www/server/panel/vhost/nginx/s3.example.com.conf`):
292+
293+
```nginx
294+
# S3 API 负载均衡配置
295+
upstream rustfs {
296+
least_conn;
297+
server 127.0.0.1:9000; # S3 API 服务端口
298+
}
299+
300+
# HTTP 重定向到 HTTPS
301+
server {
302+
listen 80;
303+
listen [::]:80;
304+
server_name s3.example.com; # 替换为你的 S3 API 域名
305+
306+
return 301 https://$host$request_uri;
307+
}
308+
309+
# HTTPS 主配置
310+
server {
311+
listen 443 ssl;
312+
listen [::]:443 ssl;
313+
http2 on;
314+
server_name s3.example.com; # 替换为你的 S3 API 域名
315+
316+
# SSL 证书配置(请替换为实际证书路径)
317+
ssl_certificate /www/server/panel/vhost/cert/s3.example.com/fullchain.pem;
318+
ssl_certificate_key /www/server/panel/vhost/cert/s3.example.com/privkey.pem;
319+
ssl_protocols TLSv1.2 TLSv1.3;
320+
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
321+
ssl_prefer_server_ciphers on;
322+
ssl_session_cache shared:SSL:10m;
323+
ssl_session_timeout 10m;
324+
add_header Strict-Transport-Security "max-age=31536000";
325+
326+
# 反向代理 RustFS S3 API
327+
location / {
328+
proxy_set_header Host $host;
329+
proxy_set_header X-Real-IP $remote_addr;
330+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
331+
proxy_set_header X-Forwarded-Proto $scheme;
332+
proxy_set_header X-Forwarded-Port $server_port;
333+
proxy_set_header X-Forwarded-Host $host;
334+
335+
# 关键配置:禁用 HEAD 请求转换,避免 S3 V4 签名失效
336+
proxy_cache_convert_head off;
337+
proxy_connect_timeout 300;
338+
proxy_http_version 1.1;
339+
proxy_set_header Connection "";
340+
341+
proxy_pass http://rustfs; # 代理到 S3 API
342+
}
343+
344+
# 日志配置(请根据实际情况修改路径)
345+
access_log /www/wwwlogs/s3.example.com.log;
346+
error_log /www/wwwlogs/s3.example.com.error.log;
347+
}
348+
```
349+
350+
##### 控制台端配置
351+
352+
为控制台创建 Nginx 配置文件(如 `/www/server/panel/vhost/nginx/console.example.com.conf`):
353+
354+
```nginx
355+
# 控制台负载均衡配置
356+
upstream rustfs-console {
357+
least_conn;
358+
server 127.0.0.1:9001; # 控制台服务端口
359+
}
360+
361+
# HTTP 重定向到 HTTPS
362+
server {
363+
listen 80;
364+
listen [::]:80;
365+
server_name console.example.com; # 替换为你的控制台域名
366+
367+
return 301 https://$host$request_uri;
368+
}
369+
370+
# HTTPS 主配置
371+
server {
372+
listen 443 ssl;
373+
listen [::]:443 ssl;
374+
http2 on;
375+
server_name console.example.com; # 替换为你的控制台域名
376+
377+
# SSL 证书配置(请替换为实际证书路径)
378+
ssl_certificate /www/server/panel/vhost/cert/console.example.com/fullchain.pem;
379+
ssl_certificate_key /www/server/panel/vhost/cert/console.example.com/privkey.pem;
380+
ssl_protocols TLSv1.2 TLSv1.3;
381+
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
382+
ssl_prefer_server_ciphers on;
383+
ssl_session_cache shared:SSL:10m;
384+
ssl_session_timeout 10m;
385+
add_header Strict-Transport-Security "max-age=31536000";
386+
387+
# 反向代理 RustFS 控制台
388+
location / {
389+
proxy_set_header Host $host;
390+
proxy_set_header X-Real-IP $remote_addr;
391+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
392+
proxy_set_header X-Forwarded-Proto $scheme;
393+
proxy_set_header X-Forwarded-Port $server_port;
394+
proxy_set_header X-Forwarded-Host $host;
395+
396+
# 禁用 HEAD 请求转换
397+
proxy_cache_convert_head off;
398+
proxy_connect_timeout 300;
399+
proxy_http_version 1.1;
400+
proxy_set_header Connection "";
401+
402+
proxy_pass http://rustfs-console; # 代理到控制台
403+
}
404+
405+
# 日志配置(请根据实际情况修改路径)
406+
access_log /www/wwwlogs/console.example.com.log;
407+
error_log /www/wwwlogs/console.example.com.error.log;
408+
}
409+
```
410+
411+
重载 Nginx 配置:
412+
413+
```bash
414+
nginx -t && nginx -s reload
415+
```
416+
417+
#### 重要说明
418+
419+
> [!WARNING]
420+
> **关键配置项**
421+
>
422+
> 在 Nginx 配置中**必须添加** `proxy_cache_convert_head off` 指令,原因如下:
423+
>
424+
> - Nginx 默认会将 HEAD 请求转换为 GET 请求以便缓存
425+
> - 这种转换会导致 S3 V4 签名验证失败
426+
> - 症状表现为访问存储桶时报错 `Bucket not found``403 AccessDenied`
427+
>
428+
> 参考 [Nginx 官方文档](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_convert_head)
429+
430+
#### 访问验证
431+
432+
配置完成后,通过以下方式验证部署:
433+
434+
1. **访问控制台**
435+
```
436+
https://console.example.com
437+
```
438+
使用账号密码登录(默认均为 `rustfsadmin`
439+
440+
2. **测试 S3 API**
441+
```bash
442+
# 使用 mc 客户端
443+
mc alias set myrustfs https://s3.example.com rustfsadmin rustfsadmin
444+
mc mb myrustfs/test-bucket
445+
mc ls myrustfs
446+
```
447+
448+
3. **检查服务状态**
449+
```bash
450+
# 查看容器状态
451+
docker ps
452+
453+
# 查看服务日志
454+
docker logs rustfs-server
455+
456+
# 检查健康状态
457+
curl http://localhost:9000/health
458+
curl http://localhost:9001/health
459+
```
460+
461+
#### 安全建议
462+
463+
1. **修改默认密钥**:生产环境务必修改 `RUSTFS_ACCESS_KEY``RUSTFS_SECRET_KEY` 为强密码
464+
2. **限制 CORS**:将 `RUSTFS_CORS_ALLOWED_ORIGINS``*` 改为具体域名
465+
3. **防火墙配置**:确保 9000 和 9001 端口仅允许 Nginx 服务器访问
466+
4. **SSL 证书**:建议使用 Let's Encrypt 自动续期证书
467+
5. **定期备份**:配置数据卷的定期备份策略
468+
212469
## 四、验证与访问
213470

214471
1. **查看容器状态与日志:**

0 commit comments

Comments
 (0)