外观
使用Rclone挂载腾讯云对象存储到服务器
参考资料
参考文章:ubuntu挂载腾讯云cos实现自动备份网站和数据库
参考文章:腾讯云200M锐驰轻量实例手动挂载免费轻量对象存储
安装 Rclone
# 安装方式1
sudo apt install rclone
# 安装方式2
sudo curl https://rclone.org/install.sh | bash
提示
两种安装方式可挂载的远程储存顺序可能是不一致的,需要注意一下。
安装 fusermount
# 安装 fuse,如果挂载时报错请安装 fuse3
apt update && apt install -y fuse
# 安装 fuse3
apt update && apt install -y fuse3
Rclone 配置
使用命令配置
运行如下命令
rclone config
输出
# No remotes found, make a new one?
# n) New remote
# s) Set configuration password
# q) Quit config
n/s/q> n
# Enter name for new remote.
name> Set your own name
# Option Storage.
# Type of storage to configure.
# Choose a number from below, or type in your own value.
# ...
# 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, ArvanCloud, Ceph, ChinaMobile, Cloudflare, DigitalOcean, Dreamhost, GCS, HuaweiOBS, IBMCOS, IDrive, IONOS, LyveCloud, Leviia, Liara, Linode, Magalu, Minio, Netease, Outscale, Petabox, RackCorp, Rclone, Scaleway, SeaweedFS, Selectel, StackPath, Storj, Synology, TencentCOS, Wasabi, Qiniu and others
# \ (s3)
# ...
# 此步注意不一定为 4
Storage> 4
# Option provider.
# Choose your S3 provider.
# Choose a number from below, or type in your own value.
# Press Enter to leave empty.
# ...
# 31 / Tencent Cloud Object Storage (COS)
# \ (TencentCOS)
# ...
# 此步注意不一定为 31
provider> 31
# Option env_auth.
# Get AWS credentials from runtime (environment variables or EC2/ECS meta data if no env vars).
# Only applies if access_key_id and secret_access_key is blank.
# Choose a number from below, or type in your own boolean value (true or false).
# Press Enter for the default (false).
# 1 / Enter AWS credentials in the next step.
# \ (false)
# 2 / Get AWS credentials from the environment (env vars or IAM).
# \ (true)
env_auth> 1
# Option access_key_id.
# AWS Access Key ID.
# Leave blank for anonymous access or runtime credentials.
# Enter a value. Press Enter to leave empty.
access_key_id> Your SecretId
# Option secret_access_key.
# AWS Secret Access Key (password).
# Leave blank for anonymous access or runtime credentials.
# Enter a value. Press Enter to leave empty.
secret_access_key> Your SecretKey
# Option endpoint.
# Endpoint for Tencent COS API.
# Choose a number from below, or type in your own value.
# Press Enter to leave empty.
# 1 / Beijing Region
# \ (cos.ap-beijing.myqcloud.com)
# 2 / Nanjing Region
# \ (cos.ap-nanjing.myqcloud.com)
# 3 / Shanghai Region
# \ (cos.ap-shanghai.myqcloud.com)
# 4 / Guangzhou Region
# \ (cos.ap-guangzhou.myqcloud.com)
# 5 / Nanjing Region
# \ (cos.ap-nanjing.myqcloud.com)
# 6 / Chengdu Region
# \ (cos.ap-chengdu.myqcloud.com)
# 7 / Chongqing Region
# \ (cos.ap-chongqing.myqcloud.com)
# 8 / Hong Kong (China) Region
# \ (cos.ap-hongkong.myqcloud.com)
# 9 / Singapore Region
# \ (cos.ap-singapore.myqcloud.com)
# 10 / Mumbai Region
# \ (cos.ap-mumbai.myqcloud.com)
# 11 / Seoul Region
# \ (cos.ap-seoul.myqcloud.com)
# 12 / Bangkok Region
# \ (cos.ap-bangkok.myqcloud.com)
# 13 / Tokyo Region
# \ (cos.ap-tokyo.myqcloud.com)
# 14 / Silicon Valley Region
# \ (cos.na-siliconvalley.myqcloud.com)
# 15 / Virginia Region
# \ (cos.na-ashburn.myqcloud.com)
# 16 / Toronto Region
# \ (cos.na-toronto.myqcloud.com)
# 17 / Frankfurt Region
# \ (cos.eu-frankfurt.myqcloud.com)
# 18 / Moscow Region
# \ (cos.eu-moscow.myqcloud.com)
# 19 / Use Tencent COS Accelerate Endpoint
# \ (cos.accelerate.myqcloud.com)
# 按照实际cos的地域选择
endpoint> 1
# Option acl.
# Canned ACL used when creating buckets and storing or copying objects.
# This ACL is used for creating objects and if bucket_acl isn't set, for creating buckets too.
# For more info visit https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
# Note that this ACL is applied when server-side copying objects as S3
# doesn't copy the ACL from the source but rather writes a fresh one.
# If the acl is an empty string then no X-Amz-Acl: header is added and
# the default (private) will be used.
# Choose a number from below, or type in your own value.
# Press Enter to leave empty.
# / Owner gets Full_CONTROL.
# 1 | No one else has access rights (default).
# \ (default)
# ...
acl> 1
# Option storage_class.
# The storage class to use when storing new objects in Tencent COS.
# Choose a number from below, or type in your own value.
# Press Enter to leave empty.
# 1 / Default
# \ ()
# ...
storage_class> 1
# Edit advanced config?
# y) Yes
# n) No (default)
y/n> n
# Configuration complete.
# Options:
# - type: s3
# - provider: TencentCOS
# - access_key_id: Your SecretId
# - secret_access_key: Your SecretKey
# - endpoint: cos.ap-beijing.myqcloud.com
# - acl: default
# Keep this "set your own name" remote?
# y) Yes this is OK (default)
# e) Edit this remote
# d) Delete this remote
y/e/d> y
# Current remotes:
# Name Type
# ==== ====
# set your own name s3
# e) Edit existing remote
# n) New remote
# d) Delete remote
# r) Rename remote
# c) Copy remote
# s) Set configuration password
# q) Quit config
e/n/d/r/c/s/q> q
编写rclone.conf
文件
配置文件在/root/.config/rclone/rclone.conf
,直接将配置添加至末尾即可,配置内容如下,注意将set your own name
、Your SecretId
和Your SecretKey
换成自己的。
[Set your own name]
type = s3
provider = TencentCOS
access_key_id = Your SecretId
secret_access_key = Your SecretKey
endpoint = cos.ap-beijing.myqcloud.com
acl = default
挂载
手动挂载
重启过后不会自动挂载
rclone mount Set your own name:/Your Bucket name /home/rclone/data --cache-dir /tmp --vfs-cache-mode writes --allow-non-empty --log-file /var/log/rclone.log --log-level DEBUG
rclone mount
:rclone mount
是用来挂载远程存储到本地文件系统的一种命令。它将远程存储服务(如 Google Drive、Dropbox、S3 等)挂载为一个虚拟文件系统,使你可以通过本地目录访问远程数据。Set your own name:/Your Bucket name
:
Set your own name
是你在配置rclone
时为远程存储提供的名称(比如在rclone config
中设置的名称)。/Your Bucket name
是存储在远程服务上的某个桶(Bucket)的名字。桶类似于云存储中的文件夹或目录,存储所有文件。 例如,如果你的远程存储配置名称是TencentCOS
,桶名是cos-10000000000000
,那么这部分应该是TencentCOS:cos-10000000000000
。
/home/rclone/data
: 这是本地挂载的目录。挂载命令会将远程存储的内容挂载到这个本地路径。也就是说,你可以通过访问/home/rclone/data
来访问远程存储上的数据。--cache-dir /tmp
: 该选项指定了一个本地目录(此处为/tmp
)来存储缓存文件。当挂载时,rclone
会将一些数据缓存到该目录,以提高性能和访问速度。通常缓存的内容包括文件列表和最近访问的文件。--vfs-cache-mode writes
: 这个选项设置了虚拟文件系统(VFS)的缓存模式。在writes
模式下,rclone
会在本地保存写入的文件内容,然后将它们同步到远程存储。这有助于提升文件写入的速度和稳定性,特别是对于大型文件的处理。--allow-non-empty
: 该选项允许在本地挂载点已经有内容的情况下挂载远程存储。如果不指定这个选项,rclone mount
会拒绝挂载到非空的本地目录。--log-file /var/log/rclone.log
: 该选项指定了rclone
的日志文件路径。在这里,日志会保存到/var/log/rclone.log
。日志包含了命令的执行过程和错误信息,便于排查问题。--log-level DEBUG
: 这个选项设置了日志的详细程度。DEBUG
是最高级别的日志输出,包含了最详细的调试信息。这对于排查问题非常有用,但也会产生大量日志数据。
systemd
进程守护
cat > /etc/systemd/system/rclonecos.service <<EOF
[Unit]
Description=Rclone Cos Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/rclone mount Set your own name:/Your Bucket name / /home/rclone/data --cache-dir /tmp --vfs-cache-mode writes --allow-non-empty
StandardOutput=append:/home/rclone/rclone.log
StandardError=append:/home/rclone/rclone.log
[Install]
WantedBy=multi-user.target
EOF
设置开机自启动
# 允许开机自启
systemctl enable rclonecos
# 其余常用命令
systemctl stop rclonecos
systemctl daemon-reload
systemctl start rclonecos
systemctl status rclonecos
备注
检查 rclone
是否挂载成功
mount | grep rclone
不想挂载 /home/rclone/data
,可以卸载:
fusermount -u /home/rclone/data
删除rclonecos.service
服务
# 停止服务
sudo systemctl stop rclonecos.service
# 禁用服务
sudo systemctl disable rclonecos.service
# 删除服务文件
sudo rm /etc/systemd/system/rclonecos.service
# 重新加载 systemd 配置
sudo systemctl daemon-reload
# 清理未使用的服务
sudo systemctl reset-failed