服务端
部署
将 Free FS 服务端部署到生产环境。
1. JAR 包部署
在服务器上,确保已安装 JDK 21+。
nohup java -jar fs-admin.jar --spring.profiles.active=prod > logs.txt 2>&1 &2. Docker 部署
项目内置了 Docker 支持,镜像已预装 LibreOffice,可直接用于文件预览,无需额外安装。
第一步:修改 Docker 专属配置
在构建镜像 之前,需要先修改服务端的 application-docker.yml 配置文件,将其中的数据库、Redis、存储路径等改为你实际的地址和密码。
配置文件路径:fs-admin/src/main/resources/application-docker.yml
以下是完整配置示例及各项说明:
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
# MySQL 数据库配置
url: jdbc:mysql://<your-mysql-host>:3306/free-fs?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
# PostgreSQL 数据库配置(二选一,启用时注释掉 MySQL 部分)
# url: jdbc:postgresql://<your-pg-host>:5432/free-fs?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true
# username: postgres
# password: postgres
# driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: 20
minimum-idle: 10
connectionTimeout: 30000
validationTimeout: 5000
idleTimeout: 600000
maxLifetime: 1800000
connectionTestQuery: SELECT 1
keepaliveTime: 30000
data:
redis:
host: <your-redis-host>
port: 6379
password: <your-redis-password>
database: 0
timeout: 10s
lettuce:
pool:
max-active: 200
max-wait: -1ms
max-idle: 10
min-idle: 0
cache:
type: redis
redis:
time-to-live: 3600000
cache-null-values: true
fs:
share:
# 前端访问地址,用于生成分享链接
domain: ${FS_SHARE_DOMAIN:http://<your-host>:5173}
preview:
# 本服务的文件流预览地址
stream-api: http://<your-host>:8080/api/file/stream/preview
max-file-size: 524288000
max-range-size: 10485760
small-file-size: 10485760
buffer-size: 8192
office:
enabled: true
# 镜像已内置 LibreOffice,此路径无需修改
office-home: /usr/lib/libreoffice
pool-size: 2
task-execution-timeout: 120000
task-queue-timeout: 30000
max-tasks-per-process: 200
cache-path: ${java.io.tmpdir}/office-convert
storage:
local:
# 容器内的文件存储路径,建议挂载到宿主机目录
base-path: /data/upload
# 文件访问地址(供外部访问)
base-url: http://<your-host>:8080/files
mybatis-flex:
audit_enable: true
sql_print: true注意事项:
office-home: /usr/lib/libreoffice不需要修改,Docker 镜像已内置 LibreOffice。base-path: /data/upload是容器内路径,建议通过-v挂载到宿主机,防止容器删除后数据丢失。domain和stream-api、base-url中的<your-host>替换为服务器实际 IP 或域名。
第二步:构建镜像
在项目 根目录 下执行以下命令:
docker build -t free-fs:latest -f docker/Dockerfile .构建时间视机器配置及网络情况而定,LibreOffice 较大,首次构建可能需要几分钟。
第三步:运行容器
建议使用支持 JDK 21 的基础镜像(如 ubuntu:24.04 或 debian:12 自行安装 JRE)。启动时需在 JVM 参数中添加 --enable-native-access=ALL-UNNAMED 以兼容部分底层库调用:
docker run -d --name free-fs -p 8080:8080 -e JAVA_TOOL_OPTIONS="--enable-native-access=ALL-UNNAMED" free-fs:latest常用容器命令
# 查看容器日志
docker logs -f free-fs
# 停止容器
docker stop free-fs
# 重启容器
docker restart free-fs
# 删除容器
docker rm -f free-fs3. Nginx 反向代理(推荐)
建议使用 Nginx 对服务进行反向代理并开启 Gzip 压缩:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# SSE 长连接支持
proxy_buffering off;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
}SSE 注意:Free FS 使用 SSE 推送上传进度,Nginx 需关闭缓冲(
proxy_buffering off)并适当延长超时时间,否则进度消息会卡顿或丢失。