This post will show you how to setup up a Plex media server on a Raspberry Pi
Setting up the PI
Its very simple to setup a SD card for a Raspberry Pi:
- Reformat the entire SD card to FAT32
- Download the latest version of Raspbian Lite from here
- Use a program, like Etcher to write the zip/iso to your newly formatted SD card
At this point you can bootup your newly formatted Raspberry Pi, but I always complete these additional two steps to get SSH access working on my Raspberry Pi and enabling WiFi connecting for the Raspberry Pis that support Wireless Internet (Raspberry Pi 3 and Raspberry Pi Zero W):
- Create a blank file called
ssh
in the boot folder of your SD card - Copy this template to create your own wpa_supplicant.conf file. Put this file in the same boot folder and add your SSID between the quotes and your wifi password between the quotes
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid=""
psk=""
}
Congratulations, your Raspberry Pi is ready to go and should enable SSH access and automatically connect to your wifi. By default, the login is pi and the password is raspberry.
Note: On bootup, the .ssh and wpa_supplicant.conf files will be deleted. This is okay, as the settings are written back to the raspberry pi
Connecting to zerotier
Now you can connect to your pi. However you can only connect to it while you are on the same network. We can use ZeroTier to connect to the pi from anywhere.
- Sign up for a ZeroTier account if you do not already have one
- Set up a ZeroTier network that you would like to use
- Install zerotier on your pi
curl -s https://install.zerotier.com | sudo bash
- To ensure ZeroTier starts on system boot
sudo systemctl enable zerotier-one
- Connect to your ZeroTier network
sudo zerotier-cli join [Network ID]
- you will have to accept the connection from your ZeroTier account.
- To have your Raspberry Pi automatically join the virtual network on system boot, simply run
sudo touch /var/lib/zerotier-one/networks.d/[Network ID].conf
- You can now reboot your pi and you will see on the ZeroTier network page that it connects automatically when it boots
Mounting an external hard drive to your pi
The pi is up and running but now we need to mount a storage device to it so we can store all of the Plex data
- Find your drive with this command. Mine in this example is at /dev/sda1
sudo fdisk -l
- Install NTFS-3g if you havent already
sudo apt-get install ntfs-3g
- Create the directory you want to mount
sudo mkdir /media/plex
- Manage that directorys owner
sudo chown pi:pi /media/plex
- Mount the drive
sudo mount -t ntfs-3g -o uid-pi,gid-pi /dev/sda1 /media/plex
Now the hard drive is mounted to your pi. To make the mount permanent we need to edit the filesystem tab
sudo vim /etc/fstab
- Add this line at the bottom of that file and save the file
/dev/sda1 /media/drive ntfs-3g uid=pi,gid=pi 0 0
- This now will be mounted permanently and will persist through restarts
Setting up plex
We have our pi configured, are able to connect to it from anywhere and it has a storage device mounted to it. Last thing we need to do is setup the Plex media server
- Install docker
curl -sSL https://get.docker.com | sh
- Install docker-compose
sudo apt-get install -y libffi-dev libssl-dev
sudo apt-get install -y python3 python3-pip
sudo apt-get remove python-configparser
sudo pip3 -v install docker-compose
- Create your plex directories
mkdir -p ~/media/plex/{config,data,transcode}
- For this next part you will need your Plex claim token which can be found here
- Copy this docker-compose.yaml file and add in your Plex claim token
version: '3.3'
services:
plex-server-docker-rpi:
volumes:
- /media/plex/config:/config
- /media/plex/data:/data
- /media/plex/transcode:/transcode
container_name: 'plex'
network_mode: 'host'
restart: 'always'
environment:
- SET_PLEX_UID=1001
- SET_PLEX_GID=1001
- PLEX_CLAIM=[Plex Claim Token]
image: 'greensheep/plex-server-docker-rpi:latest'
- Now we need to spin up the docker container
sudo docker-compose up
- After around 30 seconds, the Plex web admin should be available at http://{ip address of Pi}:32400/web