I. 安装配置#
1.1 获取 Cloudreve#
在 GitHub Release
页面获取已经构建打包完成的主程序。
1.2 启动 Cloudreve#
1
2
3
4
5
6
7
8
9
10
| # 创建程序安装目录
mkdir /path/to/directory
# 解压主程序到安装目录
tar -zxvf cloudreve_VERSION_OS_ARCH.tar.gz -C /path/to/directory
# 切换到解压目录
cd /path/to/directory
# 赋予执行权限
chmod +x ./cloudreve
# 启动 Cloudreve
./cloudreve
|
📢 注意:请记录输出日志中的系统默认用户名和密码,以在后续使用。
1.3 反向代理配置#
在 Nginx 的 server 字段中加入:
1
2
3
4
5
6
7
8
9
| location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:5212;
# 如果您要使用本地存储策略,请将下一行注释符删除,并更改大小为理论最大文件尺寸
client_max_body_size 20000m;
}
|
1.4 域名解析#
参考示例:域名解析-腾讯云
II. 进阶配置(可选)#
2.1 配置文件#
首次启动时,Cloudreve 会在同级目录下创建名为 conf.ini 的配置文件,你可以修改此文件进行一些参数的配置,保存后需要重新启动 Cloudreve 生效。
一个完整的配置文件示例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| [System]
; 运行模式
Mode = master
; 监听端口
Listen = :5212
; 是否开启 Debug
Debug = false
; Session 密钥, 一般在首次启动时自动生成
SessionSecret = 23333
; Hash 加盐, 一般在首次启动时自动生成
HashIDSalt = something really hard to guss
; 呈递客户端 IP 时使用的 Header
ProxyHeader = X-Forwarded-For
; SSL 相关
[SSL]
; SSL 监听端口
Listen = :443
; 证书路径
CertPath = /path/to/fullchain.pem
; 私钥路径
KeyPath = /path/to/privkey.pem
; 启用 Unix Socket 监听
[UnixSocket]
Listen = /run/cloudreve/cloudreve.sock
; 设置产生的 socket 文件的权限
Perm = 0666
; 数据库相关,如果你只想使用内置的 SQLite 数据库,这一部分直接删去即可
[Database]
; 数据库类型,目前支持 sqlite/mysql/mssql/postgres
Type = mysql
; MySQL 端口
Port = 3306
; 用户名
User = root
; 密码
Password = root
; 数据库地址
Host = 127.0.0.1
; 数据库名称
Name = v3
; 数据表前缀
TablePrefix = cd_
; 字符集
Charset = utf8mb4
; SQLite 数据库文件路径
DBFile = cloudreve.db
; 进程退出前安全关闭数据库连接的缓冲时间
GracePeriod = 30
; 使用 Unix Socket 连接到数据库
UnixSocket = false
; 从机模式下的配置
[Slave]
; 通信密钥
Secret = 1234567891234567123456789123456712345678912345671234567891234567
; 回调请求超时时间 (s)
CallbackTimeout = 20
; 签名有效期
SignatureTTL = 60
; 跨域配置
[CORS]
AllowOrigins = *
AllowMethods = OPTIONS,GET,POST
AllowHeaders = *
AllowCredentials = false
SameSite = Default
Secure = lse
; Redis 相关
[Redis]
Server = 127.0.0.1:6379
Password =
DB = 0
; 从机配置覆盖
[OptionOverwrite]
; 可直接使用 `设置名称 = 值` 的格式覆盖
max_worker_num = 50
|
2.2 配置案例#
2.2.1 使用 MySQL#
⚠️ 警告:更换数据库配置后,Cloudreve 会重新初始化数据库,原有的数据将会丢失!!!
默认情况下,Cloudreve 会使用内置的 SQLite 数据库,并在同级目录创建数据库文件 cloudreve.db,如果您想要使用 MySQL,请在配置文件中加入以下内容,并重启 Cloudreve。注意,Cloudreve 只支持 >=5.7 版本的 MySQL 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| [Database]
; 数据库类型,目前支持 sqlite/mysql/mssql/postgres
Type = mysql
; MySQL 端口
Port = 3306
; 用户名
User = root
; 密码
Password = root
; 数据库地址
Host = 127.0.0.1
; 数据库名称
Name = v3
; 数据表前缀
TablePrefix = cd
; 字符集
Charset = utf8
|
III. 进程守护#
3.1 Systemd#
1、创建 systemd 配置文件
1
| vim /usr/lib/systemd/system/cloudreve.service
|
2、将下文 PATH_TO_CLOUDREVE 更换为程序所在目录:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| [Unit]
Description=Cloudreve
Documentation=https://docs.cloudreve.org
After=network.target
#After=mysqld.service
Wants=network.target
[Service]
WorkingDirectory=/PATH_TO_CLOUDREVE
ExecStart=/PATH_TO_CLOUDREVE/cloudreve
Restart=on-abnormal
RestartSec=5s
KillMode=mixed
StandardOutput=null
StandardError=journal
[Install]
WantedBy=multi-user.target
|
3.2 管理命令#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| # 更新配置
systemctl daemon-reload
# 启动服务
systemctl start cloudreve
# 设置开机启动
systemctl enable cloudreve
# 停止服务
systemctl stop cloudreve
# 重启服务
systemctl restart cloudreve
# 查看状态
systemctl status cloudreve
|
IV. 安全配置#
4.1 默认用户#
管理面板 -> 用户:
修改默认用户 admin@cloudreve.org 及密码。
4.2 关闭注册#
管理面板 -> 参数设置 -> 注册与登录
🟩 允许新用户注册(关闭)
✅ 登录验证码(开启)
✅ 找回密码验证码(开启)
X. 参考文档#
Cloudreve Doc