Well I decided to try something new after running Plex Media Server on my CentOS 6 successfully I thought I might try CentOS 7. I'm still testing this build, but it looks stable and so I thought I would share my current build steps on CentOS 7.
The target audience for this guide are those that are new to a minimal build, specifically a build that is performed on the command line interface. I have tested these steps on CentOS 7.0 minimal installation media. I have tested these instructions purely in a VMWare instance, there are a few things I'm trying to get working before I install I build on bare metal.
This guide assumes that you are installing on a x86 64 bit architecture because, unlike CentOS 6, is only available in 64 bit. No Intel Atom installs with CentOS 7
The scope will cover from downloading CentOS to basic application and server configuration to get Plex running and optionally connect to a Samba Share for media. Please feel free to suggest better solutions or steps - I'm no expert, but know a bit more than my first guide.
[UPDATE: added section to setup the Plex server to connect to a NAS samba share for media]
Ok, enough talk, to the guide.
Obtain and Install Centos 7.x
First step is to download the Centos Minimal installation media. Go to https://www.centos.org/download/
and select the 'Minimal OS' button. This will load a page with links to your country mirrors and nearby mirrors. Click the desired link and get a coffee while the ISO downloads. Now burn a copy of the CD if you are installing via physical media if required, install on a USB key or leave the iso if you are going to install within a VM environment.
Boot up the PC using the Minimal CD or USB Key and perform the following steps: (this is verbose for completeness):
- (Optional) At the 'CentOS 7' Boot Menu select "Test thiss media and Install CentOS 7", yes it will take a couple of minutes, but it will save hours if the media is corrupt.
- At the Installation Language Menu select the appropriate system language and locale for the CentOS system and click 'Continue'
- At the 'Installation Summary' click on the 'Date and Time' section.
- Click on the region and/or search for an appriopriate region and city.
- I leave network time enabled that will automatically sync the date and time based on the region and city, or you can disable the network clock and set the date and time manually.
- Click on the 'Done' button in the top left hand corner to close the 'Date and Time' window.
- Check that the 'Keyboard' and 'Language Support' have suitable choices and continue. Otherwise click on the sections and select the desired options.
- At the "Installation Summary" click on the 'Installation Destination' section - IMPORTANT: this installation assumes that you will be formatting and installing on the HDD completely using all available space. If this is not want you want then stop now, do not proceed unless you understand what you are doing. I will not be responsible for data loss.
- Click on the target HDD that you wish to install CentOS onto. Make sure you know which drive you want to install to!
- In the "Installation Destination" section you can accept the defaults; or
- (optionally) You can encrypt the drive and/or manually partition the HDD
- Finally, click the 'Done' button in the top left hand corner to accept the selected HDD and partitioning options
- Next select 'Network and Hostname'
- Click on the Network Adapter (if not selected by default) and click on the 'Configure...' button in the bottom right hand corner of the screen
- Click on the 'General' tab in the new window (just left of the 'Ethernet' tab)
- IMPORTANT: Click on the 'Automatically connect to this Network when it is available', this we auto enable the network when the Server is rebooted
- Leave the 'All users may connect to this network' - I don't know the effects of deselecting it :rolleyes:
- (optional but recommended) If you want a static IP address for the server, then click on the 'IPv4 Settings' tab (the one to right of the DCB tab), select 'Manual' from the Method drop down menu, click the 'Add' button and enter the required IP (i.e. 192.168.1.100), the netmask (usually 255.255.255.0) and the IP of your gateway/router (usually 192.168.1.1 or 192.168.1.254) and the DNS (again usually the IP of the router - you can use another PC and look at the network settings to get this information).
- Once you have completed the Network configuration details, click the 'Save' button on the bottom right hand corner of the window to close the window and return back to the 'Network and Hostname' section.
- Next, give the server a hostname, you can leave it as localhost.localdomain but I recommend changing it to something else to avoid a name conflict with other linux computers. I use pms.localdomain but you can call it whatever you want (this will not be the name of the plex server, just the name of the pc)
- Finally click on the 'Done' button in the top left hand corner to close the 'Network and Hostname' window
- Finally at the 'Installation Summary' window, click the 'Begin Installation’ button to start the installation process and grab a coffee.
While installing there will be a 'Configuration' window to prompt you to set the 'Root Password' and 'User Creation'. We will only need to set the root password for the installation step. We will create a user manually later in the guide.
- Click on the 'Root Password' section.
- In the 'Root Password' window, type in the desired password in both the 'Root Password' and 'Confirm' fields.
- Click the 'Done' button to confirm the password and to close the 'Root Password' window. (note if your password is 'weak' you will have to click the 'Done' button twice)
After the 'Root Password' has set and the installation have been completed you will be able to click on the 'Finish configuration' button to finalise the installation and configuration.
When the entire installation and configuration has completed you will simply need to click on the 'Reboot' button to reboot the server with CentOS.
Congradulations you have installed CentOS 7!
Configure Centos 7.x
In this section we will update the system, create and configure the ‘plex’ user that will be used to install and setup Plex Media Server and slightly secure the system. This will be done all within the Command Prompt… but don’t be scared.
To start we need to log in with the ‘root’ user after the PC has restarted. Use the login of ‘root’ without inverted comma’s and the password you gave root during the installation.
pms login: root
password: <root’s password>
Firstly we are best to update the system to get the latest Centos packages using the following command:
Yum will automatically download and update any package that is currently installed. Yum will prompt you with a few questions, just reply with ‘y’ or ‘yes’ for all questions and you should be OK.
After we have updated all packages next we need to create a ‘plex’ user. This is the user that will install and generally run activities for the Plex Media Server. This will be a general user, but will be setup to run commands as the ‘root’ user if required.
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:
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:
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 anywhere
root ALL=(ALL) ALL
plex 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:
This will return you to the login prompt, next enter ‘plex’ and the plex password to login in with the new user.
pms login: plex
password: <plex’s 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:
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:
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 linux 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.
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 24th May): Important, please check the current URL, below is an example.
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 as of 24th May)
> sudo yum localinstall plexmediaserver-0.9.12.1.1079-b655370.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 systemctl start plexmediaserver.service
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 systemctl stop firewalld.service
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.
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.
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:
The command will immediately restart the server.
Once restarted, login with the ‘plex’ user. Now to configure the firewall.
Configuring the Firewall
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 firewalld configuration, I’m assuming that people will have other recommendations and I will gladly update the following to ensure the best configuration.
First step is to log into the server using the 'plex' user.
We want to stop the Plex Media Server whilst we config the firewall, use the following command to stop plex media server:
> sudo systemctl stop plexmediaserver.service
Next we want to switch user to root. You could just log into the server as root, unless you are trying to log in via ssh (which we disabled). The guide will use the switch user command to cater for both cases. This works over ssh as you have logged into the server using a non-root account.
To switch the user we use the 'su' command, specifically:
Next you will need to enter the 'root' password NOT the plex user password that you can use with sudo. This is because you are effectively logging into the server as root, not trying to run a command as root.
Next we want to create a plexmediaserver set of firewall rules, this will open the ports required for the plexmediaserver service. Using vi (or nano) create a new file with a suffix of 'xml':
> vi /etc/firewalld/services/plexmediaserver.xml
Next we need to populate the file with the following lines:
<?xml version="1.0" encoding="utf-8"?>
<description>Plex TV Media Server</description>
<port port="1900" protocol="udp"/>
<port port="5353" protocol="udp"/>
<port port="32400" protocol="tcp"/>
<port port="32410" protocol="udp"/>
<port port="32412" protocol="udp"/>
<port port="32413" protocol="udp"/>
<port port="32414" protocol="udp"/>
<port port="32469" protocol="tcp"/>
Save the file.
This configuration will allow the Plex ports 32400, 32410, 32412, 32414 open. By default port 22 should be open from the base Centos installation.
Ok now we have to register the new service firewall rules with the firewall deamon. We do this using the firewall command tool. But first lets confirm that the firewall is up to accept commands, use (note we are still logged on as root, so we don't need sudo):
> systemctl start firewalld.service
OK, not the firewall is up, we can register the service specific rules using the following command:
> firewall-cmd --permanent --add-service=plexmediaserver
Next we need to do is register the server to the default public zone. To be honest I don't know all the details of zones
but I know I have to add the service to the zone to work. We do this with the following command:
> firewall-cmd --permanent --zone=public --add-service=plexmediaserver
OK the last step is to restart the firewall and start the plex media server service, use the following commands:
> systemctl restart firewalld.service
> systemctl start plexmediaserver.service
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. If it doesn't work, then stop the firewall and retry. If it works after disabling the firewall then go through the firewall steps again to confirm you didn't miss anything.
[Optional] Setup Plex Server to connect to media on a NAS server using Samba
A default minimal CentOS 7 build will not be able to mount SMB\CIFS shares. We’ll need to install a package onto the server that allows it to understand the SMB protocol.
1. First we need to Install the cifs-utils package from the default CentOS yum repository. This will install the applications and libraries required to support Samba/CIFS.
> sudo yum install cifs-utils
2. Next we have to open the firewall to allow connections to Samba shares:
> sudo firewall-cmd --permanent --zone=public --add-service=samba
> sudo firewall-cmd --reload
3. Next, we need an account on the CentOS server that will be dedicated for Samba Shares. We’ll create a service account named usr_smb_core with a user id (uid) of 5000.
> sudo useradd -u 5000 usr_smb_core
4. We also want a group on the CentOS server that will map to the share. This group will contain all of the Linux accounts that will need access to the share. Our account will be called share_smb_core and it will have a group id (gid) of 6000.
> sudo groupadd -g 6000 share_smb_core
5. Finally, add any Linux accounts that require access to the SMB share to the newly created Linux group. Will add the plex user to the share_library_core group.
> sudo usermod -G share_smb_core -a plex
6. Next we have to create a directory to mount the SMB share into. We’ll mount the share in a directory called /mnt/nas/media. This means that when the Samba/CIFS share is setup it will be accessible from this directory.
> mkdir /mnt/nas
> mkdir /mnt/nas/media
7. Let’s test the details to ensure we can connect, you will have to type in the password when prompted, assuming:
- 192.168.1.200 is the IP of the NAS/Samba Server
- shareName is the name of NAS/Samba share
- /mnt/nas/media is the directory on the plex server that you want to map the share to
- SambaShareUserName is the NAS user name that you want to use to connect to the NAS/Samba server
> sudo mount.cifs \\\\192.168.1.200\shareName /mnt/nas/media -o user= SambaShareUserName,uid=5000,gid=6000
note: I was connecting to a Unix based NAS, I don’t know if this will be different for Windows PC / server.
If no errors appeared, the share should successfully be mounted. The verify this, use the 'df' command, this command displays all mounted drives.
You should see your HHD partitions and the share, note this assumes that the NAS share is called ‘media’:
Filesystem 1K-blocks Used Available Use% Mounted on
\\192.168.1.200\shareName 2147422700 2141280606 6142094 100% /mnt/nas/media
If that works we are half way there. But lets set it up to automatically mount the NAS share in a secure way, that is not expose the user credentials for the Samba Share. We will do this by creating a credentials file that only root can read and set up the mount command to read this file.
8. Create a credentials file in Root’s home directory, you can put this somewhere but for this guide I’m just having it here. The ‘touch’ command essentially creates an empty file.
> sudo touch /root/creds_smb_library_core
9. Modify the credential file’s permissions so that only the Root account is granted read permissions using the ‘chmod’ command. No groups or other users should have access to the file. Not even the plex user.
> sudo chmod 0600 /root/creds_smb_library_core
10. Next we need to edit the file to inject the username and password that we will use to connect to the Samba share.
> sudo vi /root/creds_smb_library_core
The file will contain 2 lines, one for the username and the last for the password, it should look something like this:
11. OK, Let’s test this credential file, first we have to un-mount the share, assuming that it is still mounted from step 7. We simply use the ‘umount’, the unmount command, and reference the directory that the share is mapped to, (note you need to change director to / to ensure you can unmount the share)
> cd /
> umount /mnt/nas/media
12. Next lets remount with Samba share the credentials file using, that is to not use the username as shown in step 7:
> sudo mount.cifs \\\\192.168.1.200\\shareName /mnt/nas/media -o credentials=/root/creds_smb_library_core,uid=5000,gid=6000
Note: The extra backslashes (\) are not typos. Backslashes are used to escape certain characters. Because of this, we have to double up on them when accessing Microsoft shares.
Ok, Let’s verify this again, use the df command, this command displays all mounted drives.
You should see details as before. If so, woohoo, the credentials file works!
Now to set up the ‘fstab’ file, the ‘file-system table’ file. This will automatically mount the share at startup.
13. Open the fstab file
Next add the following line at the end of the file:
Again this is assuming:
- 192.168.1.200 is the IP of the NAS/Samba Server
- shareName is the name of NAS/Samba share
\\\\192.168.1.200\\shareName /mnt/nas/media cifs credentials=/root/creds_smb_library_core,uid=5000,gid=6000 0 0
The file should look something like this:
# Created by anaconda on Mon May 25 10:52:37 2015
/dev/mapper/centos-root / xfs defaults 0 0
UUID=9d33fce4-de21-4a3a-925b-1014ab2ffed0 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
\\\\192.168.1.200\\shareName /mnt/nas/media cifs credentials=/root/creds_smb_library_core,uid=5000,gid=6000 0 0
Save the file.
14. OK, the last step is to restart the server. After the server has restarted we just want to log on and check that the share has been mounted using the ‘df’ command.
Fingers crossed it has all worked! if so congratulations you have configured your server and the share that holds your media now automatically mounts.
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.
I hope this guide is helpful for some people, at the very least this post will backup my steps if I need to reinstall
. Please let me know if you have any other suggestions to improve this process too!