A Complete Plex Home Media Centre on CentOS 7

I used to run Plex, Sick Beard and CouchPotato all on a Windows 8 VM. It always annoyed me though in that I had to leave a terminal services connection open at all times for Plex to keep running. Then I upgraded the machine to the Windows 10 tech preview, and it drove me nuts rebooting itself every few days (yeah yeah, I know, it’s a tech preview).

So I decided to have a little fun and built a CentOS 7 VM to host my media centre instead. I was also curious to see if it would have better performance, and so far it seems to have improved a little from the clients I used to connect to it.

I’ve done this on CentOS, as opposed to Debian variants, because any skills learned translate better to the work I do with RHEL-based customers.

Server Setup

I provisioned a Windows 8 Hyper-V VM with 30GB space and 2GB of static RAM. 2GB should be plenty, unless you’re doing some intense transcoding with plex.

I installed CentOS 7 with the minimal install option, to help keep things lightweight.

Starting with some initial configuration of the server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
## Elevate to root:
sudo su

## Update the Server
yum update -y

## Turn off SELinux, because I can't be bothered configuring it for just my home network
sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config

## Install the Prerequisites
yum install epel-release -y
yum install wget yum-cron python python-cheetah git -y

## Turn on Auto Updates
sed -i 's/apply_updates = no/apply_updates = yes/g' /etc/yum/yum-cron.conf

## Restart the Server
shutdown -r now

Firewall Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
firewall-cmd --permanent --zone=internal --change-interface=eth0
firewall-cmd --permanent --zone=internal --add-source=192.168.0.0/24
firewall-cmd --permanent --zone=internal --add-service=ssh
firewall-cmd --permanent --zone=internal --add-service=samba
firewall-cmd --permanent --zone=internal --add-service=ntp
firewall-cmd --permanent --zone=internal --add-service=dns
firewall-cmd --permanent --zone=internal --add-service=smtp
# Sick Beard:
firewall-cmd --permanent --zone=internal --add-port=8081/tcp
# CouchPotato:
firewall-cmd --permanent --zone=internal --add-port=5050/tcp
# Headphones:
firewall-cmd --permanent --zone=internal --add-port=8181/tcp
# Plex:
firewall-cmd --permanent --zone=internal --add-port=32400/tcp
## This is required if you want to access the Plex server from outside of your internal network:
firewall-cmd --permanent --zone=public --add-port=32400/tcp
firewall-cmd --reload

Installing SickBeard

This is also covered here.

1
2
3
4
5
6
## Install Sickbeard
adduser sickbeard
cd /opt/
git clone git://github.com/midgetspy/Sick-Beard.git sickbeard
chown -R sickbeard:sickbeard sickbeard/
cp sickbeard/init.systemd /etc/systemd/system/sickbeard.service

Installing CouchPotato

Just like Sick Beard, I’ve blogged about this before.

1
2
3
4
5
6
7
8
9
## Install Couchpotato
adduser couchpotato
cd /opt/
git clone git://github.com/RuudBurger/CouchPotatoServer.git couchpotato
chown -R couchpotato:couchpotato couchpotato/
cp couchpotato/init/couchpotato.fedora.service /etc/systemd/system/couchpotato.service

## Fix the Startup Script to point to the /opt/ directory
sed -i 's\ExecStart=/var/lib/CouchPotatoServer/CouchPotato.py --daemon\ExecStart=/opt/couchpotato/CouchPotato.py --daemon\g' /etc/systemd/system/couchpotato.service

Installing Headphones

I only just discovered headphones. I included it here as it looks interesting, but I haven’t really done anything with it yet.

1
2
3
4
5
6
7
8
9
10
11
12
13
## Install Headphones
adduser headphones
cd /opt/
git clone https://github.com/rembo10/headphones.git headphones
chown -R headphones:headphones /opt/headphones/
cp headphones/init-scripts/init.fedora.centos.systemd /etc/systemd/system/headphones.service

## Fix the Startup Script to point to the /opt/ directory
sed -i 's\/home/sabnzbd/headphones/Headphones.py\/opt/headphones/Headphones.py\g' /etc/systemd/system/headphones.service
sed -i 's\/etc/headphones/headphones.ini\/opt/headphones/headphones.ini\g' /etc/systemd/system/headphones.service
sed -i 's\/home/sabnzbd/.headphones\/opt/headphones/.headphones\g' /etc/systemd/system/headphones.service
sed -i 's\User=sabnzbd\User=headphones\g' /etc/systemd/system/headphones.service
sed -i 's\Group=sabnzbd\Group=headphones\g' /etc/systemd/system/headphones.service

Installing Plex

Things are easy here, as Plex distribute rpm packages for installation:

1
2
3
## Download and Install Plex
wget https://downloads.plex.tv/plex-media-server/0.9.12.2.1124-e797a3e/plexmediaserver-0.9.12.2.1124-e797a3e.x86_64.rpm
yum install plexmediaserver-0.9.12.2.1124-e797a3e.x86_64.rpm -y

Note: I have a Plex pass subscription, so I’ve grabbed that subscriber version. Simply change the URL to whatever is posted on the plex.tv website.

Enable and Start the Services

1
2
3
4
5
6
7
8
9
systemctl enable couchpotato
systemctl enable headphones
systemctl enable plexmediaserver
systemctl enable sickbeard

systemctl start couchpotato
systemctl start headphones
systemctl start plexmediaserver
systemctl start sickbeard

Now all of the services should be up and running. I don’t run sabnzbd at all, as I don’t use CouchPotato or Sick Beard to actually download anything. They’re just there to keep my media clean and organised.

Additionally, as long as your Router allows inbound connections on 32400 (or you’ve set up a forwarded port) then you should be able to connect Plex to the plex.tv site for remote access.

Bonus: Adding Nagios Monitoring

I run a Nagios server at home, mostly to fire alerts at me if this website goes down or my SSL certificate expires. Here’s what I did to enable monitoring of my new server, telling me if any of the services fall over:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## Install the nrpe service
yum install nagios-nrpe nagios-plugins-all -y

## Allow the Nagios Server to connect
sed -i 's\allowed_hosts=127.0.0.1\allowed_hosts=127.0.0.1,192.168.0.50\g' /etc/nagios/nrpe.cfg

## Set up the checks
vi /etc/nagios/nrpe.cfg
## add:
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/centos-root
command[check_ping]=/usr/lib64/nagios/plugins/check_ping -H 127.0.0.1 -w 100.0,20% -c 500.0,60%
command[check_swap]=/usr/lib64/nagios/plugins/check_swap -w 20 -c 10
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 260 -c 300
command[check_plexmediaserver]=/usr/lib64/nagios/plugins/check_procs -c 1:10 -a plexmediaserver
command[check_sickbeard]=/usr/lib64/nagios/plugins/check_procs -c 1:1 -a sickbeard
command[check_couchpotato]=/usr/lib64/nagios/plugins/check_procs -c 1:1 -a couchpotato
command[check_headphones]=/usr/lib64/nagios/plugins/check_procs -c 1:1 -a headphones

## Firewall Configuration
firewall-cmd --permanent --zone=internal --add-port=5666/tcp
firewall-cmd --reload

## Enable & Start the Service
systemctl enable nrpe
systemctl start nrpe

Plex spins up more than one service, so you may notice a different configuration for that service check. I also found the machine breaches the standard check_procs limit of 250, so I bumped the tolerance up a little.

Bonus: Mounting a Windows Network Share

This wasn’t as straightforward as I would’ve liked. I’ve never mounted an SMB share before, only local drives, so it took me a while to get a solution with the correct permissions working.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Install prerequisites
yum install cifs-utils -y

## Setup user and group for the share (this user has the same name as an AD account with privileges to access the share)
useradd -u 5000 mediaserver
group -g 6000 mediaservergroup

## Add the Users that need access to the share
usermod -G mediaservergroup -a sickbeard
usermod -G mediaservergroup -a couchpotato
usermod -G mediaservergroup -a headphones
usermod -G mediaservergroup -a plex

## Create the folder that the share will live in
mkdir /mnt/media

## Create a credentials file, with root only access
sudo su
cd ~
touch smb-credentials
echo "username=mediaserver" >> smb-credentials
echo "password={password}" >> smb-credentials
chmod 0600 smb-credentials

## Add the entry to fstab to mount on boot (this is all one line)
echo '//SERVER/Share /mnt/media cifs uid=5000,gid=6000,rw,credentials=/root/smb-credentials,file_mode=0775,dir_mode=0775 0 0' >> /etc/fstab

## Finally, mount the drive
mount -a

The share should mount now on boot. I found if I didn’t specify the file_mode and dir_mode, then the mounted share would only have 0755 permission everywhere, preventing any software from making changes to the file system.