[toc]
前言
由于国内的很多教育PT站都有新手考核,奈何电脑硬盘的小盒子已经被某站资源塞的满满的(100G的英语六级还有其他种种巴拉巴拉…)。
最近在某网站上看到一条GCP + Google Drive(Unlimited)进行云做种的帖子。正好目前新入的PT站支持v4做种(国内大多数的教育网PT站都不支持v4),于是在GCP上新开一台主机进行做种,给本地电脑减少压力。
Required:
- Google Cloud Platform (其他能正常访问Google Services的VPS也可以,但Google Drive的同步速度可能就没有那么快了)
- Google Drive (unlimited) (15G的就不要来凑热闹了,GCP上随便开个2T的也别这个方便,unlimited的获取方法自行Google/BaiDu)
VPS
VPS在GPC上选择最廉价的那一款,也就是0.6G共享CPU的哪个就够了,但是一定要记住,不要吝啬硬盘。
貌似0.6G共享的哪个性能真的超级差,推荐选择small规格的主机,内存至少给够1G,否则真的进入Transmission的控制台都得加载好久。
如果做5G以内的小种,10G即可,40多G的大种可能就需要至少100G的硬盘。虽然是通过挂载Google Drive的方式减少本地硬盘的压力,但是,缓存是逃避不了的问题。虽然我也考虑过直接关闭缓存,从Google Drive上获取文件,但是…transmission直接卡崩掉了,所以,不要吝啬硬盘。当然,如果硬盘足够便宜,也可以直接分一个几TB的大硬盘,这是当然是最好的。
操作系统选择Ubuntu(14/16/18)或者CentOS 7。我在此处选择了Ubuntu16.04 LTSB。
安装全程在root用户下进行,使用下列命令获取root权限。
sudo su
Rclone
安装Rclone
wget https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
chmod 0777 ./rclone-*/rclone
cp ./rclone-*/rclone /usr/bin/
rm -rf ./rclone-*
没有的命令就使用对应的安装方式安装,如果你真的不懂linux,那就放弃吧
配置Rclone
请注意以下文本中的注释区域(#标注)为重点区域。
rclone config
n) New remote # 新建配置
s) Set configuration password # 设置配置文件密码
q) Quit config # 退出配置
n/s/q> n # 输入n,新建配置
name> example # name随便输入,但后续挂在的时候会使用到
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 a existing remote
\ "alias"
3 / Amazon Drive
\ "amazon cloud drive"
4 / Amazon S3 Compliant Storage Providers (AWS, Ceph, Dreamhost, IBM COS, Minio)
\ "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 / Local Disk
\ "local"
16 / Mega
\ "mega"
17 / Microsoft Azure Blob Storage
\ "azureblob"
18 / Microsoft OneDrive
\ "onedrive"
19 / OpenDrive
\ "opendrive"
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
\ "swift"
21 / Pcloud
\ "pcloud"
22 / QingCloud Object Storage
\ "qingstor"
23 / SSH/SFTP Connection
\ "sftp"
24 / Webdav
\ "webdav"
25 / Yandex Disk
\ "yandex"
26 / http Connection
\ "http"
Storage> 12 # 选择Google Drive
** See help for drive backend at: https://rclone.org/drive/ **
Google Application Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> # 留空不填
Google Application Client Secret
Leave blank normally.
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 # 选择1,完全写入模式
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 or Y didn't work
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?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=***************************
# 将链接复制到浏览器,获得Google Drive对rclone的访问授权
Log in and authorize rclone for access
Enter verification code> *************************** # 输入从浏览器上获取的访问授权码
Configure this as a team drive?
y) Yes
n) No
y/n> y # 输入y,作为一个团队设备,哪怕是个人用户也选择y
Fetching team drive list...
No team drives found in your account--------------------
[example]
type = drive
scope = drive
token = {"access_token":"****************************************************************","token_type":"********","refresh_token":"************************************************************************,"expiry":"2019-01-01T00:00:00.00000000z"}
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y # 输入y,结束配置
Current remotes:
Name Type
==== ====
example 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,退出配置
挂载Google Drive
- 新建挂载点
mkdir -p -m 777 /home/example/GoogleDrive
- 挂载Google Drive
rclone mount example:/share /home/example/GooleDrive --allow-non-empty --allow-other --vfs-cache-mode writes & # example 为rclone配置文件的名称 # /share 指定GoogleDrive中的share文件夹为根目录 # /home/example/GoogleDrive 为本地的挂载点
- 查看挂载
df -h
Filesystem Size Used Avail Use% Mounted on udev 280M 0 280M 0% /dev tmpfs 59M 2.1M 57M 4% /run /dev/sda1 97G 2G 95G 2% / tmpfs 291M 0 291M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 291M 0 291M 0% /sys/fs/cgroup example:share 1.0P 0G 1.0P 0% /home/example/GoogleDrive # 如果存在此条记录说明挂载成功 tmpfs 59M 0 59M 0% /run/user/1001
- 开机自动启动
vi rcloned
将下列代码粘贴到rcloned中,然后修改文件内如下内容,保存退出。
NAME=”” #[name]
REMOTE=” #[google drive dir]
LOCAL=” #[mount dir]#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH NAME_BIN="rclone" ### BEGIN INIT INFO # Provides: rclone # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start rclone at boot time # Description: Enable rclone by daemon. ### END INIT INFO NAME="" # rclone name名 REMOTE='' # 远程文件夹 LOCAL='' # 挂载地址 Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" Info="${Green_font_prefix}[信息]${Font_color_suffix}" Error="${Red_font_prefix}[错误]${Font_color_suffix}" RETVAL=0 check_running(){ PID="$(ps -C $NAME_BIN -o pid= |head -n1 |grep -o '[0-9]\{1,\}')" if [[ ! -z ${PID} ]]; then return 0 else return 1 fi } do_start(){ check_running if [[ $? -eq 0 ]]; then echo -e "${Info} $NAME_BIN (PID ${PID}) 正在运行..." && exit 0 else fusermount -zuq $LOCAL >/dev/null 2>&1 mkdir -p $LOCAL # sudo /usr/bin/rclone mount $NAME:$REMOTE $LOCAL --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 >/dev/null 2>&1 & sudo /usr/bin/rclone mount $NAME:$REMOTE $LOCAL --allow-non-empty --allow-other --vfs-cache-mode writes >/dev/null 2>&1 & sleep 2s check_running if [[ $? -eq 0 ]]; then echo -e "${Info} $NAME_BIN 启动成功 !" else echo -e "${Error} $NAME_BIN 启动失败 !" fi fi } do_stop(){ check_running if [[ $? -eq 0 ]]; then kill -9 ${PID} RETVAL=$? if [[ $RETVAL -eq 0 ]]; then echo -e "${Info} $NAME_BIN 停止成功 !" else echo -e "${Error} $NAME_BIN 停止失败 !" fi else echo -e "${Info} $NAME_BIN 未运行" RETVAL=1 fi fusermount -zuq $LOCAL >/dev/null 2>&1 } do_status(){ check_running if [[ $? -eq 0 ]]; then echo -e "${Info} $NAME_BIN (PID $(echo ${PID})) 正在运行..." else echo -e "${Info} $NAME_BIN 未运行 !" RETVAL=1 fi } do_restart(){ do_stop do_start } case "$1" in start|stop|restart|status) do_$1 ;; *) echo "使用方法: $0 { start | stop | restart | status }" RETVAL=1 ;; esac exit $RETVAL
mv rcloned /etc/init.d/rcloned chmod +x /etc/init.d/rcloned vim /etc/rc.local # 在末尾加入bash /etc/init.d/rcloned start chmod +x /etc/rc.d/rc.local
Rclone结语
至此,Rclone配置结束,文字内容偏多,还请耐心阅读。
Transmission
安装Transmission
apt-get update
apt-get install transmission-cli transmission-common transmission-daemon
/etc/init.d/transmission-daemon start
/etc/init.d/transmission-daemon stop
配置Transmission
配置transmission之前一定要先结束transmission的进程,否则配置无法保存。
vim /etc/transmission-daemon/settings.json
主要修改以下几个地方:
"rpc-authentication-required": true, # 打开用户权限验证
"rpc-enabled": true, # 默认开启不用做修改
"rpc-password": "mypassword", # 用户密码
"rpc-username": "mysuperlogin", # 用户名
"rpc-whitelist-enabled": false, # ip访问白名单关闭
"rpc-whitelist": "0.0.0.0", # 默认不做修改
/etc/init.d/transmission-daemon start
开始使用Transmissin
浏览器中访问输入 ip:9091访问transmission控制台,VPS一定要开放9091端口,否则无法访问。
下载的时候,选择路径为Google Drive的挂载点即可直接下载种子到Google Drive中
躺坑记录
- transmission的下载速度和上传速度不太快,否则可能会导致transmission卡死。主要是由于Google Drive需要时间去同步导致的,下载速度和上传速度大致在1024kb即可。
-
centos没有默认安装fusermount,会导致rclone的挂载操作出现报错,使用
yum install fusermount
安装即可解决
-
rclone会在本地磁盘上建立缓存,缓存一定时候会清理,大概是在种子不再使用或者其他新种需要空间的时候会自动清理,所以无需管空间占用的问题,但是要注意的是,同时下载多个种子的时候,一定要注意提前预算好空间,否则可能会导致transmission卡死。
-
不要轻易直接wget别人的配置文件来用,即便是要使用也要仔细理解到底是什么。上文中提到的rclone开机自动启动的配置部分,最开始是使用的别人的配置,结果发现重启vps以后,会导致下载种子出现illegal seek的报错。结果发现是使用了别人的配置导致开机重新挂载的时候出现了问题。
不过本文已经修复了这个问题。大可放心食用。
-
不要吝啬磁盘空间,一定要把缓存区域留够,一般100G就可以了,大概在4美刀左右。
结语
至此,配置结束。如果需要flexGet插件的,自行Google/BaiDu。
目前你已经可以开始愉快的做种和下载种子了,但是一定记住,不要下载有色动作片或者违禁资源到Google Drive里,否则,嘿嘿嘿嘿嘿….反正教育网做种,有的仅是电视节目和学习的辅助资料。
后续
经过近乎10多天的实践,0.6G内存1vCPU的哪个主机也完全没有问题。导致vps占用出奇高的原因仅仅只是因为IO瓶颈。经过实际测试发现,如果是直接将BT下载到挂载到本地的GD中,会导致VPS卡死等问题。所以最好的办法就是通过transmission+flexget的办法,先将种子下载到本地,然后移动到挂载到本地的GD中。这样做的好处就是种子还在本地,可以有几乎获得一定的上传量,如果种子已经转移到了GD中,可以靠挂种得交易性标志物(如魔力豆、沙粒等等玩意),因为貌似进入了GD的文件,不会因为做种请求就再拉取到本地,你的服务器也不能当一个中转帮你直接从GD上拉取文件,但能依靠挂种获得交易性标志物也很不错啦,毕竟上传量和下载量都可以通过这些东西兑换。