使用rclone挂载onedrive搭建影音服务器

使用rclone挂载onedrive充当本地硬盘,搭建plex影音服务器。不仅可以省下硬盘购买费用,速度还相当不错。下面就一起来折腾吧。本次我使用的是debian11 - x86 系统,理论上任何系统都可以完成此次项目的搭建。媒体服务器则采用了常见的plex及emby。下面就一起来折腾吧。

一键安装rclone及plex代码

注意:此代码有时效性,仅适用于emby 6.7.0.及plex,如需安装最新版本,请看下列教程。

运行完成一键安装指令,可以跳转到rclone配置目录

安装rclone、plex及emby

apt-get update && apt-get install -y fuse && curl https://rclone.org/install.sh | sudo bash && wget https://downloads.plex.tv/plex-media-server-new/1.28.2.6106-44a5bbd28/debian/plexmediaserver_1.28.2.6106-44a5bbd28_amd64.deb && dpkg -i plexmediaserver_1.28.2.6106-44a5bbd28_amd64.deb && wget https://github.com/MediaBrowser/Emby.Releases/releases/download/4.7.6.0/emby-server-deb_4.7.6.0_amd64.deb && dpkg -i emby-server-deb_4.7.6.0_amd64.deb

安装rclone、plex

apt-get update && apt-get install -y fuse && curl https://rclone.org/install.sh | sudo bash && wget https://downloads.plex.tv/plex-media-server-new/1.28.2.6106-44a5bbd28/debian/plexmediaserver_1.28.2.6106-44a5bbd28_amd64.deb && dpkg -i plexmediaserver_1.28.2.6106-44a5bbd28_amd64.deb

安装rclone、emby

apt-get update && apt-get install -y fuse && curl https://rclone.org/install.sh | sudo bash && wget https://github.com/MediaBrowser/Emby.Releases/releases/download/4.7.6.0/emby-server-deb_4.7.6.0_amd64.deb && dpkg -i emby-server-deb_4.7.6.0_amd64.deb

安装rclone及其使用环境

更新软件安装源及安装fush

新版本rclone需要fuse3,具体说明请访问rclone issues

apt-get update && apt-get install -y fuse fuse3

安装rclone

官方提供了一键安装代码,直接运行就好

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

安装emby

下载emby

首先打开emby官网,找到官网安装教程,跳转到Debian系统 - 点此跳转emby官网

复制emby最新安装包链接地址,本篇文章采用的是emby 4.7.6.0

进入shell窗口,按下面所示,运行次命令

wget https://github.com/MediaBrowser/Emby.Releases/releases/download/4.7.6.0/emby-server-deb_4.7.6.0_amd64.deb

安装emby

运行dpkg安装emby。注意:此处的名称需和上步下载的安装包对应

dpkg -i emby-server-deb_4.7.6.0_amd64.deb

安装plex

下载plex

首先打开plex官网,找到官网下载,跳转到Linux系统下的Plex Media Server安装地址 - 点此跳转

复制pelx最新安装包链接地址,本篇文章采用的是plex - 1.28.2.6106-44a5bbd28

image-20220829221856461

进入shell窗口,按下面所示,运行次命令

wget https://downloads.plex.tv/plex-media-server-new/1.28.2.6106-44a5bbd28/debian/plexmediaserver_1.28.2.6106-44a5bbd28_amd64.deb

安装plex

运行dpkg安装plex。注意:此处的名称需和上步下载的安装包对应

dpkg -i plexmediaserver_1.28.2.6106-44a5bbd28_amd64.deb

配置rclone

准备工作

rclone挂载OneDrive需要使用到OneDrive授权密钥,需要使用rclone客户端进行获取

首先进入rclone官网,下载适合自己系统版本的客户端,我所使用的系统为win10 64 位系统,所以下载win版本客户端软件

解压此压缩包,注意:此软件不能直接打开

打开cmd或者powershell,进入刚刚解压过的文件夹内

cd D:\rclone-v1.59.1-windows-amd64
./rclone authorize "onedrive"

image-20220829223733270

此时,浏览器会自动打开,请登录需要挂载的微软账号,按网页指示完成授权

当网页出现Success!时,代表已经成功授权。返回powershell,你会看到如下的密钥,密钥包含{xxx}所有内容,复制此密钥,保存备用

image-20220829224229693

配置rclone

输入rclone config进入配置rclone

root@aaaavos:~# rclone config
 NOTICE: Config file "/root/.config/rclone/rclone.conf" not f                                                                              ound - using defaults
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n             ### 新建一个rclone配置

Enter name for new remote.
name> onedrive       ### 输入新rclone名字

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ (fichier)
 2 / Akamai NetStorage
   \ (netstorage)
 3 / Alias for an existing remote
   \ (alias)
 4 / Amazon Drive
   \ (amazon cloud drive)
 5 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, China Mobile, Cloudflare, ArvanCloud, Digital Ocean, Dreamhost, Huawei OBS, IBM COS, IDrive e2, Lyve Cloud, Minio, Netease, RackCorp, Scaleway, SeaweedFS, StackPath, Storj, Tencent COS and Wasabi
   \ (s3)
 6 / Backblaze B2
   \ (b2)
 7 / Better checksums for other remotes
   \ (hasher)
 8 / Box
   \ (box)
 9 / Cache a remote
   \ (cache)
10 / Citrix Sharefile
   \ (sharefile)
11 / Combine several remotes into one
   \ (combine)
12 / Compress a remote
   \ (compress)
13 / Dropbox
   \ (dropbox)
14 / Encrypt/Decrypt a remote
   \ (crypt)
15 / Enterprise File Fabric
   \ (filefabric)
16 / FTP
   \ (ftp)
17 / Google Cloud Storage (this is not Google Drive)
   \ (google cloud storage)
18 / Google Drive
   \ (drive)
19 / Google Photos
   \ (google photos)
20 / HTTP
   \ (http)
21 / Hadoop distributed file system
   \ (hdfs)
22 / HiDrive
   \ (hidrive)
23 / Hubic
   \ (hubic)
24 / In memory object storage system.
   \ (memory)
25 / Internet Archive
   \ (internetarchive)
26 / Jottacloud
   \ (jottacloud)
27 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
28 / Local Disk
   \ (local)
29 / Mail.ru Cloud
   \ (mailru)
30 / Mega
   \ (mega)
31 / Microsoft Azure Blob Storage
   \ (azureblob)
32 / Microsoft OneDrive
   \ (onedrive)
33 / OpenDrive
   \ (opendrive)
34 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ (swift)
35 / Pcloud
   \ (pcloud)
36 / Put.io
   \ (putio)
37 / QingCloud Object Storage
   \ (qingstor)
38 / SSH/SFTP
   \ (sftp)
39 / Sia Decentralized Cloud
   \ (sia)
40 / Storj Decentralized Cloud Storage
   \ (storj)
41 / Sugarsync
   \ (sugarsync)
42 / Transparently chunk/split large files
   \ (chunker)
43 / Union merges the contents of several upstream fs
   \ (union)
44 / Uptobox
   \ (uptobox)
45 / WebDAV
   \ (webdav)
46 / Yandex Disk
   \ (yandex)
47 / Zoho
   \ (zoho)
48 / premiumize.me
   \ (premiumizeme)
49 / seafile
   \ (seafile)
Storage>  32     ### 输入OneDrive代码

Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_id>      ### 回车

Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret>   ### 回车

Option region.
Choose national cloud region for OneDrive.
Choose a number from below, or type in your own string value.
Press Enter for the default (global).
 1 / Microsoft Cloud Global
   \ (global)
 2 / Microsoft Cloud for US Government
   \ (us)
 3 / Microsoft Cloud Germany
   \ (de)
 4 / Azure and Office 365 operated by 21Vianet in China
   \ (cn)
region>   ### 回车默认或按OneDrive账号选择

Edit advanced config?
y) Yes
n) No (default)
y/n> n   ### 填入n

Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine

y) Yes (default)
n) No
y/n> n   ### 填入 n

Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
        rclone authorize "onedrive"
Then paste the result.
Enter a value.
config_token>    ### 刚刚准备的密钥 ,完整复制
Option config_type.
Type of connection
Choose a number from below, or type in an existing string value.
Press Enter for the default (onedrive).
 1 / OneDrive Personal or Business
   \ (onedrive)
 2 / Root Sharepoint site
   \ (sharepoint)
   / Sharepoint site name or URL
 3 | E.g. mysite or https://contoso.sharepoint.com/sites/mysite
   \ (url)
 4 / Search for a Sharepoint site
   \ (search)
 5 / Type in driveID (advanced)
   \ (driveid)
 6 / Type in SiteID (advanced)
   \ (siteid)
   / Sharepoint server-relative path (advanced)
 7 | E.g. /teams/hr
   \ (path)
config_type> 1  ### 选择1 

Option config_driveid.
Select drive you want to use
Choose a number from below, or type in your own string value.
Press Enter for the default (b4f254d3a2d9d97c).
 1 /  (xxxxxxxx)
   \ (xxxxxxxxxxxxxxx)
config_driveid> 1  ### 按前面序号选择

Found drive 'root' of type 'business', URL: https://xxxxxx-my.sharepoint.com/personal/xxxxxxx/Documents
Is that okay?
y) Yes
n) No
y/n> y    ### 选y
--------------------
[onedrive]
type = onedrive
token = {"XXXXXXXX"}
drive_id = XXXXXXXXX
drive_type = business
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  ###  选y
Current remotes:

Name                 Type
====                 ====
onedrive               onedrive

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,退出

挂载为本地磁盘

新建一个本机下的存储路径,任意位置均可,此处我新建在根目录下

mkdir /onedrive

给予读写权限

chmod -R 777 /onedrive

挂载为本地磁盘

#挂载
rclone mount <网盘名称:网盘路径> <本地路径> [参数] --daemon

#取消挂载
fusermount -qzu <本地路径>

例子

rclone mount onedrive:/ /onedrive --copy-links --allow-other --allow-non-empty --umask 000 --daemon

使用df -h命令查看挂载是否完成

root@debian:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           384M   15M  369M   4% /run
/dev/sda1        38G  3.1G   33G   9% /
tmpfs           1.9G  4.0K  1.9G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda15      121M  138K  120M   1% /boot/efi
onedrive:       5.0T   42G  5.0T   1% /onedrive   ###这就是挂载的网盘
tmpfs           384M     0  384M   0% /run/user/1000
tmpfs           384M     0  384M   0% /run/user/0

配置开机自动挂载

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

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount onedrive:/ /onedrive \   ##此处按需修改 ,前面是配置文件,后面是挂载路径
--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

设置开机自启

systemctl enable rcloned

emby配置

在浏览器输入ip:8096进入emby配置后台,按网页指引一步步配置

进入后台,找到播放页面,设置原画播放

image-20220829232119238

plex配置

plex和emby不同的是,它第一次登录需要本地环境登录配置,对于不在本地的服务器来说,第一次登录需要配置ssh隧道,来帮助我们配置plex

ssh -L [LOCAL_IP:]LOCAL_PORT:DESTINATION:DESTINATION_PORT [USER@]SSH_SERVER

示例

ssh -L 127.0.0.1:22222:127.0.0.1:32400 [email protected]

如果你使用的ssh软件支持ui设置ssh隧道,例如MobaXterm

image-20220829233047785

image-20220829233115967

image-20220829233251456

此时,打开浏览器,输入127.0.0.1:32400/web即可访问plex

登录账号,按指引完成登录

进入plex后台

image-20220829234115737

添加资料库

image-20220829234147352

禁用转码

image-20220829234258994