Plex Media Server on a Raspberry Pi 3

It has been a while since I wrote up a “how-to” for the Raspberry Pi and I thought I would share my latest project with you. I purchased a Raspberry Pi 3B+ to replace my RPi 2 as a media server. In case you are new to the Raspberry Pi. Here are the specs for the 3B+:

  • SOC: Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC
  • CPU: 1.4GHz 64-bit quad-core ARM Cortex-A53 CPU
  • RAM: 1GB LPDDR2 SDRAM
  • WIFI: Dual-band 802.11ac wireless LAN (2.4GHz and 5GHz ) and Bluetooth 4.2
  • Ethernet: Gigabit Ethernet over USB 2.0 (max 300 Mbps). Power-over-
  • Ethernet support (with separate PoE HAT). Improved PXE network and USB mass-storage booting.
  • Thermal management: Yes
  • Video: Yes – VideoCore IV 3D. Full-size HDMI
  • Audio: Yes
  • USB 2.0: 4 ports
  • GPIO: 40-pin
  • Power: 5V/2.5A DC power input
  • Operating system support: Linux and Unix

I have tried and tested many tutorials that I have found online, but this Medium post from Niha M is fantastic, Plex Media Server on Raspberry Pi 3 using Raspbian Lite (Stretch).

I followed all of Niha’s instructions but I had the following modifications:

  1. I am using a wired gigabit network and will not be using Wifi.
  2. I reserved a static IP address through DHCP reservation in my router.
  3. I left the metadata on the SD card.
  4. I attached a 2GB HDD and set up the SAMBA share to make it easier to transfer video, audio, and pictures from my laptop to the server.

I additionally set up a backup script for the SD card since I have had them go bad in the past. I followed the instructions from GrammatonCleric on the Ubuntu Forums.

What I did:
Filled the SD card with zeros because when I compress the image it will shrink down considerably.

dd if=/dev/zero of=/tmp/disk_zero_fill.tmp bs=8M; rm -f/tmp/disk_zero_fill.tmp

I then copied the entire drive to an image and compressed it, by creating an executable script.

bakup_sdcard.sh

##################################
# set date variable 
################################## 

tdy=`date +%m%d%Y`  

################################## 
# Remove img.gz files older than 21 days 
################################## 

find /path/to/usbdrive/pi_image_bkup.*.img.gz -type f -mtime +21 exec rm {} \;  

################################## 
# consider zeroing unused space before imaging. 
# remove # in front of line below enable this function 
# this step it will reduce the lifespan of the SD card 
################################## 

# dd if=/dev/zero of=/dev/mmcblk0/disk_zero_fill.tmp bs=8M; rm -f /dev/mmcblk0/disk_zero_fill.tmp 

##################################
# image server to new location
##################################

dd bs=8M if=/dev/mmcblk0 conv=sync,noerror | "gzip > /path/to/usbdrive/pi_image_bkup.$tdy.img.gz

I automated the script to backup once a week by adding a Cron Job that runs on Sundays at 2AM.

0 2 * * 0 /path/to/script/bakup_sdcard.sh > /dev/null 2>&1

Now if the SD card goes bad; I can ungzip the latest image on the HDD and burn it to a new SD card and not have to rebuild the Plex server. I have also backed up all my media to a second external drive (just in case).

Bonus: My clean-up script that I run once a week.

echo "Cleaning Up" && 
sudo apt-get update && 
sudo apt-get -y upgrade && 
sudo apt-get -f install && 
sudo apt-get autoremove && 
sudo apt-get -y autoclean && 
sudo apt-get -y clean && 
sudo find /var/log/ -type f -regex '.*\.[0-9]+\.gz$' -delete

Finding a Virtual Private Server

From 2004 to 2014, I was using a shared hosting service for my personal domain (fusco.ca) which cost me about C$4/month. It was a great way to get your site up and running and it was really easy to manage. However, as the popularity of the Internet grew and everyone was looking for a place to host their website, I found these shared hosting services became very crowded. This caused my site to slow down dramatically.

If you are using a shared hosting service, check out www.ip-neighbors.com to see how many websites are sharing your IP address and possibly your server. One of the reasons my site slowed down, was because there were a couple of adult sites sharing my IP address and they were using the majority of the server’s resources.

In 2014, I decided to migrate my site to a new server. I had discovered VPS’s (Virtual Private Servers). The difference with this hosting service is that you get to control the Operating System and customize the service to suit your needs. You do share the server hardware with other users but everyone has their own IP address and block of space on the server. They are considerably less crowded than shared hosting.

While looking for a VPS, I came across the site LowEndBox which is like a clearing house for VPS’s. I stumbled onto a great “Black Friday” deal for a VPS with a quad core cpu, 2 GB ram, 30 GB SSD, and a 1 Gbit Internet connection for just US$20/year. The offers are always changing so keep an eye out.

After I found a VPS, I had to learn about administrating it. The first thing I did was install Ubuntu Server LTS as the OS, using much of the advice from this DigitalOcean tutorial. I also found tutorials on setting up a firewall , adding additional security to protect my server, and setting up my LAMP stack to host my site.

The great thing about DigitalOcean is that they have tutorials for a wide variety of OS’s and can guide you through anything you want to do with your server. For example, I followed this guide on Virtual Hosts to host multiple domains on my VPS.

That is it for now, next time I will share how to get a domain and have it connect to your new VPS.