Why?


Search This Blog

Sunday, April 12, 2015

Plex install on Centos 6.6

I jacked this from:

https://forums.plex.tv/index.php/topic/132843-plex-media-server-on-minimal-centos-65/

I did not do everything this way but it was a great guide and got me going. I am local lan behind two firewalls and double nat'd so I have firewall/iptables off, so no need for me to do any of that stuff.

To create the ‘plex’ user we use the following command:
 
> adduser -c "Plex Media Server User" -d /home/plex -s /bin/bash plex

This command will create a user ‘plex’ that has a home directory of ‘/home/plex/‘ and will be setup with the ‘bash’ shell. Don’t worry if that means nothing to you.

Next we have to give a password to the ‘plex’ user to activate (?) the user. We use the following command to prompt to set a password:
 
> passwd plex

You will be prompted to set a password and then prompted to confirm the password. This command is also used to change the password of a Linux user. Congratulations, you have created a new user from the command prompt.

Next we need to configure the ‘plex’ user to be allowed to run commands as ‘root’ using ‘sudo’. To do this we need to add ‘plex’ to the list of users that can use the ‘sudo’ command. use the following command to open the configuration file to do this:
 
> visudo

This will open the /etc/sudoers file in vi, an standard editor in Linux. Vi is not friendly to new users of linux. If you stumble with vi, you can use ’nano’ which is a more friendly editor. To use nano you will need first install with ‘yum install nano’. After yum has installed nano you can open the sudoers file with ‘nano /etc/sudoers’ command without inverted commas.

To add plex to the users you need to find the two lines in the sudoer’s file:

“## Allow root to run any commands anywhere
root ALL=(ALL) ALL”

then you need to add the following line after the line that mentions 'root':

“plex ALL=(ALL) ALL” so the 3 lines look like:
 
## Allow root to run any commands anywhereroot ALL=(ALL) ALLplex ALL=(ALL)  ALL

Save the file. That is it, the ‘plex’ user will now be able to use the ‘sudo’ command and run commands as a superuser.

So lets confirm that the ‘plex’ user has been setup correctly. Logout using the following command:
 
> exit

This will return you to the login prompt, next enter ‘plex’ and the plex password to login in with the new user.
 
pms login: plexpassword: <plexs password>

If all is fine you will have a command prompt. Next we need to check that the ‘plex’ user can run the ‘sudo’ command. Try the following:
 
> sudo pwd

You will be prompted for a password… you need to use the ‘plex’ user’s password. You should get a response of ‘/home/plex’, the home directory of the plex user that was setup with the 'adducer' command. If you got an error then repeat the steps to update the /etc/sudoers file.

At this time you can use a SSH client to access you Plex Media Server, something like the Mac OS X ‘Terminal’ application or Putty on windows is fine. I usually perform the rest of the setup via SSH but you can perform all the steps on the Plex Server locally.

While using SSH to remotely access the Plex Server is helpful it is also recommended to block the ‘root’ user to use SSH remotely. To do this use the following command to open the SSH config file:
 
> sudo vi /etc/ssh/sshd_config

Again you can use ‘sudo nano /etc/ssh/sshd_config’ if you don’t like vi.

Search for the ‘# PermitRootLogin yes’, delete the hash (‘#’) character and change ‘yes’ to ‘no’. The result should be:
 
PermitRootLogin no

Save the file. After the next restart root will not be able to remotely login over SSH, but will be able to log in locally.

That is the ‘plex’ user set up!


Downloading and Installing Plex Media Server

Because we are using just the command prompt and Plex Media Service isn’t out of the box linked to a Plex Repository we can’t use the ‘yum’ command. There are ways we can use this but from the forums it appears that the latest version of Plex Media Server is not always available via this route. So we are going to use commands to get the latest version.

Before we can get the Plex, we need to install some applications to allow Centos to download the Plex Media Server package. Run the following command to install the wget application. Note: going forward it is assumed that you are logged in under the ‘plex’ user and is why you will see 'sudo' infront of commands.
 
> sudo yum install wget

This will install the wget application that can download files using a URL. We also need to get the latest URL for the current version of Plex to download.

I got the download URL by using another PC, going to the Plex downloads section and copying the Link to the current version. Now that we have the URL for the latest version it is time to download. I recommending creating a download’s folder in the ‘plex’ users home directory, but this is optional. To do this use the following commands to create and then open the download directory:
 
> mkdir ~/Downloads> cd ~/Downloads

Next we want to download the Plex package using:
 
> wget <URL of the Plex Media Server RPM package>

i.e. (current as of 22nd Feb): Important, please check the current URL, below is an example.
 
> wget https://downloads.plex.tv/plex-media-server/0.9.11.7.803-87d0708/plexmediaserver-0.9.11.7.803-87d0708.x86_64.rpm

This will download the Plex package.

After the download has completed it is time to install! As we have downloaded the package to our Plex Server we can use the ‘localinstall’ option in yum to install from the downloaded file.

To install plex from the download we use the following command:
 
> sudo yum localinstall <Plex Media Server RPM package>

Based on the filename from above this would be: (Again check the filename based on the current Plex package)
 
> sudo yum localinstall plexmediaserver-0.9.11.7.803-87d0708.x86_64.rpm

The installation will take a minute or two. That is it, Plex is installed…. but it is not running, and the Linux firewall will stop clients connecting - Doh! But first let’s check the install.

To start plex we need to start the service using the following command. We only have to do this once after we install, after we reboot the Plex Media Server should start automatically on your Plex Server.
 
> sudo service plexmediaserver start

That should be it… Plex is running. But what about the firewall? At this time the firewall will block Plex ports.

We will disable the firewall for a moment to check that things are OK. In the final section we will configure the firewall to allow Plex to work as desired.

To disable the firewall temporarily use the following command:
 
> sudo service iptables stop

Caution: this will disable the firewall, after we have confirmed things are OK we will bring it back up.

Next is to check that we can use a Web Browser on another PC (or tablet, etc) to access Plex. For the purpose of this guide lets assume that the Plex Media Server has an IP of 192.168.1.100. Please change 192.168.1.100 with the IP of your Plex Server

Open a supported Web Browser and enter the following address, for example of the Plex Server having an IP of 192.168.1.100.
 
http://192.168.1.100:32400/web/

If all is OK then Plex should start. WooHoo. If not, well check the steps above to make sure you haven't missed anything. I would double check that you have disabled the firewall.

Note: previously there has been an issue with Centos 6.x and Plex producing a 404 error. I have seen this before in a desktop Centos install, but not yet in a minimal install <touch wood>. I can’t help here if you see this (yet).

OK, lets reboot the server to ensure that Plex starts up automatically and that the firewall also turned back on. Use the following command to restart:
 
> sudo shutdown -r now

The command will immediately restart the server.

Once restarted, login with the ‘plex’ user. Now to configure the firewall.


Configuring the firewall to work with Plex

The last step is to configure the firewall so the Server doesn’t block Plex traffic. I found this to be tricky, but this was my first attempt too :)

NOTE: This is my first attempt with iptable (firewall) configuration, I’m assuming that people will have other recommendations and I will gladly update the following to ensure the best configuration.

Assuming that you are logged in with the ‘plex’ user, run the following commands (note that each command should be one line):
 
> sudo iptables -A INPUT -p tcp -m tcp --sport 513:65535 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
> sudo iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 32400 -j ACCEPT
> sudo iptables -A INPUT -p udp -m state --state NEW -m udp --dport 32400 -j ACCEPT
> sudo iptables -A INPUT -p udp -m state --state NEW -m udp --dport 32410 -j ACCEPT
> sudo iptables -A INPUT -p udp -m state --state NEW -m udp --dport 32412 -j ACCEPT
> sudo iptables -A INPUT -p udp -m state --state NEW -m udp --dport 32414 -j ACCEPT
> sudo iptables -A INPUT -p udp -m state --state NEW -m udp --dport 1900 -j ACCEPT
> sudo iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
> sudo iptables -A INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT
> sudo iptables -A INPUT -i eth0 -p udp -m udp --sport 53 -j ACCEPT
> sudo iptables -A INPUT -i eth0 -p tcp -m tcp --dport 443 -j ACCEPT
> sudo iptables -A INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
> sudo iptables -A OUTPUT -p tcp -m tcp -m state --state ESTABLISHED -j ACCEPT
> sudo iptables -A OUTPUT -o lo -j ACCEPT
> sudo iptables -A OUTPUT -p tcp -m tcp --sport 22 --dport 513:65535 -m state --state NEW,ESTABLISHED -j ACCEPT
> sudo iptables -A OUTPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT
> sudo iptables -A OUTPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
> sudo iptables -A OUTPUT -o eth0 -p udp -m udp --dport 53 -j ACCEPT
> sudo iptables -A OUTPUT -o eth0 -p tcp -m tcp --dport 443 -j ACCEPT
> sudo iptables -A OUTPUT -o eth0 -p tcp -m tcp --dport 80 -j ACCEPT
> sudo service iptables save

This configuration will allow the Plex ports 32400, 32410, 32412, 32414 open. By default port 22 should be open from the base Centos installation. I have also opened DNS (53), HTTP (80) and HTTPS (443) in preparation of PlexConnect.

Again open a supported Web Browser on another PC and check you are able to connect to http://<IP address of Plex Server>:32400/web/ . If so - awesome.


Add you media to your server

Finally time to add your media to your server, and something I will leave up to you. Just remember that the plex user needs to have the right permissions to access your media if you are installing it locally as per the Plex Linux Guide in the FAQs.

No comments:

Post a Comment