共计 4615 个字符,预计需要花费 12 分钟才能阅读完成。
准备工作
安装Alist
curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s install
我们要设置下密码才能使用,首先cd进入alist的安装目录,然后输入./alist admin set 新密码,回车即可。
---------如何获取密码?--------
先cd到alist所在目录:
cd /opt/alist
随机设置新密码:
./alist admin random
或者手动设置新密码:
./alist admin set NEW_PASSWORD
----------------------------
安装rclone
curl https://rclone.org/install.sh | sudo bash
# Ubuntu系统使用apt安装
apt-get install fuse3 -y
# centos系统使用yum安装
yum install fuse3 -y
设置rclone
# 进入rclone设置
rclone config
# 选择新远程
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n #这里选择n
# 设置名字
name> alist
Type of storage to configure.
Choose a number from below, or type in your own value
[snip]
XX / WebDAV
\ "webdav"
[snip]
Storage> webdav #这里输入远程的名字,之后就是你的远程名称
# 设置远程地址url http://your_alist_ip:port/dav
URL of http host to connect to
Choose a number from below, or type in your own value
1 / Connect to example.com
\ "https://example.com"
url> http://127.0.0.1:8080/dav #这里设置alist的地址和端口,后面要带dav,这是alist要求的
# 这里选6就可以了,1-5都不是我们使用的
Name of the WebDAV site/service/software you are using
Choose a number from below, or type in your own value
1 / Fastmail Files
\ (fastmail)
2 / Nextcloud
\ (nextcloud)
3 / Owncloud
\ (owncloud)
4 / Sharepoint Online, authenticated by Microsoft account
\ (sharepoint)
5 / Sharepoint with NTLM authentication, usually self-hosted or on-premises
\ (sharepoint-ntlm)
6 / Other site/service or software
\ (other)
vendor> 6
# 设置远程账号
User name
user> admin #这里是你alist的密码
# 设置远程密码
Password.
y) Yes type in my own password
g) Generate random password
n) No leave this optional password blank
y/g/n> y #这里输入y
Enter the password: #这输入你的密码,密码是看不到的
password:
Confirm the password: #再次输入你的密码
password:
# 这里直接回车即可
Bearer token instead of user/pass (e.g. a Macaroon)
bearer_token>
Remote config
# 这里可能会问你是默认还是高级,选择默认即可
# 你的远程信息
--------------------
[remote]
type = webdav
url = http://127.0.0.1:8080/dav
vendor = Other
user = admin
pass = *** ENCRYPTED ***
--------------------
# 确认
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y #输入y即可,
# 最后按q退出设置
挂载rclone到本地
查看是否连接成功,使用以下命令可以确认是否已经挂载上了alist
# 查看alist的目录 alist: 等于配置文件里面的名字
rclone lsd alist:
# 查看alist的文件 等于配置文件的remote
rclone ls alist:
#新建本地文件夹(不是必须的,根据自己的需求使用,我这里就没用)
mkdir -p /www/wwwroot/www.xxx.com/images
#挂载
rclone mount DriveName:Folder LocalFolder --cache-dir /tmp --allow-other --vfs-cache-mode writes --allow-non-empty
是不是有点懵,这里我们详细的说下参数就明白了,DriverName是你在配置rclone的时候设置的名字,Folder没有需要求的话填/即可,LocalFolder是你本地挂载的地址,/tmp比较特殊,上传时缓存目录,其他类型挂载一般时不需要这个参数的,默认/tmp地址即可,除非你的系统特殊
因为我们这里是需要存储网站的数据,所以我们要把挂载点挂载到网站的目录,最终写成
rclone mount alist:/ /www/wwwroot/www.xxx.com/images --allow-other --allow-non-empty --vfs-cache-mode writes --daemon
这里alist是我们上面的remote项目名,/www/wwwroot/www.xxx.com/images是我们需要挂载到哪个网站的目录,后面的参数自己看着设置即可。--daemon是后台运行的意思
./rclone mount:"添加网盘时的配置名称":"网盘指定目录" "挂载至本地的目录"
[--添加参数]
--allow-other:允许非当前 rclone 用户外其它用户进行访问
--attr-timeout 5m:文件属性缓存,(大小,修改时间等)的时间。如果 VPS 配置比较低,建议适当提高这个值,避免过多内核交互,降低资源占用。
--vfs-cache-mode full:开启 VFS 文件缓存,可减少 rclone 与 API 交互,同时可提高文件读写效率
--vfs-cache-max-age 24h:VFS 文件缓存时间,这里设置 24 小时,如果文件很少更改,建议设置更长时间
--vfs-cache-max-size 5G:VFS 文件缓存上限大小,请根据服务器剩余磁盘自行调节
--vfs-read-chunk-size-limit 300M:分块读取大小,这里设置的是300M,可以提高文件读取的效率,比如1G的文件,大致分为10个块进行读取,但与此同时 API 请求次数也会增多
--buffer-size 300M:设置内存缓存,请根据服务器内存大小自行设置
--daemon:后台运行程序
--copy-links: 如果 OneDrive 中存在链接(symlink),则复制链接而不是解析它们。
--no-gzip-encoding: 禁止对文件进行 gzip 编码。
--no-check-certificate: 禁止检查 SSL 证书。
--allow-other: 允许其他用户(非挂载命令的用户)访问和操作挂载的文件系统。
--allow-non-empty: 允许挂载到非空目录。如果您要将 OneDrive 挂载到一个非空目录,需要使用这个选项。
--umask 000: 设置挂载目录的文件权限掩码为 000,意味着挂载的文件和目录对所有用户都具有完全的权限。
--no-modtime 用缺少modtime信息换取加载速度。
检查挂载
df -h
我们可以看到名字为alist的云盘挂载已经挂载完成了,空间有1.0P,到这里我们已经完成云盘的挂载可以直接使用了。
解除本地挂载
# 解除本地挂载,后面跟的是挂载的本地目录
# 当自动取消挂载失败时,也可以这样手动取消挂载
fusermount -qzu /alist
最后
Rclone 设置
rclone config - 进入交互式配置选项,进行添加、删除、管理网盘等操作,以控制会话的形式添加rclone的配置,配置保存在.rclone.conf文件中。
rclone config file - 显示配置文件的路径,一般配置文件在 ~/.config/rclone/rclone.conf
rclone config show - 显示配置文件信
rclone copy - 将文件从源复制到目的地址,跳过已复制完成的。
rclone sync - 将源数据同步到目的地址,只更新目的地址的数据。
rclone move - 将源数据移动到目的地址。
rclone delete - 删除指定路径下的文件内容。
rclone purge - 清空指定路径下所有文件数据。
rclone mkdir - 创建一个新目录。
rclone rmdir - 删除空目录。
rclone check - 检查源和目的地址数据是否匹配。
rclone ls - 列出指定路径下所有的文件以及文件大小和路径。
rclone lsd - 列出指定路径下所有的目录/容器/桶。
rclone lsl - 列出指定路径下所有文件以及修改时间,文件大小和路径。
rclone md5sum - 为指定路径下的所有文件产生一个md5sum文件。
rclone sha1sum - 为指定路径下的所有文件产生一个sha1sum文件。
rclone size - 获取指定路径下,文件内容的总大小。 .
rclone version - 查看当前版本。
rclone cleanup - 清空remote。
rclone dedupe - 交互式查找重复文件,进行删除/重命名操作
开机启动
通过上面的教程,我们想要的效果已经基本实现了,就是有一个缺点,那就是当我们重启服务器后,rclone服务无法自动启动,所以我们为了更方便使用,可以把rclone添加系统启动服务
设置service文件
#创建service文件
vim /usr/lib/systemd/system/rclone.service
[Unit]
Description=rclone
[Service]
User=root
ExecStart=/usr/bin/rclone mount alist:/ /www/wwwroot/www.xxx.com/images --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --use-mmap
[Install]
WantedBy=multi-user.target
上面文件内容mount alist: 根据自己的来修改 这个是挂载目录,
设置开机自启
# reload守护进程
systemctl daemon-reload
# 设置service文件自启
systemctl enable rclone.service
# 启动service文件
systemctl start rclone.service