Cách cài đặt Jellyfin Media Server trên Debian 11

theanh

Administrator
Nhân viên
Jellyfin là ứng dụng phát trực tuyến phương tiện miễn phí và mã nguồn mở, có chức năng sắp xếp, quản lý và chia sẻ các tệp phương tiện kỹ thuật số tới các thiết bị được kết nối mạng. Ứng dụng này cho phép bạn phát trực tuyến các tệp phương tiện đã tải lên tới PC, Laptop, Mobile và Roku. Ứng dụng này cung cấp giao diện web tương tác để quản lý tất cả ảnh, video và nhạc của bạn. Nếu bạn đang tìm kiếm một giải pháp thay thế cho Plex và Netflix, Jellyfin là lựa chọn tốt nhất.

Tính năng
  • Miễn phí, mã nguồn mở và đa nền tảng
  • Hỗ trợ tăng tốc phần cứng cho mã hóa/giải mã video bằng FFMpeg
  • Cho phép bạn lấy siêu dữ liệu từ TheTVDB và TheMovieDB
  • Không giới hạn phát lại trên ứng dụng di động
Bài đăng này sẽ chỉ cho bạn cách cài đặt ứng dụng phát trực tuyến phương tiện Jellyfin với Nginx và Let's Encrypt SSL trên Debian 11.

Điều kiện tiên quyết​

  • Máy chủ chạy Debian 11.
  • Tên miền hợp lệ được trỏ bằng IP máy chủ của bạn.
  • Mật khẩu gốc được cấu hình trên máy chủ.

Cài đặt Jellyfin​

Trước khi bắt đầu, bạn sẽ cần thêm kho lưu trữ Jellyfin vào APT. Để thực hiện, trước tiên hãy cài đặt các phụ thuộc cần thiết bằng lệnh sau:
Mã:
apt-get install apt-transport-https ca-certificates gnupg2 curl git -y
Sau khi cài đặt xong tất cả các phụ thuộc, hãy thêm khóa GPG và kho lưu trữ bằng lệnh sau lệnh:
Mã:
wget -O - https://repo.jellyfin.org/jellyfin_team.gpg.key | apt-key add -
echo "deb [arch=$( dpkg --print-architecture )] https://repo.jellyfin.org/debian bullseye main" | tee /etc/apt/sources.list.d/jellyfin.list
Tiếp theo, hãy cập nhật kho lưu trữ và cài đặt Jellyfin bằng lệnh sau:
Mã:
apt-get update -y
apt-get install jellyfin -y
Sau khi Jellyfin đã được cài đặt, bạn có thể xác minh trạng thái của Jellyfin bằng lệnh sau lệnh:
Mã:
systemctl status jellyfin
Bạn sẽ nhận được kết quả sau:
Mã:
? jellyfin.service - Jellyfin Media Server Loaded: loaded (/lib/systemd/system/jellyfin.service; enabled; vendor preset: enabled) Drop-In: /etc/systemd/system/jellyfin.service.d ??jellyfin.service.conf Active: active (running) since Fri 2022-02-04 03:48:50 UTC; 9s ago Main PID: 4989 (jellyfin) Tasks: 19 (limit: 2341) Memory: 85.0M CPU: 4.069s CGroup: /system.slice/jellyfin.service ??4989 /usr/bin/jellyfin --webdir=/usr/share/jellyfin/web --restartpath=/usr/lib/jellyfin/restart.sh --ffmpeg=/usr/lib/jellyfin->
Feb 04 03:48:56 debian11 jellyfin[4989]: [03:48:56] [INF] ServerId: 809b343f6da845699dd6447e1bb4f061
Feb 04 03:48:56 debian11 jellyfin[4989]: [03:48:56] [INF] Registering publisher for urn:schemas-upnp-org:device:MediaServer:1 on 127.0.0.1/32
Feb 04 03:48:56 debian11 jellyfin[4989]: [03:48:56] [WRN] 127.0.0.1/32: GetBindInterface: Loopback 127.0.0.1 returned.
Feb 04 03:48:56 debian11 jellyfin[4989]: [03:48:56] [INF] Executed all pre-startup entry points in 0:00:00.2808517
Feb 04 03:48:56 debian11 jellyfin[4989]: [03:48:56] [INF] Core startup complete
Feb 04 03:48:57 debian11 jellyfin[4989]: [03:48:57] [INF] Executed all post-startup entry points in 0:00:00.2169291
Feb 04 03:48:57 debian11 jellyfin[4989]: [03:48:57] [INF] Startup complete 0:00:06.7385186
Feb 04 03:48:59 debian11 jellyfin[4989]: [03:48:59] [INF] StartupTrigger fired for task: Update Plugins
Feb 04 03:48:59 debian11 jellyfin[4989]: [03:48:59] [INF] Queuing task PluginUpdateTask
Feb 04 03:48:59 debian11 jellyfin[4989]: [03:48:59] [INF] Executing Update Plugins
Theo mặc định, Jellyfin lắng nghe trên cổng 8096. Bạn có thể kiểm tra bằng lệnh sau lệnh:
Mã:
ss -antpl | grep 8096
Bạn sẽ nhận được kết quả đầu ra sau:
Mã:
LISTEN 0 512 0.0.0.0:8096 0.0.0.0:* users:(("jellyfin",pid=4989,fd=289))

Cấu hình Nginx làm Proxy ngược cho Jellyfin​

Tiếp theo, bạn sẽ cần cài đặt và cấu hình Nginx làm proxy ngược cho Jellyfin. Trước tiên, hãy cài đặt Nginx bằng lệnh sau:
Mã:
apt-get install nginx -y
Tiếp theo, hãy tạo tệp cấu hình máy chủ ảo Nginx bằng lệnh sau:
Mã:
nano /etc/nginx/conf.d/jellyfin.conf
Thêm các dòng sau:
Mã:
server { listen 80; server_name jellyfin.example.com; access_log /var/log/nginx/jellyfin.access; error_log /var/log/nginx/jellyfin.error; resolver 127.0.0.1 valid=30; # Security / XSS Mitigation Headers add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; location / { # Proxy main Jellyfin traffic proxy_pass http://localhost: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://localhost: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://localhost:8096/socket; 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; }
}
Lưu và đóng tệp sau đó xác minh Nginx xem có lỗi cú pháp nào không.
Mã:
nginx -t
Bạn sẽ nhận được thông báo sau đầu ra:
Mã:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Cuối cùng, khởi động lại Nginx để áp dụng các thay đổi:
Mã:
systemctl reload nginx
Để kiểm tra trạng thái của Nginx, hãy sử dụng lệnh sau lệnh:
Mã:
systemctl status nginx
Bạn sẽ thấy kết quả sau:
Mã:
? nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-02-04 03:49:27 UTC; 55s ago Docs: man:nginx(8) Process: 6314 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 6315 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 6454 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS) Main PID: 6395 (nginx) Tasks: 2 (limit: 2341) Memory: 2.8M CPU: 66ms CGroup: /system.slice/nginx.service ??6395 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ??6455 nginx: worker process
Feb 04 03:49:27 debian11 systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 04 03:49:27 debian11 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Feb 04 03:49:27 debian11 systemd[1]: Started A high performance web server and a reverse proxy server.
Feb 04 03:50:17 debian11 systemd[1]: Reloading A high performance web server and a reverse proxy server.
Feb 04 03:50:17 debian11 systemd[1]: Reloaded A high performance web server and a reverse proxy server.

Truy cập Giao diện Web Jellyfin​

Bây giờ, hãy mở trình duyệt web của bạn và truy cập giao diện web Jellyfin bằng URL . Bạn sẽ được chuyển hướng đến trang sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22344%22%3E%3C/svg%3E


Chọn ngôn ngữ của bạn và nhấp vào nút Tiếp theo. Bạn sẽ thấy trang sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22405%22%3E%3C/svg%3E


Cung cấp tên người dùng quản trị, mật khẩu và nhấp vào nút Tiếp theo. Bạn sẽ thấy trang sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22392%22%3E%3C/svg%3E


Nhấp vào nút Tiếp theo. Bạn sẽ thấy trang sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22376%22%3E%3C/svg%3E


Chọn ngôn ngữ siêu dữ liệu của bạn và nhấp vào nút Tiếp theo. Bạn sẽ thấy trang sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22350%22%3E%3C/svg%3E


Chọn tùy chọn bạn muốn và nhấp vào nút Tiếp theo. Sau khi Jellyfin được cài đặt, bạn sẽ thấy trang sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22328%22%3E%3C/svg%3E


Nhấp vào nút Hoàn tất. Bạn sẽ được chuyển hướng đến trang đăng nhập Jellyfin:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22361%22%3E%3C/svg%3E


Cung cấp tên người dùng quản trị, mật khẩu và nhấp vào nút Đăng nhập. Bạn sẽ thấy bảng điều khiển Jellyfin trên trang sau:


data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22291%22%3E%3C/svg%3E

Bảo mật Jellyfin bằng Let's Encrypt​

Tiếp theo, bạn sẽ cần cài đặt gói máy khách Certbot để cài đặt và quản lý Let's Encrypt SSL.

Đầu tiên, hãy cài đặt Certbot bằng lệnh sau lệnh:
Mã:
apt-get install certbot python3-certbot-nginx -y
Sau khi cài đặt hoàn tất, hãy chạy lệnh sau để cài đặt Let's Encrypt SSL trên trang web của bạn:
Mã:
certbot --nginx -d jellyfin.example.com
Bạn sẽ được yêu cầu cung cấp địa chỉ email hợp lệ và chấp nhận điều khoản dịch vụ như hiển thị bên dưới:
Mã:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [emailprotected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for jellyfin.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/jellyfin.conf
Tiếp theo, chọn có chuyển hướng lưu lượng HTTP sang HTTPS hay không như hiển thị bên dưới:
Mã:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Nhập 2 và nhấn Enter để hoàn tất cài đặt. Bạn sẽ thấy đầu ra sau:
Mã:
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/jellyfin.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://jellyfin.example.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=jellyfin.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/jellyfin.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/jellyfin.example.com/privkey.pem Your cert will expire on 2022-05-07. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le - We were unable to subscribe you the EFF mailing list because your e-mail address appears to be invalid. You can try again later by visiting https://act.eff.org.

Kết luận​

Xin chúc mừng! Bạn đã cài đặt thành công Jellyfin với Nginx và Let's Encrypt SSL trên Debian 11. Bây giờ bạn có thể bắt đầu tải phương tiện của mình lên và phát trực tuyến chúng từ các thiết bị di động.
 
Back
Bên trên