自建媒体库亮点

将谷歌云盘挂载到vps上,然后在服务器上搭建emby媒体服务与谷歌云盘绑定,这样就可以把谷歌云盘当作媒体资源库。再配合aria2离线转存到谷歌云盘,轻松实现搜刮资源到emby媒体库。这样下载资源以及观看十分方便,只需要一台vps和云盘(无需nas)就可以拥有自己的媒体库。

搭建

使用rclone将Google Drive挂载到vps上

  1. 安装rclone

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

    rclone config
  3. 使用rclone挂载Google Drive大致流程
No remotes found - make a new one
 n) New remote
 s) Set configuration password
 q) Quit config
 n/s/q> n #输入n
 name> gdrive  #名称随便填
 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 / 1Fichier
    \ "fichier"
  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 / Citrix Sharefile
    \ "sharefile"
  9 / Dropbox
    \ "dropbox"
 10 / Encrypt/Decrypt a remote
    \ "crypt"
 11 / FTP Connection
    \ "ftp"
 12 / Google Cloud Storage (this is not Google Drive)
    \ "google cloud storage"
 13 / Google Drive
    \ "drive"
 14 / Google Photos
    \ "google photos"
 15 / Hubic
    \ "hubic"
 16 / JottaCloud
    \ "jottacloud"
 17 / Koofr
    \ "koofr"
 18 / Local Disk
    \ "local"
 19 / Mail.ru Cloud
    \ "mailru"
 20 / Mega
    \ "mega"
 21 / Microsoft Azure Blob Storage
    \ "azureblob"
 22 / Microsoft OneDrive
    \ "onedrive"
 23 / OpenDrive
    \ "opendrive"
 24 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
    \ "swift"
 25 / Pcloud
    \ "pcloud"
 26 / Put.io
    \ "putio"
 27 / QingCloud Object Storage
    \ "qingstor"
 28 / SSH/SFTP Connection
    \ "sftp"
 29 / Transparently chunk/split large files
    \ "chunker"
 30 / Union merges the contents of several remotes
    \ "union"
 31 / Webdav
    \ "webdav"
 32 / Yandex Disk
    \ "yandex"
 33 / http Connection
    \ "http"
 34 / premiumize.me
    \ "premiumizeme"
 Storage> 13 #选择13,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> 1 #输入1
 ID of the root folder
 Leave blank normally.
 Fill in to access "Computers" folders (see docs), or for rclone to use
 a non root folder as its starting point.
 Note that if this is blank, the first time rclone runs it will fill it
 in with the ID of the root folder.
 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=202264815644.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=tZzSXMvZc8iu0lYFB4ANBw
 Log in and authorize rclone for access
 Enter verification code>  #打开以上链接,登录要绑定的Google,此处输入活动的Code
 Configure this as a team drive?
 y) Yes
 n) No
 y/n> y   #如果你的是团队盘,则输入y,否则n
 Fetching team drive list…
 Choose a number from below, or type in your own value
 1 / owejoij
 \ "0AMp-QeDCIy_mUk9PVA" 
 Enter a Team Drive ID> 1 #如果是团队盘,输入序号
 [gdrive]
 type = drive
 scope = drive
 token = {"access_token":"ya29.Il-2B5z7OPWyx59ZHw7__IemaHsR8VT7P__jUN27hnNXZtaj0Rk1HcWPGGt2xqjkJH3e2KaVWuwz1nvW20MT0rfmEd5XAMY-je7wzQWgdjuGaBn9-txOUGh2jkk_CYio2w","token_type":"Bearer","refresh_token":"1//03yKvDZ7SOc80CgYIARAAGAMSNwF-L9Irrptm9elmrbRA1jxPeBsodd2FZw0TG5Utj5dUXeEDxKgZcR2EkYy1D0_wpsWsmgCWDzg","expiry":"2019-12-24T03:17:54.135381482-05:00"}
 team_drive = 0AMp-QeDCIy_mUk9PVA
 y) Yes this is OK
 e) Edit this remote
 d) Delete this remote
 y/e/d> y #输入y
 Current remotes:
 Name                 Type
 ====                 ====
 gdrive               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退出,如果要继续绑定,输入y重复以上步骤

Google Drive的token获取

新版本的rclone不会跳出Google Drive授权链接,因此需要下载Windows版本的rclone在Windows电脑上获取授权token,大致流程如下:

  • 访问rclone官网,下载Windows版本的rclone
  • rclone解压后,打开cmd控制台界面路径定位到rclone.exe,执行Google Drive授权命令:

    rclone authorize "drive"


这里也可以选中路径输入cmd回车快捷打开命令行窗口

  • 此时浏览器会打开Google Drive授权界面按照提示操作即可,最后提示授权成功后,回到cmd控制台即可查看到授权token

控制台的授权代码复制整个花括号内(包含花括号)
请输入图片描述

注意这个授权过段时间有可能过期,发现挂载好的Google Drive突然没了需要重新获取授权编辑已经rclone好的Google Drive

  1. 将Google Drive挂载到vps指定目录
  • 这里我们假设将云盘挂载到vps根目录下的GoogleDrive目录上
    创建GoogleDrive目录
cd ~
 mkdir -p GoogleDrive
  • 创建rclone开机自启动rclone.service配置文件

创建配置文件

nano /usr/lib/systemd/system/rclone.service

写入:

[Unit]
Description = rclone
[Service]
User = root
ExecStart = /usr/bin/rclone mount gdrive: /GoogleDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
Restart = on-abort

[Install]
WantedBy = multi-user.target

ExecStart = /usr/bin/rclone mount gdrive: /GoogleDrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000中的/GoogleDrive是你要挂载到vps的目录路径,根据实际情况改动

  • 重载配置文件
systemctl daemon-reload
  • 设置rclone开机自启动
systemctl enable rclone
  • 重启rclone
systemctl restart rclone
  • 其他rclone常用命令
systemctl start rclone //启动rclone
systemctl stop rclone  //停止rclone
systemctl status rclone //查看rclone状态
  1. 最后查看Google Drive是否挂载成功
    执行如下命令:
df -h

看到下图代表成功:

注意rclone挂载的Google Drive过段时间突然掉的问题

  • 出现该问题可能是服务器时间问题,可以执行date命令查看服务器时间,如果不正确执行如下命令

    sudo cp  /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  • 时间同步后rclone重新编辑挂载的Google Drive,重新获取新的token替换掉失效的授权

rclone进阶

rclone进阶配置可参考这位大佬文章

搭建aria2离线下载服务

  1. 安装aria2一键增强脚本

    wget -N git.io/aria2.sh && chmod +x aria2.sh && ./aria2.sh
  2. 修改aria2.conf配置文件

    • 执行nano /root/.aria2c/aria2.conf命令打开aria2.conf文件进行编辑
    • 找到文件中on-download-complete=/root/.aria2c/clean.sh命令修改为on-download-complete=/root/.aria2c/upload.sh
  3. 修改script.conf配置文件

    • 执行nano /root/.aria2c/script.conf命令打开script.conf文件进行编辑
    • 主要修改网盘名称和挂载Google Drive的根目录,如下
  4. 重启aria2服务

    service aria2 restart
  5. 测试aria2服务能否离线下载转存到Google Drive

    • 执行/root/.aria2c/upload.sh返回success代表aria2与Google Drive通信成功
    • 打开aria2网页服务(aria2安装成功返回的链接)添加一个文件地址下载文件测试
      (1)下载完成过段时间登录Google Drive查看有文件说明aria2离线转存Google Drive服务搭建成功。

    (2)如果没有文件需要安装jq,安装成功后重启服务器,命令如下:

    wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -ivh epel-release-latest-7.noarch.rpm
    yum repolist
    yum install jq
    //ubuntu执行
    sudo apt-get install jq
    //重启服务器
    reboot

拓展

docker搭建aria2

  • docker搭建aria2的优点
    (1)使用docker搭建aria2方便管理aria2服务

(2)最重要的作用可以在一台服务器上部署多个aria2服务并挂载多个网盘,然后把文件离线存储到不同网盘中。

  • 搭建大致流程
    (1)创建aria2docker镜像存放的位置
mkdir -p /root/data/docker_data/aria2-pro1
mkdir -p /root/data/docker_data/aria2-pro1/{config,downloads}    
cd /root/data/docker_data/aria2-pro1
chmod +x downloads
chmod +x config

(2)创建docker-compose.yml配置文件

//执行以下命令打开docker-compose.yml进行编辑
nano docker-compose.yml
//docker-compose内容如下
version: "3.8"

services:

Aria2-Pro:
  container_name: aria2-pro1
  image: p3terx/aria2-pro
  privileged: true
  environment:
    - PUID=$UID
    - PGID=$GID
    - UMASK_SET=022
    - RPC_SECRET=fdjfdsffd234 #这里是aria2的密钥自定义
    - RPC_PORT=6801           # aira2的端口自定义
    - LISTEN_PORT=6889        # bt的端口自定义
    - DISK_CACHE=64M
    - IPV6_MODE=false
    - UPDATE_TRACKERS=true
    - SPECIAL_MODE=rclone
    - TZ=Asia/Shanghai
  volumes:
    - /root/data/docker_data/aria2-pro1/config:/config
    - /root/data/docker_data/aria2-pro1/downloads:/downloads
    - /lib/modules:/lib/modules  //这里是映射fuse的指定文件,共享宿主机的指令
# If you use host network mode, then no port mapping is required.
# This is the easiest way to use IPv6 networks.
  network_mode: host
  restart: unless-stopped
  command: apk add fuse
# Since Aria2 will continue to generate logs, limit the log size to 1M to prevent your hard disk from running out of space.
  logging:
    driver: json-file
    options:
      max-size: 1m

(3)docker-compose.yml文件编辑好后执行如下命令启动容器

docker-compose up -d

(4)进入容器挂载并执行挂载网盘操作

 docker exec -it aria2-pro1 rclone config

(5)挂载网盘的操作同上述挂载Google Drive类似
(6)配置aria2服务同上述aria2配置类似,大致流程如下

docker exec -it aria2-pro1 /bin/bash  
# 使用如下两条命令各自编辑aria2.conf和script.conf配置文件,大致流程参照上面
nano /config/aria2.conf
nano /config/script.conf

(7)上述操作成功后,执行exit命令推出容器
(8)打开aria2ng客户端添加配置,aria2的端口号和密钥在docker-compose.yml文件中获取。

  • 更新aria2
cd /root/data/docker_data/aria2-pro1
docker-compose pull
docker-compose up -d
  • 卸载aria2

    cd /root/data/docker_data/aria2-pro1
    docker-compose down # 卸载容器
    rm -rf /root/data/docker_data/aria2-pro1 # 完全删除宿主机映射的文件
  • docker-compose常用的其他命令
docker-compose start #启动所有容器
docker-compose restart #重启所有容器
docker-compose stop #停止所有容器
docker ps -a  #若想要操作具体某一个容器,在后面跟容器名称或者ID即可,可到容器列表中查看,执行如下命令
docker inspect 容器名称  #若想要查看某个容器的具体信息,比如容器卷挂载路径,执行如下命令

emby服务搭建

安装

  • 使用如下命令下载安装报
wget https://github.com/MediaBrowser/Emby.Releases/releases/download/4.7.11.0/emby-server-deb_4.7.11.0_arm64.deb

其中安装报要看自己的服务器是什么架构的,我的是arm架构服务器,因此下载了arm架构的安装包。查看自己的服务器架构到下载页面获取下载链接替换掉wget后面的下载链接。

  • 安装emby
dpkg -i emby-server-deb_4.7.11.0_arm64.deb
  • 设置开机自启动
systemctl enable emby-server
  • 访问emby服务
    浏览器启输入http://ip:8096即可访问,如果访问不通请做后续操作
  • 重启emby服务
systemctl restart emby-server.service
  • 若服务器厂家有安全组设置请打开安全组
  • 查看系统是否设置了防火墙,如果有放开8096端口,具体操作浏览器搜索
  • 停止emby服务命令
systemctl stop emby-server.service

到此不出意外接口通过浏览器打开emby服务,如果想要通过域名访问emby服务可设置反代。

配置

  • 描述
    打开emby服务跟着流程进行配置即可,其中尤其注意三点,创建媒体库时文件路径、媒体视频转码问题、远程控制选项
  • 媒体库文件路径选择
    路径输入挂载网盘到服务器上的路径。
  • 媒体视频转码和远程控制选项参考下图
    emby配置
最后修改:2023 年 02 月 12 日
如果觉得我的文章对你有用,请随意赞赏