Youtubeのような動画サーバを提供するPLEXのインストール方法を記載します。PLEXに動画を追加するにはこちらを参考にしてください。
Table of Contents
1 PLEXのインストール
CentOS 7向けのrpmパッケージをインストールします。
> PLEX=https://downloads.plex.tv/plex-media-server/0.9.16.3.1840-cece46d
> wget -q ${PLEX}/plexmediaserver-0.9.16.3.1840-cece46d.x86_64.rpm
> sudo zypper --no-gpg-checks -n in \
plexmediaserver-0.9.16.3.1840-cece46d.x86_64.rpm
> sudo systemctl enable plexmediaserver
> sudo systemctl start plexmediaserver
> sudo systemctl start plexmediaserver
2 ポートの開放
32400/tcpを開放します。
> firewall_open_tcp()
{
for t in FW_SERVICES_EXT_TCP FW_SERVICES_DMZ_TCP FW_SERVICES_INT_TCP; do
sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \
-i /etc/sysconfig/SuSEfirewall2
done
sudo systemctl restart SuSEfirewall2
}
> firewall_open_tcp 32400
3 Apache2によるDigest認証(任意)
Apache2経由でPLEXにアクセスできるようにし、Apache2のDigest認証でアクセス制御を実現します。
Apache2をインストールし、URI書き換えに必要なモジュールを有効にします。
> sudo zypper -n in apache2
> for mod in proxy proxy_http rewrite auth_digest; do
sudo a2enmod ${mod}
done
PLEX向けの設定ファイルを追加します。
> sudo su -c 'cat <<EOF > /etc/apache2/conf.d/plexmediaserver.conf
ProxyPass / http://127.0.0.1:32400/
ProxyPassReverse / http://127.0.0.1:32400/
ProxyRequests Off
ProxyPreserveHost On
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/web
RewriteCond %{HTTP:X-Plex-Device} ^$
RewriteRule ^/$ /web/$1 [R,L]
<Proxy http://127.0.0.1:32400>
AuthType Digest
AuthName "plexmediaserver"
AuthUserFile /etc/apache2/.plexmediaserver
Require valid-user
</Proxy>
EOF
'
PLEX向けのDigest認証ファイルを作成します。
> sudo htdigest2 -c /etc/apache2/.plexmediaserver \ "plexmediaserver" user
Apache2を再起動します。
> sudo systemctl enable apache2 > sudo systemctl restart apache2
Apache2のポートを開放します。32400/tcpを開いている場合は閉じてください。
> firewall_open_service()
{
for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do
sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \
-i /etc/sysconfig/SuSEfirewall2
done
sudo systemctl restart SuSEfirewall2
}
> firewall_open_service apache2
4 PLEXをインストールするスクリプト
以下のスクリプトでPLEXのインストールとApache2のDigest認証を利用できます。
#!/bin/sh # Password and username for digest authentication. DIGEST_PASSWD=plexmediaserver DIGEST_USER=user firewall_open_tcp() { for t in FW_SERVICES_EXT_TCP FW_SERVICES_DMZ_TCP FW_SERVICES_INT_TCP; do sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \ -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2 } firewall_open_service() { for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \ -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2 } # Install PLEX. PLEX=https://downloads.plex.tv/plex-media-server/0.9.16.3.1840-cece46d wget -q ${PLEX}/plexmediaserver-0.9.16.3.1840-cece46d.x86_64.rpm sudo zypper --no-gpg-checks -n in \ plexmediaserver-0.9.16.3.1840-cece46d.x86_64.rpm sudo systemctl enable plexmediaserver sudo systemctl start plexmediaserver # Comment out if you need. # firewall_open_tcp 32400 # Install apache2. sudo zypper -n in apache2 for mod in proxy proxy_http rewrite auth_digest; do sudo a2enmod ${mod} done sudo su -c 'cat <<EOF > /etc/apache2/conf.d/plexmediaserver.conf ProxyPass / http://127.0.0.1:32400/ ProxyPassReverse / http://127.0.0.1:32400/ ProxyRequests Off ProxyPreserveHost On RewriteEngine on RewriteCond %{REQUEST_URI} !^/web RewriteCond %{HTTP:X-Plex-Device} ^$ RewriteRule ^/$ /web/$1 [R,L] <Proxy http://127.0.0.1:32400> AuthType Digest AuthName "plexmediaserver" AuthUserFile /etc/apache2/.plexmediaserver Require valid-user </Proxy> EOF ' sudo zypper -n in expect expect -c " set timeout -1 spawn sudo htdigest2 -c /etc/apache2/.plexmediaserver \ \"plexmediaserver\" ${DIGEST_USER} expect \"New password: \" send \"${DIGEST_PASSWD}\n\" expect \"Re-type new password: \" send \"${DIGEST_PASSWD}\n\" expect eof " sudo systemctl enable apache2 sudo systemctl restart apache2 firewall_open_service apache2