VPS挂载Google Drive-Rclone给服务器自动挂载多块盘

将Google Drive 挂载到 VPS服务器,实现多种用途。可以扩充服务器空间,用作离线下载转存空间,可以备份服务器资料,或者挂载影音资源打造个人媒体中心。玩法多种多样,可以自行挖掘。

安装 Rclone,fuse

以 Centos 7 为例

yum install fuse

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

Rclone 配置

rclone config

详细配置步骤

  1e) Edit existing remote
  2n) New remote
  3d) Delete remote
  4r) Rename remote
  5c) Copy remote
  6s) Set configuration password
  7q) Quit config
  8e/n/d/r/c/s/q> n                          #选择 n ,创建新的连接
  9name> folder1                                   #名字随意,与后面代码要对应
 10Type of storage to configure.
 11Enter a string value. Press Enter for the default ("").
 12Choose a number from below, or type in your own value
 13 1 / 1Fichier
 14   \ "fichier"
 15 2 / Alias for an existing remote
 16   \ "alias"
 17 3 / Amazon Drive
 18   \ "amazon cloud drive"
 19 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, SeaweedFS, and Tencent COS
 20   \ "s3"
 21.
 22.
 23.
 2414 / Google Cloud Storage (this is not Google Drive)
 25   \ "google cloud storage"
 2615 / Google Drive
 27   \ "drive"
 2816 / Google Photos
 29   \ "google photos"
 30.
 31.
 32.
 3343 / seafile
 34   \ "seafile"
 35Storage> 15                  #选择15,可能因为版本不同而序号不同,注意选择 Google Drive
 36Google Application Client Id
 37Setting your own is recommended.
 38See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
 39If you leave this blank, it will use an internal key which is low performance.
 40Enter a string value. Press Enter for the default ("").
 41client_id>                               # 直接回车
 42OAuth Client Secret
 43Leave blank normally.
 44Enter a string value. Press Enter for the default ("").
 45client_secret>                           #直接回车
 46Scope that rclone should use when requesting access from drive.
 47Enter a string value. Press Enter for the default ("").
 48Choose a number from below, or type in your own value
 49 1 / Full access all files, excluding Application Data Folder.
 50   \ "drive"
 51 2 / Read-only access to file metadata and file contents.
 52   \ "drive.readonly"
 53   / Access to files created by rclone only.
 54 3 | These are visible in the drive website.
 55   | File authorization is revoked when the user deauthorizes the app.
 56   \ "drive.file"
 57   / Allows read and write access to the Application Data folder.
 58 4 | This is not visible in the drive website.
 59   \ "drive.appfolder"
 60   / Allows read-only access to file metadata but
 61 5 | does not allow any access to read or download file content.
 62   \ "drive.metadata.readonly"
 63scope> 1                             #选择1 ,所有权限
 64ID of the root folder
 65Leave blank normally.
 66
 67Fill in to access "Computers" folders (see docs), or for rclone to use
 68a non root folder as its starting point.
 69
 70Enter a string value. Press Enter for the default ("").
 71root_folder_id>           #设置Google Drive挂载路径,空是根路径;打开某个文件夹,地址栏结尾一串字符为该文件夹路径
 72Service Account Credentials JSON file path 
 73Leave blank normally.
 74Needed only if you want use SA instead of interactive login.
 75
 76Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.
 77
 78Enter a string value. Press Enter for the default ("").
 79service_account_file>        # 直接回车   
 80Edit advanced config?
 81y) Yes
 82n) No (default)
 83y/n> n                  #选择 n
 84Use auto config?
 85 * Say Y if not sure
 86 * Say N if you are working on a remote or headless machine
 87
 88y) Yes (default)
 89n) No
 90y/n> n               #选择 n
 91Verification code
 92
 93Go to this URL, authenticate then paste the code here.
 94
 95https://accounts.google.com/XXXXXXXXXXXm%2Fauth%2FdXXXXXXXXXXX
 96
 97Enter a string value. Press Enter for the default ("").
 98config_verification_code>    #浏览器打开链接,将获取到的key粘贴到这里
 99Configure this as a Shared Drive (Team Drive)?
100
101y) Yes
102n) No (default)
103y/n> n                    # 选 n
104--------------------
105[emby]
106type = drive
107scope = drive
108root_folder_id = XXXXXXXXXXX
109token = {"access_token":"XXXXXXXXXXX","token_type":"Bearer","refresh_token":"XXXXXXXXXXX","expiry":"2011-05-07T01:XXXXXXXXXXX"}
110team_drive = 
111--------------------
112y) Yes this is OK (default)
113e) Edit this remote
114d) Delete this remote
115y/e/d> y
116
117
118# 最后退出

手动挂载方式

mkdir -p /home/pan1 #创建挂载文件夹

1/usr/bin/rclone mount folder1: /home/pan1 \
2 --umask 0000 \
3 --default-permissions \
4 --allow-non-empty \
5 --allow-other \
6 --buffer-size 32M \
7 --dir-cache-time 12h \
8 --vfs-read-chunk-size 64M \
9 --vfs-read-chunk-size-limit 1G &

创建自动挂载服务

mkdir -p /home/pan1 #创建挂载文件夹

 1cat > /etc/systemd/system/rclone1.service <<EOF    #挂载第2块盘时候,修改此处服务名称
 2[Unit]
 3Description=Rclone
 4AssertPathIsDirectory=LocalFolder
 5After=network-online.target
 6
 7[Service]
 8Type=simple
 9ExecStart=/usr/bin/rclone mount folder1: /home/pan1 \   #挂载第2块盘时,修改此处名称和挂载点
10 --umask 0000 \
11 --default-permissions \
12 --allow-non-empty \
13 --allow-other \
14 --buffer-size 32M \
15 --dir-cache-time 12h \
16 --vfs-read-chunk-size 64M \
17 --vfs-read-chunk-size-limit 1G
18ExecStop=/bin/fusermount -u LocalFolder
19Restart=on-abort
20User=root
21
22[Install]
23WantedBy=default.target
24EOF

挂载第2块盘时,再配置一遍 Rclone。 然后新创建一个挂载服务,依照上面注释修改。

启动服务并设置开启自启

systemctl start rclone1

systemctl enable rclone1

查看挂载是否成功

df -h

版权

评论