做一个谷歌云端硬盘文件列表吧

众所周知,onedrive有例如OneList、PyOne、OLAINDEX等多种目录列表程序,本文将用FileBrowser实现Google drive也具有类似功能。

准备

  1. 国外vps(要访问Google drive,kvm虚拟最好)
  2. Google drive

 

搭建

安装rclone

这里用Rat’s的一键脚本(能一键谁想手动,谁和方便过不去)

#适用Debian/Ubuntu系统
wget https://www.moerats.com/usr/shell/rclone_debian.sh && bash rclone_debian.sh
#完成后初始化配置
rclone config

会出现以下信息:(时间不同可能会有出入)

2019/06/18 10:10:13 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> kenshin     #名字随便填,但是要记住,后面要用到
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 / A stackable unification remote, which can appear to merge the contents of several remotes
   \ "union"
 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 / Dropbox
   \ "dropbox"
 9 / Encrypt/Decrypt a remote
   \ "crypt"
10 / FTP Connection
   \ "ftp"
11 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
12 / Google Drive
   \ "drive"
13 / Hubic
   \ "hubic"
14 / JottaCloud
   \ "jottacloud"
15 / Koofr
   \ "koofr"
16 / Local Disk
   \ "local"
17 / Mega
   \ "mega"
18 / Microsoft Azure Blob Storage
   \ "azureblob"
19 / Microsoft OneDrive
   \ "onedrive"
20 / OpenDrive
   \ "opendrive"
21 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
22 / Pcloud
   \ "pcloud"
23 / QingCloud Object Storage
   \ "qingstor"
24 / SSH/SFTP Connection
   \ "sftp"
25 / Webdav
   \ "webdav"
26 / Yandex Disk
   \ "yandex"
27 / http Connection
   \ "http"
Storage> 12     #选择12,Google Drive
** 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>   #留空
ID of the root folder
Leave blank normally.
Fill in to access "Computers" folders. (see docs).
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
y/n> 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
n) No
y/n> n     #选n
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?......     #复制到浏览器打开,登录需要挂载的谷歌账号
Log in and authorize rclone for access
Enter verification code>   #填入上面获取到的验证码
Configure this as a team drive?
y) Yes
n) No
y/n> n     #团队云盘,看需要填写,我没需要填了n
[kenshin]
type = drive
token = {"access_token":"ya29.GlsrB3Ub9qLFP2GP69KBmwyZRd-"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y     #选择y
Current remotes:

Name                 Type
====                 ====
kenshin             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     #选q退出

挂载为磁盘

#挂载为磁盘,DriveName为rclone的name,Folder为Google Drive里的文件夹,全部挂载就改为/,LocalFolder为VPS上的本地文件夹
rclone mount DriveName:Folder LocalFolder --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
#我选择新建本地文件夹作为本地挂载点
mkdir /root/GoogleDrive

查看是否挂载成功

root@kenshin:~# df -h #查看
Filesystem                    Size  Used Avail Use% Mounted on
udev                          235M     0  235M   0% /dev
tmpfs                         50M  5.4M   44M  11% /run
/dev/mapper/vg_jh-root        5.4G  1.3G  3.9G  25% /
tmpfs                         247M     0  247M   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                         247M     0  247M   0% /sys/fs/cgroup
/dev/vda1                     464M   37M  399M   9% /boot
tmpfs                         50M     0   50M   0% /run/user/0
kenshin:                      1.0P   24T  1.0P   3% /root/GoogleDrive     #出现这个即挂载成功
root@kenshin:~# 

自启动(同采用Rat’s的一键脚本)

wget https://www.moerats.com/usr/shell/rcloned && nano rcloned
#修改以下内容:
#NAME=""  #rclone name名,及配置时输入的Name
#REMOTE=''  #远程文件夹,Google Drive网盘里的挂载的一个文件夹
#LOCAL=''  #挂载地址,VPS本地挂载目录

使用命令设置自启:

#Debian系统
apt-get install sudo -y

#设置自启
mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned
update-rc.d -f rcloned defaults
bash /etc/init.d/rcloned start

检测信息显示rclone启动成功即可。

安装 FileBrowser

File Browser 适用于全平台,任何操作系统都可以安装它。一条命令安装

curl -fsSL https://filebrowser.xyz/get.sh | bash

github地址:https://github.com/filebrowser/filebrowser/

修改配置

创建配置数据库:filebrowser -d /etc/filebrowser.db config init

设置监听地址:filebrowser -d /etc/filebrowser.db config set --address 0.0.0.0

设置监听端口:filebrowser -d /etc/filebrowser.db config set --port 80

设置语言环境:filebrowser -d /etc/filebrowser.db config set --locale zh-cn

设置日志位置:filebrowser -d /etc/filebrowser.db config set --log /var/log/filebrowser.log

添加一个用户:filebrowser -d /etc/filebrowser.db users add root password --perm.admin,其中的rootpassword分别是用户名和密码,根据自己的需求更改。

配置修改好以后,就可以启动 File Browser 了,使用-d参数指定配置数据库路径。

filebrowser -d /etc/filebrowser.db

在这里我用screen来启动,因为断开ssh会关闭程序。后面有解决办法,我没试

然后http://IP:监听端口/访问 File Browser

登录进入默认目录是根目录,设置-用户管理可以修改目录,我直接修改成挂载目录

 

 

你甚至可以看视频

可以上传,下载

 

网上资料补充(未测试)

File Browser 后台运行

第一种方法:

运行:nohup filebrowser -d /etc/filebrowser.db >/dev/null 2>&1 &

停止运行:kill -9 $(pidof filebrowser)

开机启动:sed -i '/exit 0/i\nohup filebrowser -d \/etc\/filebrowser.db >\/dev\/null 2>&1 &' /etc/rc.local

取消开机启动:sed -i '/nohup filebrowser -d \/etc\/filebrowser.db >\/dev\/null 2>&1 &/d' /etc/rc.local

第二种方法:

首先下载 File Browser 的 service 文件:curl https://cdn.mivm.cn/www.mivm.cn/archives/filebrowser/filebrowser.service -o /lib/systemd/system/filebrowser.service

如果你的运行命令不是/usr/local/bin/filebrowser -d /etc/filebrowser.db,需要对 service 文件进行修改,将文件的 ExecStart 改为你的运行命令,更改完成后需要输入systemctl daemon-reload

运行:systemctl start filebrowser.service

停止运行:systemctl stop filebrowser.service

开机启动:systemctl enable filebrowser.service

取消开机启动:systemctl disable filebrowser.service

查看运行状态:systemctl status filebrowser.service

 

HTTPS

File Browser 2.0 起开始内建 HTTPS 支持,只需要配置 SSL 证书即可。

配置 SSL:filebrowser -d /etc/filebrowser.db config set --cert example.com.crt --key example.com.key,其中example.com.crtexample.com.key分别是 SSL 证书和密钥路径,根据自身情况进行更改。配置完 SSL 后,只可以使用 HTTPS 访问,不可以使用 HTTP。

取消 SSL:filebrowser -d /etc/filebrowser.db config set --cert "" --key ""

当然,你也可以使用 Nginx 等 Web 服务器对 File Browser 进行反向代理,以达到 HTTPS 访问的目的。

还有就是使用 Caddy,这是一个开源、支持 HTTP/2 的 Web 服务器,它的一个显著特点就是默认启用 HTTPS 访问,会自己申请 SSL 证书,同时支持大量的插件,File Browser 就可以作为其插件运行。

赞(0)
转载请注明出处:咕鸽 » 做一个谷歌云端硬盘文件列表吧
分享到: 更多 (0)

谈笑风生 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址