国内网盘这几年的表现,说实话,真的让人不敢把重要资料放上去。折腾来折腾去,要么限速卡成狗,要么文件被无故和谐,更离谱的是直接跑路。如果非要矮子里拔将军,115算勉强能用的,但价格贵得离谱,而且谁也不知道它能撑多久。相比之下,国外网盘虽然免费容量有限、扩容要付费,但胜在安全稳定——数据无价,这点钱花得值。
说到操作国外网盘,就不得不提Rclone。这是GitHub上的一个开源命令行工具,专门负责在Linux服务器中上传、下载、同步国外主流网盘,堪称神器。它支持的服务商非常全:Google Drive、Amazon S3、Openstack Swift / Rackspace Cloud Files / Memset Memstore、Dropbox、Google Cloud Storage、Amazon Drive、Microsoft OneDrive、Hubic、Backblaze B2、Yandex Disk,甚至本地文件系统也能管。
下午在局域网里用一台CentOS 7的服务器试了一把,运行Rclone命令操作Google Drive上的文件,上传下载速度都相当理想。下面把安装配置的完整过程记录下来,供有同样需求的朋友参考。
一、下载解压Rclone
首先用curl下载最新的Linux 64位压缩包:
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
如果系统没有装unzip,先装上:
yum install unzip -y
然后解压并进入目录:
unzip rclone-current-linux-amd64.zip cd rclone-v1.35-linux-amd64
二、复制二进制文件
将解压出来的rclone可执行文件复制到系统路径,设置合适的权限:
cp rclone /usr/sbin/ chown root:root /usr/sbin/rclone chmod 755 /usr/sbin/rclone
三、安装man手册页
为了方便查看帮助文档,可以安装manpage:
mkdir -p /usr/local/share/man/man1 cp rclone.1 /usr/local/share/man/man1/ mandb
四、新建rclone config文件
运行配置命令:
rclone config
首次运行会提示配置文件不存在,自动创建。之后会进入交互式配置界面,显示当前没有远程存储,询问是否创建新配置:
2017/03/02 14:25:41 Config file "/root/.rclone.conf" not found - using defaults No remotes found - make a new one n) New remote s) Set configuration password q) Quit config
输入n创建一个新的远程配置。然后给配置取个名字,这里用googledrive:
name> googledrive
接着选择存储类型,Rclone支持多种网盘。输入对应数字即可,这里选Google Drive,回复7:
Type of storage to configure. Choose a number from below, or type in your own value 1 / Amazon Drive \ "amazon cloud drive" 2 / Amazon S3 (also Dreamhost, Ceph, Minio) \ "s3" 3 / Backblaze B2 \ "b2" 4 / Dropbox \ "dropbox" 5 / Encrypt/Decrypt a remote \ "crypt" 6 / Google Cloud Storage (this is not Google Drive) \ "google cloud storage" 7 / Google Drive \ "drive" 8 / Hubic \ "hubic" 9 / Local Disk \ "local" 10 / Microsoft OneDrive \ "onedrive" 11 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH) \ "swift" 12 / Yandex Disk \ "yandex"
接下来提示输入Google Application Client Id和Client Secret,留空直接回车即可,Rclone会使用默认的公共应用ID:
Google Application Client Id - lea ve blank normally. client_id> Google Application Client Secret - lea ve blank normally. client_secret>
然后会询问是否使用自动配置。在服务器上(无图形界面)需要选择n手动授权:
Remote config Use auto config? * Say Y if not sure * Say N if you are working on a remote or headless machine or Y didn't work y) Yes n) No y/n> n
选择n之后,会显示一个授权链接。把这个链接复制到本地浏览器的地址栏中打开,用Google账号登录并授权:
If your browser doesn't open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?client_id=202266665644.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=88888c7be7969e4f5dd4cf1619265571 Log in and authorize rclone for access Enter verification code>
授权成功后,会得到一串验证码(例如4/oCKeWj4v6tnl9jfdkfjdsk3q8emfxRuZ5HEn49pJ740KJk),将它粘贴到终端中回车确认。
之后Rclone会显示配置信息,询问是否正确:
[googledrive]
client_id =
client_secret =
token = {"access_token":"ya29.GlsCBKS2rJqd_YuroyWklklklklklklSPPISs58WMJCm54DauJ_QeZudvKTTUOZ4fS09mt5wqcAggfdgdfmAqojdaTTJv-ukAoC_q0lgdfgfdtSv4yn_yEtaEtG","token_type":"Bearer","refresh_token":"1/5Tv8KqnjWb_oTtO7QDm2umcRQgfgfdgdfgfKMJIOC7dkU","expiry":"2017-03-02T15:42:10.847395882+08:00"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y
输入y确认。最后会回到主菜单,此时已经可以看到配置好的远程存储googledrive。输入q退出配置:
Current remotes: Name Type ==== ==== googledrive drive e) Edit existing remote n) New remote d) Delete remote s) Set configuration password q) Quit config e/n/d/s/q> q
至此,Rclone的安装与Google Drive配置就完成了。接下来就可以用rclone ls googledrive:列出文件,用rclone copy或rclone sync进行上传下载操作了。
