I. 安装配置

1.1 获取 Cloudreve

GitHub Release 页面获取已经构建打包完成的主程序。

1.2 启动 Cloudreve

 1# 创建程序安装目录
 2mkdir /path/to/directory
 3# 解压主程序到安装目录
 4tar -zxvf cloudreve_VERSION_OS_ARCH.tar.gz -C /path/to/directory
 5# 切换到解压目录
 6cd /path/to/directory
 7# 赋予执行权限
 8chmod +x ./cloudreve
 9# 启动 Cloudreve
10./cloudreve

📢 注意:请记录输出日志中的系统默认用户名密码,以在后续使用。

1.3 反向代理配置

在 Nginx 的 server 字段中加入:

1location / {
2    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
3    proxy_set_header Host $http_host;
4    proxy_redirect off;
5    proxy_pass http://127.0.0.1:5212;
6
7    # 如果您要使用本地存储策略,请将下一行注释符删除,并更改大小为理论最大文件尺寸
8    client_max_body_size 20000m;
9}

1.4 域名解析

参考示例:域名解析-腾讯云

II. 进阶配置(可选)

2.1 配置文件

首次启动时,Cloudreve 会在同级目录下创建名为 conf.ini 的配置文件,你可以修改此文件进行一些参数的配置,保存后需要重新启动 Cloudreve 生效。

一个完整的配置文件示例如下:

 1[System]
 2; 运行模式
 3Mode = master
 4; 监听端口
 5Listen = :5212
 6; 是否开启 Debug
 7Debug = false
 8; Session 密钥, 一般在首次启动时自动生成
 9SessionSecret = 23333
10; Hash 加盐, 一般在首次启动时自动生成
11HashIDSalt = something really hard to guss
12; 呈递客户端 IP 时使用的 Header
13ProxyHeader = X-Forwarded-For
14
15; SSL 相关
16[SSL]
17; SSL 监听端口
18Listen = :443
19; 证书路径
20CertPath = /path/to/fullchain.pem
21; 私钥路径
22KeyPath = /path/to/privkey.pem
23
24; 启用 Unix Socket 监听
25[UnixSocket]
26Listen = /run/cloudreve/cloudreve.sock
27; 设置产生的 socket 文件的权限
28Perm = 0666
29
30; 数据库相关,如果你只想使用内置的 SQLite 数据库,这一部分直接删去即可
31[Database]
32; 数据库类型,目前支持 sqlite/mysql/mssql/postgres
33Type = mysql
34; MySQL 端口
35Port = 3306
36; 用户名
37User = root
38; 密码
39Password = root
40; 数据库地址
41Host = 127.0.0.1
42; 数据库名称
43Name = v3
44; 数据表前缀
45TablePrefix = cd_
46; 字符集
47Charset = utf8mb4
48; SQLite 数据库文件路径
49DBFile = cloudreve.db
50; 进程退出前安全关闭数据库连接的缓冲时间
51GracePeriod = 30
52; 使用 Unix Socket 连接到数据库
53UnixSocket = false
54
55; 从机模式下的配置
56[Slave]
57; 通信密钥
58Secret = 1234567891234567123456789123456712345678912345671234567891234567
59; 回调请求超时时间 (s)
60CallbackTimeout = 20
61; 签名有效期
62SignatureTTL = 60
63
64; 跨域配置
65[CORS]
66AllowOrigins = *
67AllowMethods = OPTIONS,GET,POST
68AllowHeaders = *
69AllowCredentials = false
70SameSite = Default
71Secure = lse
72
73; Redis 相关
74[Redis]
75Server = 127.0.0.1:6379
76Password =
77DB = 0
78
79; 从机配置覆盖
80[OptionOverwrite]
81; 可直接使用 `设置名称 = 值` 的格式覆盖
82max_worker_num = 50

2.2 配置案例

2.2.1 使用 MySQL

⚠️ 警告:更换数据库配置后,Cloudreve 会重新初始化数据库,原有的数据将会丢失!!!

默认情况下,Cloudreve 会使用内置的 SQLite 数据库,并在同级目录创建数据库文件 cloudreve.db,如果您想要使用 MySQL,请在配置文件中加入以下内容,并重启 Cloudreve。注意,Cloudreve 只支持 >=5.7 版本的 MySQL 。

 1[Database]
 2; 数据库类型,目前支持 sqlite/mysql/mssql/postgres
 3Type = mysql
 4; MySQL 端口
 5Port = 3306
 6; 用户名
 7User = root
 8; 密码
 9Password = root
10; 数据库地址
11Host = 127.0.0.1
12; 数据库名称
13Name = v3
14; 数据表前缀
15TablePrefix = cd
16; 字符集
17Charset = utf8

III. 进程守护

3.1 Systemd

1、创建 systemd 配置文件

1vim /usr/lib/systemd/system/cloudreve.service

2、将下文 PATH_TO_CLOUDREVE 更换为程序所在目录:

 1[Unit]
 2Description=Cloudreve
 3Documentation=https://docs.cloudreve.org
 4After=network.target
 5#After=mysqld.service
 6Wants=network.target
 7
 8[Service]
 9WorkingDirectory=/PATH_TO_CLOUDREVE
10ExecStart=/PATH_TO_CLOUDREVE/cloudreve
11Restart=on-abnormal
12RestartSec=5s
13KillMode=mixed
14
15StandardOutput=null
16StandardError=journal
17
18[Install]
19WantedBy=multi-user.target

3.2 管理命令

 1# 更新配置
 2systemctl daemon-reload
 3
 4# 启动服务
 5systemctl start cloudreve
 6
 7# 设置开机启动
 8systemctl enable cloudreve
 9
10# 停止服务
11systemctl stop cloudreve
12
13# 重启服务
14systemctl restart cloudreve
15
16# 查看状态
17systemctl status cloudreve

IV. 安全配置

4.1 默认用户

管理面板 -> 用户:

修改默认用户 admin@cloudreve.org 及密码。

4.2 关闭注册

管理面板 -> 参数设置 -> 注册与登录

🟩 允许新用户注册(关闭)

✅ 登录验证码(开启)

✅ 找回密码验证码(开启)

X. 参考文档

Cloudreve Doc