Debian/Ubuntu用rclone挂载Google Drive团队盘

需要注意,在rclone官网查看可以挂载哪些网盘!

CentOS或者其它Linux系统,请使用以下命令安装rclone

在Windows电脑上下载Rclone,下载地址:https://rclone.org/downloads 然后解压至D盘根目录,将文件夹重新命名为rclone,按下键盘Win+R,然后输入cmd,确定;在出现的命令框中依次输入以下命令:

cd /d d:\rclone
rclone authorize "onedrive"
 curl  https://rclone.org/install.sh | sudo bash 

onedrive需要从windows端获得API ID,谷歌网盘挂载直接在挂载中途获取

Debian/Ubuntu系统安装rclone

 wget https://www.80tm.com/wp-download/rclone_debian.sh && bash rclone_debian.sh 

初始化配置

 rclone config 
 root@80tm:~#  rclone config
2020/04/10 02:03:40 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
name> googlepan1 #给项目起一个名字
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 Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Citrix Sharefile
   \ "sharefile"
 9 / Dropbox
   \ "dropbox"
10 / Encrypt/Decrypt a remote
   \ "crypt"
11 / FTP Connection
   \ "ftp"
12 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
13 / Google Drive
   \ "drive"
14 / Google Photos
   \ "google photos"
15 / Hubic
   \ "hubic"
16 / In memory object storage system.
   \ "memory"
17 / JottaCloud
   \ "jottacloud"
18 / Koofr
   \ "koofr"
19 / Local Disk
   \ "local"
20 / Mail.ru Cloud
   \ "mailru"
21 / Mega
   \ "mega"
22 / Microsoft Azure Blob Storage
   \ "azureblob"
23 / Microsoft OneDrive
   \ "onedrive"
24 / OpenDrive
   \ "opendrive"
25 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
26 / Pcloud
   \ "pcloud"
27 / Put.io
   \ "putio"
28 / QingCloud Object Storage
   \ "qingstor"
29 / SSH/SFTP Connection
   \ "sftp"
30 / Sugarsync
   \ "sugarsync"
31 / Transparently chunk/split large files
   \ "chunker"
32 / Union merges the contents of several remotes
   \ "union"
33 / Webdav
   \ "webdav"
34 / Yandex Disk
   \ "yandex"
35 / http Connection
   \ "http"
36 / premiumize.me
   \ "premiumizeme"
Storage> 13 #13是谷歌网盘
** See help for drive backend at: https://rclone.org/drive/ **

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> #直接回车
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret> #直接回车
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 #完全的访问权限
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.

Note that if this is blank, the first time rclone runs it will fill it
in with the ID of the root folder.

Enter a string value. Press Enter for the default ("").
root_folder_id> 
回车默认设置
Service Account Credentials JSON file path 
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file> 
回车默认设置
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n #不需要进入高级配置
Remote config
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 #不需要自动配置
Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202264815644.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=sK4NOjkW4PvvlACA2FmRlg
Log in and authorize rclone for access
Enter verification code> 4/ygGcD一长串数字  #复制上面的谷歌链接到浏览器地址打开授权获取授权码填写到这里
Configure this as a team drive?
y) Yes
n) No (default)
y/n> y #选择谷歌团队盘
Fetching team drive list...
Choose a number from below, or type in your own value
 1 / drive2
   \ "0ACwUIdUjXa-sdafsd"
 2 / drive3
   \ "0AEgZyJlnodsaf"
Enter a Team Drive ID> 1 #多个团队盘,选择是哪一个
--------------------
[googlepan1]
type = drive
scope = drive
token = {"access_token":"ya29.a0Ae4lvC3S4gpa3jiQzypd8-cqQ_L4J2ROVXdsafsd0jd9hNaXy_2G_z1mHrsP5KgZRNCb5uG3rmIJC6r8AjPg2EBdKTB6pAnwy56-kPnsL8-E3Rx77_efreY7LrWTLR5btnAuSgeXb_DKycTDc","token_type":"Bearer","refresh_token":"1//0hdsafasdBM6CgYIARAAGBESNwF-L9IrCEv9WpzWi18y1OnktS6w2gLpo16SAzhTiQd8eLkxTWW2Tmg3SPAWOs90dC8jfkuddDT0","expiry":"2020-04-10T03:04:22.461408986Z"}
team_drive = 0ACwUIdUffa-CUk9PVA
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y #需要有编辑权限
Current remotes:

Name                 Type
====                 ====
googlepan1           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 #退出
 
 #新建本地文件夹,不想挂载到root文件夹请另行设置,即下面的LocalFolder
mkdir /root/GoogleDrive
#挂载为磁盘,下面的DriveName是项目名称、Folder是网盘文件夹(也可以为空即整个网盘)、LocalFolder是挂载的本地文件夹目录
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

使用挂断在后台的方式挂载不会卡住(必须先运营一次以上挂载命令,然后断开重新运行挂断后台运行):

nohup rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000  >/dev/null 2>&1 &
 

举例:


nohup rclone mount googlepan:  /root/GoogleDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000  >/dev/null 2>&1 &
nohup rclone mount onepan:   /root/onedrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000  >/dev/null 2>&1 &

 

挂载成功后,输入df -h命令查看:

root@80tm:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            220M     0  220M   0% /dev
tmpfs            49M  2.5M   47M   6% /run
/dev/vda2       6.8G  1.7G  4.8G  26% /
tmpfs           243M     0  243M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           243M     0  243M   0% /sys/fs/cgroup
googlepan1:     1.0P     0  1.0P   0% /root/GoogleDrive #这里显示挂载成功

卸载磁盘(如果你需要卸载的话):

fusermount -qzu LocalFolder

 

使用说明

### 文件上传
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

开机自启
先新建systemd配置文件,适用CentOS 7、Debian 8+、Ubuntu 16+
#将后面修改成你上面手动运行命令中,除了rclone的全部参数
command=”mount googlepan1: /root/GoogleDrive –copy-links –no-gzip-encoding –no-check-certificate –allow-other –allow-non-empty –umask 000″
#以下是一整条命令,一起复制到SSH客户端运行
cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
After=network-online.target

[Service]
Type=simple
ExecStart=$(command -v rclone) ${command}
Restart=on-abort
User=root

[Install]
WantedBy=default.target
EOF

 

开始启动:

systemctl start rclone

设置开机自启:

systemctl enable rclone

其他命令:
重启:

systemctl restart rclone

停止:

systemctl stop rclone

状态:

systemctl status rclone

如果你想挂载多个网盘,那么将systemd配置文件的rclone.service改成rclone1.service即可,重启动什么的同样换成rclone1。

VPS服务器测试命令1

发表评论