如何在CentOS 8上安装Plex Media Server
如何在CentOS 8上安装Plex Media Server
Plex是一个免费的开放源代码且功能齐全的媒体服务器,可让您从世界各地在PC,平板电脑,手机上流式传输照片,视频和音频文件。Plex支持大多数操作系统,包括Linux,Windows,Mac和FreeBSD。Plex还支持多个插件,使您可以观看Comedy Central和MTV的内容。
Plex是一个客户端-服务器媒体播放器系统。您只需在保存媒体的服务器上安装Plex服务器,然后安装手机,平板电脑或其他设备的Plex应用程序,即可通过Internet访问媒体。
功能支持多个用户。显示电影/电视节目推荐。为您喜欢的音乐和电影创建播放列表。同步和访问媒体文件以供离线使用。家长控制允许您将Plex应用程序安装在儿童设备上,并限制他们仅观看特定内容。能够将本地电视频道流式传输到设备并观看直播电视。
在本教程中,我们将向您展示如何在使用Nginx作为反向代理的CentOS 8系统上安装Plex Media Server。
先决条件
- 运行CentOS 8且至少具有2 GB RAM的服务器。
- 有效域名指向您的服务器IP。
- 在您的服务器上配置了root密码。
更新系统
首先,建议使用最新版本更新服务器。您可以使用以下命令更新它:
dnf update -y
更新服务器后,请重新启动服务器以实施更改。
安装Plex Media Server
默认情况下,CentOS 8默认存储库中不提供Plex媒体服务器软件包。因此,您将需要为Plex媒体服务器创建一个存储库。您可以使用以下命令创建它:
nano /etc/yum.repos.d/plex.repo
添加以下行:
[Plex] name=Plex baseurl=https://downloads.plex.tv/repo/rpm/$basearch/ enabled=1 gpgkey=https://downloads.plex.tv/plex-keys/PlexSign.key gpgcheck=1
完成后保存并关闭文件。然后使用以下命令安装Plex媒体服务器:
dnf install plexmediaserver -y
安装完成后,请启动Plex媒体服务,并使用以下命令在系统重新引导后使其启动:
systemctl enable plexmediaserver
systemctl start plexmediaserver
您还可以使用以下命令来验证Plex媒体服务器的状态:
systemctl status plexmediaserver
您应该看到以下输出:
? plexmediaserver.service - Plex Media Server
Loaded: loaded (/usr/lib/systemd/system/plexmediaserver.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2020-01-06 02:45:40 EST; 41s ago
Main PID: 1009 (Plex Media Serv)
Tasks: 113 (limit: 12552)
Memory: 268.1M
CGroup: /system.slice/plexmediaserver.service
??1009 /usr/lib/plexmediaserver/Plex Media Server
??1033 Plex Plug-in [com.plexapp.system] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/Resources/>
??1077 /usr/lib/plexmediaserver/Plex Tuner Service /usr/lib/plexmediaserver/Resources/Tuner/Private /usr/lib/plexmediaserver/Resour>
??1246 Plex Plug-in [org.musicbrainz.agents.music] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/>
??1356 Plex Plug-in [com.plexapp.agents.plexthememusic] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Cont>
??1364 Plex Plug-in [com.plexapp.agents.themoviedb] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents>
??1365 Plex Plug-in [tv.plex.agents.music] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/Resource>
??1389 Plex Plug-in [com.plexapp.agents.thetvdb] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/Re>
??1450 Plex Plug-in [com.plexapp.agents.imdb] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/Resou>
Jan 06 02:45:40 plex systemd[1]: Starting Plex Media Server...
Jan 06 02:45:40 plex systemd[1]: Started Plex Media Server.
此时,Plex媒体服务器已安装并正在运行。现在,您可以继续下一步。
为Plex Media Server配置防火墙和SELinux
接下来,您将需要配置firewalld以允许Plex媒体服务器特定的端口。您可以通过运行以下命令来做到这一点:
firewall-cmd --zone=public --add-port=32400/tcp --permanent
firewall-cmd --zone=public --add-port=32469/tcp --permanent
firewall-cmd --zone=public --add-port=8324/tcp --permanent
firewall-cmd --zone=public --add-port=3005/tcp --permanent
firewall-cmd --zone=public --add-port=32412/udp --permanent
firewall-cmd --zone=public --add-port=32413/udp --permanent
firewall-cmd --zone=public --add-port=32414/udp --permanent
firewall-cmd --zone=public --add-port=32410/udp --permanent
firewall-cmd --zone=public --add-port=1900/udp --permanent
firewall-cmd --zone=public --add-port=5353/udp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
接下来,重新加载firewalld服务以实施更改:
firewall-cmd --reload
默认情况下,在CentOS 8服务器上启用SELinux。因此,您将需要配置SELinux以通过Internet访问Plex Media Server。您可以使用以下命令配置SELinux:
setsebool httpd_can_network_connect on -P
此时,可以通过Internet访问Plex媒体服务器。现在,您可以继续下一步。
访问Plex媒体服务器
现在,您可以使用URL http:// your-server-ip:32400访问Plex媒体服务器。您应该看到以下页面:

接下来,您需要使用有效的电子邮件地址进行注册才能使用该服务。成功注册后。您将被重定向到Plex媒体服务器仪表板,如下所示:

将Nginx设置为反向代理
接下来,您需要将Nginx设置为反向代理,以便您可以使用域名访问它,而无需提供IP地址和端口号。
为此,请首先使用以下命令安装Nginx Web服务器:
dnf install nginx
安装完成后,请启动Nginx服务,并使用以下命令在系统重启后使其启动:
systemctl start nginx
systemctl enable nginx
接下来,使用以下命令为Plex创建Nginx虚拟主机配置文件:
nano /etc/nginx/conf.d/plex.conf
添加以下行:
upstream plex_backend {
server 127.0.0.1:32400;
keepalive 32;
}
server {
listen 80;
server_name plex.example.com;
send_timeout 100m; #Some players don't reopen a socket and playback stops totally instead of resuming after an extended pause (e.g. Ch$
#Plex has A LOT of javascript, xml and html. This helps a lot, but if it causes playback issues with devices turn it off. (Haven't enc$
gzip on;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml application/xml text/javascript application/x-javascript image/svg+xml;
gzip_disable "MSIE [1-6]/.";
#Nginx default client_max_body_size is 1MB, which breaks Camera Upload feature from the phones.
#Increasing the limit fixes the issue. Anyhow, if 4K videos are expected to be uploaded, the size might need to be increased even more
client_max_body_size 100M;
#Forward real ip and host to Plex
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 Sec-WebSocket-Extensions $http_sec_websocket_extensions;
proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
#Websockets
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
#Buffering off send to the client as soon as the data is received from Plex.
proxy_redirect off;
proxy_buffering off;
location / {
proxy_pass http://plex_backend;
}
}
完成后保存并关闭文件。接下来,您将需要定义Nginx服务器哈希存储桶大小。您可以通过编辑Nginx配置文件来做到这一点:
nano /etc/nginx/nginx.conf
在最后一行的上方添加以下行:
server_names_hash_bucket_size 64;
完成后保存并关闭文件。然后,使用以下命令检查Nginx是否存在语法错误:
nginx -t
您应该看到以下输出:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
最后,重新启动Nginx服务以实现更改。
systemctl restart nginx
要检查Nginx服务的状态,请运行以下命令:
systemctl status nginx
如果一切正常,您应该获得以下输出:
? nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/nginx.service.d
??php-fpm.conf
Active: active (running) since Thu 2020-01-09 05:17:27 EST; 48s ago
Process: 1230 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 1229 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 1227 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 1232 (nginx)
Tasks: 2 (limit: 5060)
Memory: 13.1M
CGroup: /system.slice/nginx.service
??1232 nginx: master process /usr/sbin/nginx
??1233 nginx: worker process
Jan 09 05:17:25 centos8 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 09 05:17:27 centos8 nginx[1229]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 09 05:17:27 centos8 nginx[1229]: nginx: configuration file /etc/nginx/nginx.conf test is successful
现在,您可以使用URL http://plex.example.com访问您的Plex媒体服务器。
结论
恭喜你!您已经使用Nginx作为反向代理在CentOS 8上成功安装了Plex媒体服务器。现在,您可以浏览Plex媒体服务器以获取更多选项,并设置自己的媒体库。然后,您可以从手机的Play商店安装Plex应用程序并访问媒体。您还可以允许您的朋友和家人从Web浏览器或Plex应用程序访问您的照片,音乐和电影。
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/tech/linux/32255.html