Configuring Plex
17. July, 2021 • 7 min read • Homelab
“Plex marks the spot for free streaming”
I'm a data hoarder; that's nothing new to people who know me. This year around, I drove my passion a little bit further and streamlined my setup. The following articles will be a multi-part series introducing various areas such as:
- Introduction
- Virtualisation using a PowerEdge R820
- Storage with a QNAP TVS-1271U-RP
- Networking with Ubiquiti
- Media streaming with Plex
- Download management with SABnzb and Transmission
- Service management with Sonarr, Radarr, Lidarr, Readarr, Bazarr and Mylar
- Additional tools like Calibre, Ubooquity, Ombi or Organizr
- Monitoring with Checkmk
Before we begin
The following chapters will be focusing on tutorials with instructions on how to set up the respective services.
All services run on Virtual Machines using Ubuntu server 20.04 LTS. A section featuring the specific setup instructions is available at the end of this article.
Installing Plex
With your Ubuntu server ready, head over to the Plex website and choose the correct installation package from the downloads page. Copy the link and replace it with the {download-link}
placeholder and run the commands in sequence:
wget {download-link}
sudo apt install beignet-opencl-icd
sudo apt install ocl-icd-libopencl1
sudo dpkg -i {download-package}
sudo dpkg -L plexmediaserver
rm {download-package}
Make sure to replace {download-package}
with the respective package name 😎.
Monitor the prompt output for additional warnings or errors after running the commands. There may be subsequent packages you need to install.
Next, check the status of the Plex server and stop it for now by executing:
sudo systemctl status plexmediaserver
sudo systemctl stop plexmediaserver
sudo systemctl disable plexmediaserver
Following, enable the Plex repository by uncommenting the content in /etc/apt/sources.list.d/plexmediaserver.list
. Save the file and run the following commands:
wget -q https://downloads.plex.tv/plex-keys/PlexSign.key -O - | sudo apt-key add -
sudo apt update
sudo apt upgrade
sudo systemctl start plexmediaserver
Restart the server, and you are ready to start configuring Plex. The administration interface is reachable through x.x.x.x:32400/web. You can get the full address by running netstat -lnpt | grep Plex
.
Configuring Plex
If you want to migrate an existing Plex instance, stop here and read Migrating an existing Plex instance first. If this is not the case, continue with the configuration.
The configuration itself is pretty straight forward. Login to your account, give your server a name and add your shares. There is also a section available that demonstrates how to set up the mounts on Ubuntu.
Using a static IP address
This step is optional, but I prefer to set a static IP address for my VMs. Alternatively, add your instance hostnames to your DNS configuration to reach them locally.
To get started, figure out the network identifier that connects to your network by running ip a
. In my case, it is ens224. Then create /etc/netplan/01-netcfg.yaml
with the following content:
network:
version: 2
ethernets:
ens224:
dhcp4: no
addresses:
- 192.168.1.200/24
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.1, 8.8.8.8, 1.1.1.1]
You may need to replace ens224 with your network identifier and 192.168.1.200/24 with the desired IP address. You may also have a different gateway and nameservers. To apply the settings, run:
sudo netplan apply
ip addr show dev ens224
Enabling auto-updates for Ubuntu
I prefer Ubuntu to be updated at all times. If something breaks, I instead revert to a snapshot than having security issues. To get started. run:
sudo apt install unattended-upgrades
sudo vim /etc/apt/apt.conf.d/50unattended-upgrades
In the editor uncomment the following lines:
"${distro_id}:${distro_codename}-updates";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Next edit /etc/apt/apt.conf.d/20auto-upgrades
and replace the content with:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
You can test the changes by running sudo unattended-upgrades --dry-run --debug
and checking the logs in cat /var/log/unattended-upgrades/unattended-upgrades.log
.
Enabling auto-updates for Plex
Plex needs some special care to update automatically. Luckily there is a great script available on github.com/mrworf/plexupdate. Follow the instructions in the README.md
, and the subsequent terminal prompts.
Installing NVidia drivers
GPU passthrough is a bit of a hassle. Using a consumer GeForce GTX 1050 TI doesn’t make it easier. However, I got it to work on my setup by using the following steps:
Make sure ESXi support passthrough by adding:
hypervisor.cpuid.v0 = FALSE
pciPassthru0.msiEnabled = FALSE
to the VM configuration. Next, installing the drivers:
sudo apt install ubuntu-drivers-common
ubuntu-drivers devices
sudo ubuntu-drivers autoinstall
Next, we need to confirm that hevc_nvenc_** is working by running:
sudo apt remove ffmpeg
sudo snap install ffmpeg
ffmpeg -hwaccels
the last command should output something like:
Hardware acceleration methods:
vdpau
cuda <- this is important
vaapi
drm
opencl
Finally, we need to make sure that the system doesn’t boot in UI mode by running:
sudo systemctl set-default multi-user.target
sudo reboot -r now
Extra: Migrating an existing Plex instance
I had an existing Plex instance using a Mac Mini and needed to migrate it to the new Ubuntu server. This section is based on Moving an Install to Another System. In short:
- On the old Plex instance, disable the Empty trash automatically after every scan preference for the server.
- Do not configure anything on the new Plex instance yet. To be safe, sign out and stop the server by running
sudo systemctl stop plexmediaserver
. - Ideally, do the same for the old server. I had a running live system that I didn’t want to shut down during the process.
Now that everything is prepared copy the old instance’s data to the new server by using rsync. Rsync allows you to run the command multiple times even if there are network issues or running the old instance side-by-side.
Make sure both servers have rsync installed by executing sudo apt install rsync
. Add the following script to the server of the new Plex instance:
echo "rsync -avz --delete --exclude 'Cache' user@x.x.x.x:/var/lib/plexmediaserver/ /var/lib/plexmediaserver/
sudo chown -R plex:plex /var/lib/plexmediaserver
sudo chmod -R 755 /var/lib/plexmediaserver" > ~/plexmigrate.sh
chmod +x plexmigrate.sh
Replace user@x.x.x.x with the user/IP of your old Plex instance.
Finally, you can run the command using sudo ./autosync.sh
and start the migration. Once finished, make sure to turn off the old Plex instance permanently and start the new one:
# on the old server
sudo systemctl stop plexmediaserver
sudo systemctl disable plexmediaserver
# on the new server
sudo systemctl start plexmediaserver
sudo systemctl enable plexmediaserver
Extra: Setting up mounts
QNAP supports several protocols though I chose to use NFS as it worked best for my use case.
First, folders need to be created to mount the individual folders too. In my case, I used /media/
and added the subsequent sub-folders inside it.
Next, install the requirements into Ubuntu:
sudo apt install network-manager
sudo apt install nfs-common
Now, we can check if a connection can be established like:
sudo mount -t nfs x.x.x.x:/server/folder /media/photos
and replace x.x.x.x with the IP address of the storage server. If all works prepare the /etc/fstab
file as follows:
x.x.x.x:/server/folder1 /media/folder1 nfs _netdev,auto,x-systemd.automount 0 0
x.x.x.x:/server/folder2 /media/folder2 nfs _netdev,auto,x-systemd.automount 0 0
x.x.x.x:/server/folder3 /media/folder3 nfs _netdev,auto,x-systemd.automount 0 0
Replace x.x.x.x again with the IP address of the storage server and map the respective folders to their counterpart on Ubuntu. The additional options ensure that the folders get automatically mounted after a restart and wait for the server to be available.
Extra: Setting up Ubuntu
Get the latest version of Ubuntu server and follow the general installation steps. You may want to get the current IP through ip a
and ssh into your Ubuntu instance. After that, run the following commands:
sudo apt update
sudo apt upgrade
sudo apt full-upgrade
sudo apt install net-tools
Apply these steps for any other service you want to install.
So what’s next
We have now instructions for setting up Ubuntu in general and our first VM running Plex. In the next chapter, I’ll be setting up the DVR to manage content.
‘Till next time!