Rclone+Google Drive+Plex/Jellyfin/Kodexplorer 搭建媒体服务器

发布于 2019-03-17  8.31k 次阅读


周末任务,安装Rclone挂载GDrive,搭媒体库看看效果,可行就省得下载完上传Onedrive了(目前Onedrive上传有点慢)。
周六晚开始部署,目标是用服务器下载资源(因为服务器带宽很大,下载起来无敌爽)后,将文件转移到本地挂载的Gdrive网络硬盘,再通过搭建媒体服务器实现在线播放。方案就是Rclone + Gdrive + Plex/Jellyfin/Kodexplorer .
[su_note][/su_note]

[su_heading size="16" align="left"]安装Rclone[/su_heading]

Rclone是一款强大的网盘挂载工具,支持数十种类型的网盘,将网盘挂载到本地文件系统就可以随意挥霍服务器空间啦。

项目地址:https://github.com/ncw/rclone

CentOs 下安装方法:

curl https://rclone.org/install.sh | sudo bash
yum install fuse -y

初始化配置:

rclone config

以下为配置参考:

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> n     #选n,新建
name> Mo     	#名称,随意,后面有用
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 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 / 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    #选择自己的网盘类型,我这次要挂载的是GoogleDrive
** 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
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=xxxxxxxxxx.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=xxxxxxxxxxxxxxxxx
Log in and authorize rclone for access
Enter verification code> xxxxx    #复制上面的链接到浏览器打开,填入获取到的验证码(自行科学)
Configure this as a team drive?
y) Yes
n) No
y/n> y  #选择y
Fetching team drive list...
No team drives found in your account--------------------
[Mo]
client_id = 
client_secret = 
service_account_file = 
token = {"access_token":"xxxxxxxxx"}
team_drive = 
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  #选择y
Current remotes:

Name                 Type
====                 ====
Mo                 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:Folder LocalFolder , DriveName 是上面填的的 name(我的是Mo),Folder 是 Google Drive 里的文件夹,LocalFolder 是服务器上的本地文件夹。

/usr/bin/rclone mount DriveName:Folder LocalFolder \
 --umask 0000 \
 --default-permissions \
 --allow-non-empty \
 --allow-other \
 --transfers 4 \
 --buffer-size 32M \
 --low-level-retries 200 \
 --dir-cache-time 12h \
 --vfs-read-chunk-size 32M \
 --vfs-read-chunk-size-limit 1G

挂载成功,df -hT 查看:

Rclone+Google Drive+Plex/Jellyfin/Kodexplorer 搭建媒体服务器

以前申请的美国西南学院教育邮箱含无限量Google Drive,挂载一看1PB,随便用...

开机自启动:

一样修改DriveName:Folder LocalFolder,然后全部复制进ssh执行。

cat > /etc/systemd/system/rclone.service <<EOF
[Unit]
Description=Rclone
AssertPathIsDirectory=LocalFolder
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount DriveName:Folder LocalFolder \
 --umask 0000 \
 --default-permissions \
 --allow-non-empty \
 --allow-other \
 --buffer-size 32M \
 --dir-cache-time 12h \
 --vfs-read-chunk-size 64M \
 --vfs-read-chunk-size-limit 1G
ExecStop=/bin/fusermount -u LocalFolder
Restart=on-abort
User=root

[Install]
WantedBy=default.target
EOF

启动(CentOs 7):

systemctl start rclone

开机自启:

systemctl enable rclone

[su_heading size="16" align="left"]安装Plex或Jellyfin[/su_heading]

Plex

Plex 介绍:

Plex 是一款功能和客户端相当齐全的家庭媒体库应用,可进行转码和在线播放,索引和自动拉取IMBD影片信息。

官方网址:https://www.plex.tv

安装:

下载 Plex Media Server :https://www.plex.tv/zh/media-server-downloads/,选择自己的系统下载对应的安装包。

Centos  7:

wget https://downloads.plex.tv/plex-media-server-new/1.15.1.791-8bec0f76c/redhat/plexmediaserver-1.15.1.791-8bec0f76c.x86_64.rpm

yum install plexmedia*.rpm

启动和设置自启:

systemctl start plexmediaserver

systemctl enable plexmediaserver

启动后就可以通过 http://IP:32400 进行访问(如有防火墙请自行开放端口)。

然后安装在服务器有个坑,Plex首次不允许远程访问,进去会显示找不到服务器。

解决方法:

使用Putty设置ssh端口转发,打开Putty,Session先填好服务器Ip,到 Connection--SSH--Tunnels 设置端口转发,Source port 填一个本地端口,Destination 填 127.0.0.1:32400,如下图:

Rclone+Google Drive+Plex/Jellyfin/Kodexplorer 搭建媒体服务器

之后火狐浏览器设置手动代理,访问http://localhost:2019/web (没错就是localhost),进入后设置账户密码,然后 设置--远程访问--启用远程访问 

设置完后即可关掉ssh端口转发,以后都通过 http://IP:32400 访问就行。有多余的域名反代32400端口就可以使用域名访问了。

添加媒体库,目录选Gdrive 挂载的文件夹,开始使用!

截图:

Rclone+Google Drive+Plex/Jellyfin/Kodexplorer 搭建媒体服务器

Jellyfin

Jellyfin也是一款很不错的媒体库应用,使用ffmpeg实时转码,也能拉取资源信息,开源免费。

项目地址:https://github.com/jellyfin/jellyfin

使用手册:https://jellyfin.readthedocs.io/en/latest/

安装:

Centos 7:

yum install libicu fontconfig -y
wget https://repo.jellyfin.org/releases/server/centos/jellyfin-10.2.2-1.el7.x86_64.rpm    #若版本更新请自行更换下载地址
yum install  -y  jellyfin-10.2.2-1.el7.x86_64.rpm     

启动和自启动:

systemctl start  jellyfin
systemctl enable jellyfin

启动后访问 http://IP:8096 即可(如有防火墙请放行8096端口)。

安装ffmpeg:

Jellyfin播放视频时需要用ffmpeg实时转码,所以还需要安装ffmpeg并在Jellyfin设置里填上ffmpeg文件夹路径。

wget https://ley.best/media/ffmpeg.tar.gz

tar -xvf ffmpeg.tar.gz

cp ffmpeg/ffmpeg  /usr/bin/

然后到Jellyfin 控制台--转码--FFmpeg 路径 填入 刚才ffmpeg的文件夹路径(/root/ffmpeg) ,保存。

添加媒体库,填入Gdrive挂载路径,开始玩耍!

[su_heading size="16" align="left"]使用体验[/su_heading]

Rclone比想象中好用,文件传到Google Drive的速度在30~40MB/s 左右,基本跑满上传带宽了,很强!(接下来必须挂载Onedrive看看速度,现在的上传方式速度很不理想,如果也是三十四兆的速度,emmm爽哭)

两种媒体库功能都很强大,就是全都实时转码,看视频时单核CPU都得飚满,所以单核的服务器体验就不是很好,但是本地也可以搭成家庭媒体库,普通电脑应该都能跑得好好的,自己也有公网IP,改天自己电脑搭个玩玩。另外Plex还可以装进NAS。

于是,因为转码的关系体验一般,那就想一个不转码的在线播放方案,试了几个最后选了可道云。

可道云

可道云,可用来协同办公的私人云存储,功能也不错。可以用来在线播放音乐和视频。可道云有个离线下载可以下载直链还挺好用的,我还拿来下github zip,国内GitHub速度你懂的,下完再从可道云下载到本地。

更多介绍看官网:https://kodcloud.com/

安装方法(linux下)官方也给得很详细:http://bbs.kodcloud.com/thread-1-1-1.html

我自己有lnmp环境了,直接将可道云安装包解压丢进网站目录就能使用了。

然后,可道云目录在网站目录里,也就是用户data目录也在里面(不能任意指定),而Rclone挂载的Gdrive在其他目录,读取不到啊。

想个办法,我用 mount --bind(很很好用这个东西)将Gdrive目录绑定挂载到可道云的用户data目录,解决。

然后试试播放效果,还挺好用的!

截图:

Rclone+Google Drive+Plex/Jellyfin/Kodexplorer 搭建媒体服务器
[su_heading size="16" align="left"]总结[/su_heading]
Rclone挂载Google Drive效果很不错(国内是访问不了GDrive的,所以之前也一直闲置着,现在通过服务器中转一次就没得问题了),接下来也试试挂载Onedrive试试速度,Plex和Jellyfin功能齐全,解码吃U,单U就算了,局域网或有公网IP可以用用。想搭私有云的话可以试试可道云,其他的私有云也挺多的,nextcloud, owncloud, seafile, kiftd等等。

现在使用aria2下载电影,人人影视linux端下载美剧到服务器,速度10~40MB/s,下载完脚本自动将影片通过Rclone转至Gdrive,速度30~40MB/s,用可道云在线观看,体验还是不错的。

周末任务完成~