1、安装rclone

curl https://rclone.org/install.sh | sudo bash

2、初始化配置

rclone config 

3、每一步的设置

[root@centos72 ~]# rclone config
2022/02/20 20:09:43 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n #选n(new)新建
name> googlepan #给挂载的盘取一个名称
Option Storage.
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ "fichier"
 2 / Alias for an existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COt COS
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Better checksums for other remotes
   \ "hasher"
 7 / Box
   \ "box"
 8 / Cache a remote
   \ "cache"
 9 / Citrix Sharefile
   \ "sharefile"
10 / Compress a remote
   \ "compress"
11 / Dropbox
   \ "dropbox"
12 / Encrypt/Decrypt a remote
   \ "crypt"
13 / Enterprise File Fabric
   \ "filefabric"
14 / FTP Connection
   \ "ftp"
15 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
16 / Google Drive
   \ "drive"
17 / Google Photos
   \ "google photos"
18 / Hadoop distributed file system
   \ "hdfs"
19 / Hubic
   \ "hubic"
20 / In memory object storage system.
   \ "memory"
21 / Jottacloud
   \ "jottacloud"
22 / Koofr
   \ "koofr"
23 / Local Disk
   \ "local"
24 / Mail.ru Cloud
   \ "mailru"
25 / Mega
   \ "mega"
26 / Microsoft Azure Blob Storage
   \ "azureblob"
27 / Microsoft OneDrive
   \ "onedrive"
28 / OpenDrive
   \ "opendrive"
29 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
30 / Pcloud
   \ "pcloud"
31 / Put.io
   \ "putio"
32 / QingCloud Object Storage
   \ "qingstor"
33 / SSH/SFTP Connection
   \ "sftp"
34 / Sia Decentralized Cloud
   \ "sia"
35 / Sugarsync
   \ "sugarsync"
36 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
37 / Transparently chunk/split large files
   \ "chunker"
38 / Union merges the contents of several upstream fs
   \ "union"
39 / Uptobox
   \ "uptobox"
40 / Webdav
   \ "webdav"
41 / Yandex Disk
   \ "yandex"
42 / Zoho
   \ "zoho"
43 / http Connection
   \ "http"
44 / premiumize.me
   \ "premiumizeme"
45 / seafile
   \ "seafile"
Storage> 16 #选择16为挂载谷歌盘
Option client_id.
Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
client_id> #回车
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> #回车
Option scope.
Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value.
 1 / Full access all files, excluding Application Data Folder.
   \ "drive"
 2 / Read-only access to file metadata and file contents.
   \ "drive.readonly"
   / Access to files created by rclone only.
 3 | These are visible in the drive website.
   | File authorization is revoked when the user deauthorizes the app.
   \ "drive.file"
   / Allows read and write access to the Application Data folder.
 4 | This is not visible in the drive website.
   \ "drive.appfolder"
   / Allows read-only access to file metadata but
 5 | does not allow any access to read or download file content.
   \ "drive.metadata.readonly"
scope> 1 #选1授权最大化
Option root_folder_id.
ID of the root folder.
Leave blank normally.
Fill in to access "Computers" folders (see docs), or for rclone to use
a non root folder as its starting point.
Enter a string value. Press Enter for the default ("").
root_folder_id> #回车
Option service_account_file.
Service Account Credentials JSON file path.
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.
Enter a string value. Press Enter for the default ("").
service_account_file> #回车
Edit advanced config?
y) Yes
n) No (default)
y/n> n #不进入高级选项
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine

y) Yes (default)
n) No
y/n> n #不进入自动配置
Option config_verification_code.
Verification code
Go to this URL, authenticate then paste the code here.
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=23hmtSsBo1PMLbH2c2iIKg
Enter a string value. Press Enter for the default ("").
config_verification_code> 4/1AX4XfW #把上面的网址复制到浏览器中并确认授权,得到一串授权码粘贴在这里
Configure this as a Shared Drive (Team Drive)?

y) Yes
n) No (default)
y/n> y #确定挂载团队盘
--------------------
[googlepan]
type = drive
scope = drive
token = {"access_token":"ya29.A0ARrda","token_type":"Bearer","refresh_token":"1//0e","expiry":"2022-02-20T21:13:44.7664075+08:00"}
team_drive = 0AH4I8T23
root_folder_id = 
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y #确认配置
Current remotes:

Name                 Type
====                 ====
googlepan            drive

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退出

二、挂载Google Drive
1.创建一个googlepan目录,作为挂载目录

mkdir -p /googlepan

2、挂载参数
–后面跟的是参数 可以自己调整,mount后面跟的是googlepan,也就是最开始命名的那个名字。后面的/googlepan是刚刚新建的目录。

/usr/bin/rclone mount googlepan: /googlepan \
 --umask 0000 \
 --default-permissions \
 --allow-non-empty \
 --allow-other \
 --buffer-size 32M \
 --dir-cache-time 12h \
 --vfs-read-chunk-size 64M \
 --vfs-read-chunk-size-limit 1G &

回车,如果出现以下错误:

Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH

请安装fuse:

yum -y install fuse

3、挂载成功后,输入命令查看:

df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 459M 0 459M 0% /dev
tmpfs 493M 4.0K 493M 1% /dev/shm
tmpfs 493M 50M 443M 11% /run
tmpfs 493M 0 493M 0% /sys/fs/cgroup
/dev/sda3 39G 4.5G 34G 12% /
/dev/sda1 512M 12M 501M 3% /boot/efi
tmpfs 99M 0 99M 0% /run/user/994
tmpfs 99M 0 99M 0% /run/user/1000
googlepan: 1.0P 0 1.0P 0% /googlepan

此时进宝塔面板刷新应该就可以看到挂载的谷歌1.0P空间的盘了

三、守护运行
宝塔安装Supervisor管理器,守护挂载好的GoogleDrive。如果有挂载多个网盘,需要添加多个进程守护。
名称:随便填
启动用户:root
运行目录:/
启动命令:就是上面的挂载命令

/usr/bin/rclone mount googlepan: /googlepan --umask 0000 --default-permissions --allow-non-empty --allow-other --buffer-size 32M --dir-cache-time 12h --vfs-read-chunk-size 64M --vfs-read-chunk-size-limit 1G 

进程数量:1
四、如果要卸载,可以使用以下命令来完成。

rclone config

根据提示操作,此处不再赘述。记得卸载了,也要把Supervisor守护进程删除。

五、如果不用宝塔的也可以这样
1、新建systemd配置文件,以下是一整条命令,一起复制到SSH客户端运行。
如果你想挂载多个网盘,那么将systemd配置文件的rclone.service改成rclone1.service即可,重启动什么的同样换成rclone1。
把googlepan改成你的挂载盘的名字(前)和/目录(后)

cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
AssertPathIsDirectory=LocalFolder  
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount googlepan: /googlepan \  
 --umask 0000 \
 --default-permissions \
 --allow-non-empty \
 --allow-other \
 --buffer-size 32M \
 --dir-cache-time 12h \
 --vfs-read-chunk-size 64M \
 --vfs-read-chunk-size-limit 1G
ExecStop=/bin/fusermount -u LocalFolder 
Restart=on-abort
User=root

[Install]
WantedBy=default.target
EOF

启动

systemctl start rclone

开机启动

systemctl enable rclone

重新启动

systemctl restart rclone

停止

systemctl stop rclone

五、rclone命令用法

### 文件上传
rclone copy /home/backup gdrive:backup # 本地路径 配置名字:谷歌文件夹名字
### 文件下载
rclone copy gdrive:backup /home/backup
### 列表
rclone ls gdrive:backup
rclone lsl gdrive:backup # 比上面多一个显示上传时间
rclone lsd gdrive:backup # 只显示文件夹
### 新建文件夹
rclone mkdir gdrive:backup
### 挂载
rclone mount gdrive:mm /root/mm &
### 卸载
fusermount -u  /root/mm

#### 其他 ####
#### https://softlns.github.io/2016/11/28/rclone-guide/
rclone config - 以控制会话的形式添加rclone的配置,配置保存在.rclone.conf文件中。
rclone copy - 将文件从源复制到目的地址,跳过已复制完成的。
rclone sync - 将源数据同步到目的地址,只更新目的地址的数据。   –dry-run标志来检查要复制、删除的数据
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 - 交互式查找重复文件,进行删除/重命名操作。
#### 其他 ####
挂载到本地
apt-get install -y nload htop fuse p7zip-full

#::挂载为磁盘
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
 
#::卸载磁盘
fusermount -qzu LocalFolder
最后修改:2022 年 02 月 20 日
如果觉得我的文章对你有用,请随意赞赏