安装并配置Cloudreve网盘的离线下载

Cloudreve这个网盘程序现在已经非常好用了,代码全部用Go重写了,功能也比之前多了很多,还支持离线下载。

本文水一下新版的Cloudreve安装并配置离线下载。

咱用的系统是Debian10,首先装一下需要用到的包:

apt -y update
apt -y install aria2 nginx mariadb-server redis-server

因为要使用离线下载功能,为了获得更好的性能这里安装了mariadb替代了默认使用的sqlite。

装一下certbot,反代的时候用于签发ssl证书:

apt -y install snapd
snap install core
snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot

启动需要用到的服务:

systemctl enable --now nginx mariadb redis-server

初始化数据库:

mysql_secure_installation

创建一个名为cloudreve的数据库和用户:

mysql -u root -p
CREATE DATABASE cloudreve CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON cloudreve.* TO cloudreve@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
quit

下载cloudreve的二进制文件解压:

mkdir -p /opt/cloudreve && cd /opt/cloudreve
wget https://github.com/cloudreve/Cloudreve/releases/download/3.3.1/cloudreve_3.3.1_linux_amd64.tar.gz
tar -xzvf cloudreve_3.3.1_linux_amd64.tar.gz

新建一个配置文件:

nano conf.ini

写入如下配置:

[System]
Mode = master
Listen = 127.0.0.1:5000
Debug = false
[Database]
Type = mysql
Port = 3306
User = cloudreve
Password = password
Host = 127.0.0.1
Name = cloudreve
TablePrefix = cd_
[CORS]
AllowOrigins = *
AllowMethods = OPTIONS,GET,POST
AllowHeaders = *
AllowCredentials = false
[Redis]
Server = 127.0.0.1:6379
Password =
DB = 0

新建systemd服务,用于守护cloudreve进程:

nano /etc/systemd/system/cloudreve.service

写入如下配置:

[Unit]
Description=Cloudreve
Documentation=https://docs.cloudreve.org
After=network.target
After=mysqld.service
Wants=network.target
[Service]
WorkingDirectory=/opt/cloudreve
ExecStart=/opt/cloudreve/cloudreve
Restart=on-abnormal
RestartSec=5s
KillMode=mixed
StandardOutput=file:/var/log/cloudreve.log
StandardError=file:/var/log/cloudreve-error.log
[Install]
WantedBy=multi-user.target

启动cloudreve并设置开机自启:

systemctl enable --now cloudreve

首次运行,查看下面的日志文件获得你的管理员账号和密码:

cat /var/log/cloudreve.log

现在需要配置反向代理,新建nginx站点配置文件:

nano /etc/nginx/conf.d/cloudreve.conf

写入如下配置:

server {
listen       80;
server_name  cloudreve.233.fi;
client_max_body_size 0;
error_log /var/log/nginx/cloudreve.error.log;
access_log /var/log/nginx/cloudreve.access.log;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
}

使用certbot签发ssl证书:

certbot --nginx

接下来配置离线下载,创建需要用到的目录:

mkdir -p /opt/cloudreve/aria2/{config,temp}

新建aria2c配置文件:

nano /opt/cloudreve/aria2/config/aria2.conf

写入如下配置:

enable-rpc=true
rpc-listen-port=6800
rpc-secret=password
save-session-interval=1
save-session=/opt/cloudreve/aria2/config/aria2.session
auto-save-interval=30
max-concurrent-downloads=100
max-connection-per-server=16
split=64
enable-dht=true
dht-file-path=/opt/cloudreve/aria2/config/dht.dat
enable-peer-exchange=true
bt-enable-lpd=true
bt-max-peers=0
seed-time=0

新建systemd服务,用于守护aria2c进程:

nano /etc/systemd/system/aria2c.service

写入如下配置:

[Unit]
Description=Aria2c Download Manager
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/aria2c --conf-path=/opt/cloudreve/aria2/config/aria2.conf
Restart=on-abnormal
StandardOutput=file:/var/log/aria2c.log
StandardError=file:/var/log/aria2c-error.log
[Install]
WantedBy=multi-user.target

启动aria2c并设置开机自启:

systemctl enable --now aria2c

登录管理员后台,在离线下载这里配置连接:

测试正常可用:

参考文献:

https://docs.cloudreve.org/getting-started/config
https://aria2.github.io/manual/en/html/aria2c.html

全部为采集文章,文中的 联系方式 均不是 本人 的!

发表评论