OneKuma

OneKuma's Blog

One Lonely Kuma.
github
bilibili
twitter

在服务器用 WebDAV 部署 Jellyfin

接着上文 折腾了一下阿里云盘 + AList + Rclone + AnimePaste 继续倒腾。

在服务器上,将 阿里云盘 挂载到 AList 上,再用 rclone 挂载到本地磁盘,最后用 Jellyfin 暴露出动画媒体库。

af0c5f3688237ea4b153b64ea1a251f5

Jellyfin#

首先,安装 Jellyfin

dnf install -y https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

dnf install -y https://repo.jellyfin.org/releases/server/fedora/stable/server/jellyfin-10.8.10-1.fc36.x86_64.rpm

dnf install -y https://repo.jellyfin.org/releases/server/fedora/stable/web/jellyfin-web-10.8.10-1.fc36.noarch.rpm

# 启动 Jellyfin
systemctl start jellyfin

# 开机自动启动 Jellyfin
systemctl enable jellyfin

启动后,可以通过 http://服务器IP:8096 访问到 Jellyfin 媒体库了(服务器防火墙打开 8096 端口)。

AList#

直接用 Docker 部署 AList

#!/usr/bin/bash

docker stop alist 2> /dev/null

docker rm alist 2> /dev/null

docker run -d --name=alist --restart=always \
  -v /etc/alist:/opt/alist/data -p 5244:5244 \
  -e PUID=0 -e PGID=0 -e UMASK=022 xhofe/alist:latest

启动后,查看容器日志获得登录密码。

docker logs alist

启动后,可以通过 http://服务器IP:5244 访问到 AList 了(服务器防火墙打开 5244 端口)。然后,在它的 WebUI 上配置阿里云盘挂载到 /aliyundriver

约定动画目录是阿里云盘的 /anime/,即 AList 的 /aliyundriver/anime/

qbittorrent#

version: '3.9'

services:
  alist:
    image: xhofe/alist:latest
    container_name: alist
    restart: always
    environment:
      - PUID=0
      - PGID=0
      - UMASK=022
      - TZ=Asia/Shanghai
    volumes:
      - /etc/alist:/opt/alist/data
    networks:
      - alist_net
    ports:
      - 5244:5244

  qbittorrent:
    image: lscr.io/linuxserver/qbittorrent:latest
    container_name: qbittorrent
    restart: unless-stopped
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Asia/Shanghai
      - WEBUI_PORT=8080
    volumes:
      - ./appdata/config:/config
      - ./downloads:/downloads
    networks:
      - alist_net
    ports:
      - 8080:8080
      - 6881:6881
      - 6881:6881/udp

networks:
  alist_net:

Rclone#

[alist]
type = webdav
url = http://127.0.0.1:5244/dav/
user = admin
pass = xxxyyyzzz

密码已隐藏。

写了个脚本 mount-anime.sh 方便挂载本地目录。

#!/usr/bin/bash

mount_dir="/jellyfin/anime"
cache_dir="/root/.rclone/cache/anime" 
log_path="/var/log/rclone-anime.log"

function bootstrap() {
  mkdir -p $mount_dir
  rm $log_path
  
  rclone mount alist:/aliyundriver/anime/ $mount_dir \
    --header "Referer:https://www.aliyundrive.com/" \
    --vfs-cache-mode writes --vfs-read-chunk-size-limit 1G --vfs-read-chunk-size 256M \
    --cache-dir $cache_dir --dir-cache-time 5m --vfs-cache-max-size 10G \
    --buffer-size 128M \
    --no-check-certificate --allow-non-empty --allow-other \
    --uid $(id -u jellyfin) --gid $(id -g jellyfin) --umask 022 \
    --log-file $log_path $@
}

function stop() {
  fusermount -u $mount_dir 2> /dev/null
  ps -ef | grep rclone | grep -v grep | awk '{print $2}' | xargs kill 2> /dev/null
}

case "$1" in
  "")
    stop
    bootstrap --daemon
  ;;
  "service")
    stop
    bootstrap
  ;;
  "space")
    echo $mount_dir
  ;;
  "logs")
    tail -f $log_path
  ;;
  "stop")
    stop
  ;;
esac

注意:挂载的本地目录($mount_dir)必须给 jellyfin 用户权限,否则 Jellyfin 将无法识别。

使用方法:

# 作为 daemon 进行 mount
$ ./mount-anime.sh

# 查看日志
$ ./mount-anime.sh logs

# 停止
$ ./mount-anime.sh stop

顺便再搞到 systemd 里,重启的时候自动 mount。

[Unit]
Description=Mount Anime Directory
Documentation=man:rclone(1)
After=network.target
After=docker.service
Before=jellyfin.service

[Service]
Type=simple
ExecStart=/path/to/mount-anime.sh service
ExecStop=/path/to/mount-anime.sh stop

[Install]
WantedBy=default.target

修改 mount-anime.sh 脚本的路径。

# 将上面的 service 文件移动到 systemd 目录下
$ cp /path/to/mount-anime.service /etc/systemd/system/

# 重启,并启动服务
$ systemctl daemon-reload

$ systemctl enable mount-anime.service

$ systemctl start mount-anime.service

nginx(可选)#

顺便也把它暴露到一个域名上,方便记忆。

把下面这段配置修改后丢到 /etc/nginx/conf.d/jellyfin.conf。你需要修改:

  • server_name:你的域名;
  • ssl_certificate / ssl_certificate_key:你的 SSL 证书。
server {
    listen       80;
    listen       [::]:80;
    server_name  <SERVER_NAME>;

    # Uncomment to redirect HTTP to HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen       443 ssl http2;
    listen       [::]:443 ssl http2;
    server_name  <SERVER_NAME>;

    ## The default `client_max_body_size` is 1M, this might not be enough for some posters, etc.
    client_max_body_size 20M;

    # use a variable to store the upstream proxy
    # in this example we are using a hostname which is resolved via DNS
    # (if you aren't using DNS remove the resolver line and change the variable to point to an IP address e.g `set $jellyfin 127.0.0.1`)
    # set $jellyfin jellyfin;
    # resolver 127.0.0.1 valid=30;
    set $jellyfin 127.0.0.1;

    ssl_certificate     <SSL_PEM>;
    ssl_certificate_key <SSL_KEY>;
    #include /etc/letsencrypt/options-ssl-nginx.conf;
    #ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    add_header Strict-Transport-Security "max-age=31536000" always;
    #ssl_trusted_certificate /etc/letsencrypt/live/DOMAIN_NAME/chain.pem;
    ssl_stapling on;
    ssl_stapling_verify on;

    # Security / XSS Mitigation Headers
    # NOTE: X-Frame-Options may cause issues with the webOS app
    # add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    # Content Security Policy
    # See: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
    # Enforces https content and restricts JS/CSS to origin
    # External Javascript (such as cast_sender.js for Chromecast) must be whitelisted.
    # NOTE: The default CSP headers may cause issues with the webOS app
    #add_header Content-Security-Policy "default-src https: data: blob: http://image.tmdb.org; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' https://www.gstatic.com/cv/js/sender/v1/cast_sender.js https://www.gstatic.com/eureka/clank/95/cast_sender.js https://www.gstatic.com/eureka/clank/96/cast_sender.js https://www.gstatic.com/eureka/clank/97/cast_sender.js https://www.youtube.com blob:; worker-src 'self' blob:; connect-src 'self'; object-src 'none'; frame-ancestors 'self'";

    location = / {
        return 302 http://$host/web/;
        #return 302 https://$host/web/;
    }

    location / {
        # Proxy main Jellyfin traffic
        proxy_pass http://$jellyfin:8096;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Protocol $scheme;
        proxy_set_header X-Forwarded-Host $http_host;

        # Disable buffering when the nginx proxy gets very resource heavy upon streaming
        proxy_buffering off;
    }

    # location block for /web - This is purely for aesthetics so /web/#!/ works instead of having to go to /web/index.html/#!/
    location = /web/ {
        # Proxy main Jellyfin traffic
        proxy_pass http://$jellyfin:8096/web/index.html;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Protocol $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
    }

    location /socket {
        # Proxy Jellyfin Websockets traffic
        proxy_pass http://$jellyfin:8096;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Protocol $scheme;
        proxy_set_header X-Forwarded-Host $http_host;
    }
}

最后#

在 Jellyfin 上初始化你的媒体库,添加动画相关的插件和 jellyfin-plugin-bangumi 插件,并指定媒体库从这些插件中下载元数据。

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.