[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


Adding a Plex media server to a Redhat (Centos) 7 based NAS

Published on
9,341 Points
Last Modified:

In this article, I'll explain how to setup a Plex Media Server on a Redhat (Centos) 7 based NAS with screenshots to help those looking for assistance.

What is Plex?

If you aren't familiar with Plex, it’s a DLNA media server that offers the ability to access your own music, photos, and video. In addition, it also gives you the ability to access these on any of your devices, including PC, Playstation, Xbox, Android phone and tablet, iPhone, iPad, Windows Phone, Chromecast, Roku / Now TV, and so on. Wherever you are, whether that be at home, work, a friends house, or even on a plane (watch your data costs with this one tough, as even a transcoded video will gobble GB's) it will allow access. 

In addition to your media, the service offers the ability to aggregate your own media with artwork, recomendations, and playlists from the web or friends. Essentially it’s a Spotify+Flickr for your content. So, if you’ve got many GB’s of media and are after a handy tool to order and access it, not to mention eliminating the need to physically swap CD’s (just define a few play lists first and control the playback from a phone), this is the perfect tool to help you do so.

In addition to covering the basics, this crib sheet will help you access and map any additional content you have stored in OS X Time Machine sparse bundles, Microsoft .vhd, VMware .vmdk and Oracle .vdi or .iso disk image files on your NAS, or elsewhere on your network. The Plex server is totally file system agnostic, so your media can lurk on the full range of filesysems including, but not limited to: fat, ntfs, ext#, brtfs, nfs, hfs, hfs+, zfs. As long as it can be read by your NAS server, it can be indexed, transcoded, and streamed by Plex.

To get started, follow the steps below:

  • Create a free Plex account here: https://plex.tv/users/sign_up. (Note: This is not essential for internal use, but having an ID will simplify remote access by pushing your own server's IP and public port into their cloud, for your devices to later lookup.)
  • Grab the latest version of the Plex server package URL from here: https://plex.tv/downloads
  • Download and Install the package, and start the service (update the URL if necessary) e.g.

su -
yum install wget
wget https://downloads.plex.tv/plex-media-server/
yum localinstall plexmediaserver- 
service plexmediaserver start
ps -ef | grep -i plex
# A plex media server should now be running under the user-id "plex" eg.
# plex     27302     1  0 Jun25 ?        00:03:54 /usr/lib/plexmediaserver/Plex Media Server
# plex     27346 27302  0 Jun25 ?        00:01:18 /usr/lib/plexmediaserver/Plex DLNA Server

Open in new window

  • Check the local firewall and open ports per the Plex site ie.

netstat -plant | grep -i LIST | grep Plex
firewall-cmd --list-all
cat > /etc/firewalld/services/plexmediaserver.xml << EOS
<?xml version="1.0" encoding="utf-8"?>
<service version="1.0">
  <description>Plex Media Server</description>
  <port port="1900" protocol="udp"/>
  <port port="3005" protocol="tcp"/>
  <port port="5353" protocol="udp"/>
  <port port="8324" protocol="tcp"/>
  <port port="32400" protocol="tcp"/>
  <port port="32400" protocol="udp"/>
  <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"/>
firewall-cmd --permanent --add-service=plexmediaserver
firewall-cmd --reload  
firewall-cmd --list-all

Open in new window

  •  Check to see if the server is accessible:

wget http://localhost:32400/web/index.html

Open in new window

  • If it isn’t check your seLinux settings, and if seLinux is enabled temporality disable and test again, eg.:

[root@localhost ~]# sestatus | grep -i mode
Current mode:                   enforcing
Mode from config file:          enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# sestatus | grep -i mode
Current mode:                   permissive
Mode from config file:          enforcing
[root@localhost ~]# wget http://localhost:32400/web/index.html

Open in new window

  • If that resolves the issue, either make the seLinux change permanent or use the getsebool -a and setsebool commands to resolve the permission issues. 

  • Next, workout where your media resides on your NAS, and whether the photos, music, and / or videos are stored in native files, incorporated into a binary archives, or are on disk images. If it’s the latter, you’ll need to build / install the appropriate utilities to mount one or more of your backups as a read only filesystem, before continuing.
    • If some or all of your content is held in Microsoft .vhd, VMware .vmdk or Oracle .vdi files, then you’ll need a tool such as the Virtualbox based vdfuse to mount the files. If you need it, then the following should start you off: 
rpm --import https://www.virtualbox.org/download/oracle_vbox.asc
rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org
cd /etc/yum.repos.d/
wget http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
yum install VirtualBox-4.3 binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms fuse fuse-devel fuse-libs ntfs-3g cmake boost boost-devel
cd /usr/local/src/
git clone https://github.com/Thorsten-Sick/vdfuse.git
cd vdfuse/
svn co http://www.virtualbox.org/svn/vbox/trunk/include/
sh vdbuild_new include/ vdfuse.c
# Some mount points for the images
mkdir -p /mnt/plex/vhda
mkdir -p /mnt/plex/vhda1
mkdir -p /mnt/plex/vhda2
mkdir -p /mnt/plex/vhda3
mkdir -p /mnt/plex/vhda4
mkdir -p /mnt/plex/vhdb
mkdir -p /mnt/plex/vhdb1
mkdir -p /mnt/plex/vhdb2
mv vdfuse /usr/local/sbin/

Open in new window

  • To use vdfuse to mount a disk image under a read only mount point, you want something along the following lines:

modprobe loop
# Mount the whole disk image under a raw Disk level mount point
vdfuse -r -f /nas/backups/someBackupImage.vhd /mnt/plexMounts/vhda/
# Mount as read only the individual partitions on the disk with the correct Filesystem type.
mount -t ntfs-fuse -o loop,ro,noatime /mnt/plex/vhda/Partition1 /mnt/plex/vhda1
mount -t ntfs-fuse -o loop,ro,noatime /mnt/plex/vhda/Partition2 /mnt/plex/vhda2
mount -t vfat -o loop,ro,noatime /mnt/plex/vhda/Partition3 /mnt/plex/vhda3
mount -o loop,ro,noatime /mnt/plex/vhda/Partition4 /mnt/plex/vhda4
# Mount a second disk image
vdfuse -r -f /nas/backups/someOtherBackupImage.vhd /mnt/plexMounts/vhdb/
mount -t ntfs-fuse -o loop,ro,noatime /mnt/plex/vhdb/Partition1 /mnt/plex/vhdb1
ls /mnt/plex/vhdb1

Open in new window

  • If some media is stored in OS X Time Machine based sparse bundels, then you can similarly build a few toys to mount and use them with sparsebundlefs and tmfs:

cd /usr/local/src/
git clone git://github.com/torarnv/sparsebundlefs.git
cd sparsebundlefs/
yum install fuse fuse-devel fuse-libs gcc-c++
# Create somewhere to mount the Time Machine backup
mkdir -p /mnt/plex/sparsea
mkdir -p /mnt/plex/sparsea1
mkdir -p /mnt/plex/tma1/
mv sparsebundlefs /usr/local/sbin/
# Add HFS+ filesystem support
rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum install kmod-hfsplus
# Create the Time Machine File System (TMFS)
cd /usr/local/src/
git clone https://github.com/abique/tmfs
cd tmfs
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
DESTDIR=install-test make install
make install

Open in new window

  • To use sparsebundlefs to mount a disk image under a read only mount point, you want something along the following lines:

modprobe loop
# Mount the whole disk image under a raw Disk level mount point
sparsebundlefs -f /nas/TimeMachine/myMacBackup.sparsebundle /mnt/plex/sparsea
# Find out which partitions, their location and size are included in the mounted Disk image
[root@localhost plex]# parted /mnt/plex/sparsea/sparsebundle.dmg unit B print
Warning: Unable to open /mnt/plex/sparsea/sparsebundle.dmg read-write (Read-only file system).  /mnt/plex/sparsea/sparsebundle.dmg has been opened read-only.
Warning: Unable to open /mnt/plex/sparsea/sparsebundle.dmg read-write (Read-only file system).  /mnt/plex/sparsea/sparsebundle.dmg has been opened read-only.
Model:  (file)                                                            
Disk /mnt/plex/sparsea/sparsebundle.dmg: 934504050688B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start       End            Size           File system  Name                  Flags
 1      20480B      209735679B     209715200B     fat32        EFI System Partition  boot
 2      209735680B  934369812479B  934160076800B  hfsx         disk image
[root@localhost plex]# losetup
/dev/loop0         0      0         1  1 /mnt/plex/vhda/Partition1
# Mount the desired partition under it's own mount point.
# Note: --offset    = **Start** vale above, minus the traliby B(Byte) character.
#       --sizelimit = **Size** vale above, minus the traliby B(Byte) character.
[root@localhost plex]# losetup -f /mnt/plex/sparsea/sparsebundle.dmg --offset 209735680 --sizelimit 934160076800 --show
[root@localhost plex]# 
mount -t hfsplus -o loop,ro  /dev/loop1 /mnt/plex/sparsea1
# Mount the Time Machine contents under it's own mount point
tmfs /mnt/plex/sparsea1 /mnt/tm-root -ouid=$(id -u),gid=$(id -g),allow_other
ls /mnt/plex/tma1/*/Latest/Macintosh\ HD/

Open in new window

  • If some media is stored in iso disk images, these can similiarly be mounted and mapped:

modprobe loop
mkdir -p /mnt/iso/dvd0
mkdir -p /mnt/iso/cd0
mount -t iso9660 -o loop /nas/backups/iso/some-DVD.iso /mnt/iso/dvd0
mount -t iso9660 -o loop /nas/backups/iso/some-CD.iso /mnt/iso/cd1

Open in new window

  • If you’ve specifically mounted any backup images, stick the relevant commands to mount and unmount these files in the start() / stop() functions of your /etc/init.d/plexmediaserver script.

  • From a browser, access the Plex Media Server web interface: http://your.Nas.Hostname.Or.IP:32400/web/index.html
  • Login with your newly created Plex credentials (top right)
  • Click the + (add library) icon at the top left, just after your servers host name, to start adding media:Screen-Shot-2015-06-24-at-02.42.56.png
  • Start by adding (associating) some music with your Plex server by simply selecting the correct icon:Screen-Shot-2015-06-24-at-02.44.35.png 
  • Navigate to your iTunes, Media Center media backups and add one or more directories to the Plex library:Screen-Shot-2015-06-24-at-02.45.04.png 
  • Then, wait a while as the server indexes your content.
  • Once done, test the import has worked by:
    • On your Playstation, navigate to Music and make sure your Plex server is showing the artists, albums and artwork, and make sure you can play the music.
    • On your Android device, install the Plex for Android from the Google Play or Amazon stores. Open it, login, open the navigation drawer (top left), navigate the imported library, and attempt to play something. You'll then be prompted for an in app purchase. If you spend a few pennies, music should start to play.
      • ​You can also use the app as a remote for a Chromecast, Playstation, or Xbox playing media.
    • On your iPad / iPhone, buy the Plex app, login and play, and test per Android. You can also Airplay to an AppleTV.
    • If you have a Now TV branded Roku box, you can use either of these sets of instructions to have a play through your TV: Plex/Roku v3.1.0 or How to turn Sky's £10 Now TV box into a networked media player with Plex

  • Once the server is streaming Music, map your Video and Photo directories to seperate libraries on the server, and repeat the tests. (Note: video quality will be dependent on avaialble bandwidth and the CPU grunt available to transcode the streams. There are a few options to tweak the tanscoding if not optimal, but largely heardware dependent.)
  • Next, configure external access to your server. To do this, you'll need to configure your ADSL / Cable router to permit TCP+UDP based requests to come in on one port and for the traffic to be [re]directed on to port 32400 on your NAS server (Plex's default). The simplest solution is to make a straight mapping in your routers firewall, and will more than likely be supported by your router, but there's a slightly higher security risk in opening a standard port. This is primarily due to the number of script kiddies out there who will ping a services standard ports on every known IP (all 4 billion) the second a vunerability is found in a particular service. To deter a drive past hack, it's preferable to open a non-standard port on your routers firewall and redirect it back to port 32400 on the server running Plex. Unfortunately, not all manufacturers support this functionality on all of their routers, but if you want the extra security, you can always perform the remapping  in the Plex servers firewall.  To start:
    • Navigate to your routers web interface eg. and login. The Portforward.com site will give the sepcifics for your router.
    • Find the port fordwarding panel and either simply define a public TCP+UDP (both protocols are used) service for Plex / port 32400, or add a rule that maps this service to your Plex servers IP.
      • Alternitively:
        • Say have a Cisco router where you can specify a different external and internal port in the service defenition. You may choose to open a non-standard external port eg. 44444
        • Say have a Netgear router that dosen't permit you to use different internal and external ports (not without a hack that needs to be reinstated after each reboot). Simply define a service for the desired external port, and forward this to your Plex server on the same non standard port eg. 44444
          • ​Then on your Plex server open your chosen port (here: 44444) and redirect it to the standard Plex port (32400):

# Change interface: enp3s0 (per --get-active-zones) and dport 44444 to suit

firewall-cmd --add-port=44444/tcp --permanent
firewall-cmd --add-port=44444/udp --permanent
firewall-cmd --direct --add-rule ipv4 nat PREROUTING 0 --in-interface enp3s0 --protocol udp --dport 44444 --jump REDIRECT --to-ports 32400  --permanent
firewall-cmd --direct --add-rule ipv4 nat PREROUTING 0 --in-interface enp3s0 --protocol tcp --dport 44444 --jump REDIRECT --to-ports 32400  --permanent
firewall-cmd --reload  
firewall-cmd --get-active-zones
firewall-cmd --direct --get-all-rules

Open in new window

  • Navigate to http://ip.Of.Your.Plex,Server:32400/web/index.html#!/settings/server and select Remote Access in the navigation drawer. Enable Advanced mode. Fill in the port you've opened in your routers firewall, and press Test

    • If it comes back with an error, go back through the process. You should see the following:Screen-Shot-2015-06-25-at-04.09.03.png
  • If you want to verify this yourself, grab a phone with the Plex App on, disable WiFi (or connect to an external network), and connect to your library.
  • You're almost there! Next, create a playlist or 20, and enjoy:Screen-Shot-2015-06-25-at-01.11.34.png



Featured Post

The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

Join & Write a Comment

There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month