Skip to content

Instantly share code, notes, and snippets.

@Nilpo
Last active June 26, 2019 05:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nilpo/85d820f8f2217dc4c43d7253cfd00b33 to your computer and use it in GitHub Desktop.
Save Nilpo/85d820f8f2217dc4c43d7253cfd00b33 to your computer and use it in GitHub Desktop.
Install Plex on Raspbian Stretch for Raspberry Pi 3
  1. In terminal, upgrade Raspbian.

    sudo apt update && sudo apt dist-upgrade -y
  2. Next, use the raspi-config tool to change some default system settings.

    sudo raspi-config

    With a default installation of Raspbian, you should always change the password for the default "pi" user. For added security, we'll be replacing the "pi" user later so there's no need to complete this step now.

    Under Network Options, choose Hostname and set it to something memorable such as plexpi. You can also set it from the command line.

    echo "plexpi" > /etc/hostname && sudo hostname plexpi

    Also under Network Options, you can set your Wi-Fi information if you are not connected by Ethernet. A wired connection is highly recommended over wireless for running a Plex Media Server.

    If you intend on storing your media library on a network share or NAS, it's a good idea to go under Boot Options and choose Wait for Network at Boot and set it to Yes. This will pause during startup until the network is connected so that it doesn't attempt to mount network volumes before the network is ready.

    Under Localisation Options, check Change Locale, Change Timezone, and Change Keyboard Layout to make sure all of the settings match your location. If you are running your Plex Media Server on the newer Raspberry Pi Model B+, you must use the Change Wi-Fi Country and set it correctly before the system will connect to a wireless network.

    Next, you'll want to enable SSH so that you can connect to your Raspberry Pi remotely. Under Interfacing Options, choose SSH and choose Yes. Once again, you can also do this from the command line.

    sudo touch /boot/ssh

    Reboot your Pi for these settings to take effect.

    sudo reboot
  3. Assign your Pi a static IP address.

    • For wired connections:

      export IP=`hostname -I`
      export GW=`netstat -nr | grep 'UG[ \t]' | awk '{print $2}'`
      export NS=`netstat -nr | grep 'UG[ \t]' | awk '{print $2}'`
      sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
      echo -e "interface eth0" | sudo tee -a /etc/dhcpcd.conf
      echo -e "static ip_address=`echo $IP`/24" | sudo tee -a /etc/dhcpcd.conf
      echo -e "static routers=`echo $GW`" | sudo tee -a /etc/dhcpcd.conf
      echo -e "static domain_name_servers=`echo $NS`" | sudo tee -a /etc/dhcpcd.conf
    • For wireless connections:

      export IP=`hostname -I`
      export GW=`netstat -nr | grep 'UG[ \t]' | awk '{print $2}'`
      export NS=`netstat -nr | grep 'UG[ \t]' | awk '{print $2}'`
      sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
      echo -e "interface wlan0" | sudo tee -a /etc/dhcpcd.conf
      echo -e "static ip_address=`echo $IP`/24" | sudo tee -a /etc/dhcpcd.conf
      echo -e "static routers=`echo $GW`" | sudo tee -a /etc/dhcpcd.conf
      echo -e "static domain_name_servers=`echo $NS`" | sudo tee -a /etc/dhcpcd.conf

    Restart the networking services or reboot.

    sudo systemctl restart dhcpcd
  4. You can continue accessing your Pi locally, or connect to it via ssh with ssh pi@plexpi.local.

  5. For added security, replacing the provided "pi" user is highly recommended. This makes it much more difficult for an attacker to gain access to your system.

    All of the following commands must be completed as root, so you can save a few keystrokes by changing to a root prompt.

    sudo -i

    Add a new user named "pmsadmin". (You can use any user name of your own choosing, but you will need to adjust commands throughout the rest of this guide.)

    # adduser pmsadmin
    Adding user `pmsadmin' ...
    Adding new group `pmsadmin' (1001) ...
    Adding new user `pmsadmin' (1001) with group `pmsadmin' ...
    Creating home directory `/home/pmsadmin' ...
    Copying files from `/etc/skel' ...
    Enter new UNIX password: <enter a secure password>
    Retype new UNIX password: <repeat the new password>
    passwd: password updated successfully
    Changing the user information for pmsadmin
    Enter the new value, or press ENTER for the default
     Full Name []: Rob Dunham
     Room Number []: 
     Work Phone []: 
     Home Phone []: 
     Other []: 
    Is the information correct? [Y/n] y

    Add the new user to the sudo group.

    # adduser pmsadmin sudo
    Adding user `pmsadmin' to group `sudo' ...
    Adding user pmsadmin to group sudo
    Done.

    Disconnect from the Pi and log in with the newly created user.

    # exit
    $ exit

    To reconnect with SSH:

    ssh -4 pmsadmin@plexpi.local

    Delete the pi user.

    $ sudo deluser pi
    [sudo] password for pmsadmin: 
    Removing user `pi' ...
    Warning: group `pi' has no more members.
    Done.

    Create a password for the root account.

    sudo passwd root
  6. Install Plex Media Server.

    Make sure the Apt can use https repositories.

    sudo apt install apt-transport-https

    Add the Plex Media Server repository.

    echo "deb https://dev2day.de/pms/ stretch main" | sudo tee /etc/apt/sources.list.d/pms.list

    Add the GPG key for the repository.

    wget -O - https://dev2day.de/pms/dev2day-pms.gpg.key | sudo apt-key add -

    Update Apt sources and install Plex Media Server.

    sudo apt update
    sudo apt install -t stretch plexmediaserver-installer

    Create a default config file for Plex.

    echo "PLEX_MEDIA_SERVER_USER=pmsadmin" | sudo tee -a /etc/default/plexmediaserver.prev
    sudo chown -R pmsadmin:pmsadmin /var/lib/plexmediaserver

    Create a systemd service override configuration that will launch the plexmediaserver service with the correct user. (This step is added for situations where Plex starts, but does not listen on port 32400 as expected.)

    sudo systemctl stop plexmediaserver
    sudo systemctl edit plexmediaserver

    Paste in the following text and save the file. To save the file press Ctrl+x, then type Y and press Enter.

    #
    # Customize Plex's config
    #
    [Service]
    User=pmsadmin
    Group=pmsadmin
    

    Restart the Plex Media Server service.

    systemctl daemon-reload
    sudo systemctl start plexmediaserver

    You can verify that the server is running with the following commands:

    systemctl plexmediaserver status
    sudo netstat -lptu | grep 32400

    (Optional) Attach a network share where your media library can be found. Skip this step if your library is local to the device. //192.168.1.1/share1 should be changed to match the location of your network share. Also make sure that you change "pmsadminpassword" to match your password.

    $ sudo su
    # mkdir -p /mnt/shares/media
    # echo "username=pmsadmin" >> ~/.smbcredentials
    # echo "password=pmsadminpassword" >> ~/.smbcredentials
    # chmod 600 ~/.smbcredentials
    # echo "//192.168.1.199/share1  /mnt/shares/media  cifs  credentials=/root/.smbcredentials,_netdev,vers=1.0  0  0" >> /etc/fstab
    # exit

    Reboot to test that the share is mounted at boot or mount it now without a reboot.

    sudo mount -a

    You can now access your Plex Media Server in your favorite browser and complete the setup wizard.

    http://plexpi.local:32400/web
    
  7. Next, we'll install Tautulli, a web app for monitoring Plex Media Server. Tautulli requires Python 2.7 which is installed by default and is not compatible with Python 3. You can check your version with python --version.

    sudo apt install git-core
    cd /opt
    sudo git clone https://github.com/Tautulli/Tautulli.git

    Run Tautulli.py to install the script files. Use Ctrl + c to exit and return to the command line.

    sudo python /opt/Tautulli/Tautulli.py

    Copy the config file and create a data directory.

    sudo cp /opt/Tautulli/config.ini /etc/tautulli.conf
    sudo mkdir -p /opt/TautulliData

    Create a user named tautulli and take ownership of the script files and directories.

    sudo adduser --system --no-create-home tautulli
    sudo chown tautulli:nogroup /etc/tautulli.conf
    sudo chown -R tautulli:nogroup /opt/TautulliData
    sudo chown -R tautulli:nogroup /opt/Tautulli

    Install the systemd startup script.

    sudo cp /opt/Tautulli/init-scripts/init.systemd /lib/systemd/system/tautulli.service
    sudo sed -i 's,/opt/Tautulli/config.ini,/etc/tautulli.conf' /lib/systemd/system/tautulli.service
    sudo sed -i 's,--datadir /opt/Tautulli,--datadir /opt/TautulliData' /lib/systemd/system/tautulli.service

    Enable boot time autostart.

    sudo systemctl daemon-reload
    sudo systemctl enable tautulli

    Start the service.

    sudo systemctl start tautulli

    You can now access Tautulli from your browser to complete the welcome wizard.

    http://plexpi.local:8181/welcome

  8. For good measure, now is a good time to reboot and make sure that everything is working as intended.

    sudo reboot
  9. Install and configure the ufw package to firewall your Plex Media Server.

    Install Uncomplicated Firewall.

    sudo apt install ufw

    Create a profile for Plex Media Server.

    sudo nano /etc/ufw/applications.d/plexmediaserver

    Paste the following text into the file and save it.

    [plexmediaserver]
    title=Plex Media Server
    description=Plex allows you to aggregate all your personal media and access it anywhere you go.
    ports=3005,8324,32400,32469/tcp|1900,5353,32410,32412,32413,32414/udp
    

    Create a profile for Tautulli.

    sudo nano /etc/ufw/applications.d/tautulli

    Paste the following text into the file and save it.

    [Tautulli]
    title=Tautulli
    description=A Python based monitoring and tracking tool for Plex Media Server.
    ports=8181/tcp
    

    Enable the firewall.

    sudo ufw default deny incoming
    sudo ufw default allow outgoing
    sudo ufw allow OpenSSH
    sudo ufw allow CIFS
    sudo ufw allow plexmediaserver
    sudo ufw allow Tautulli
    sudo ufw enable
    $ sudo ufw status
    Status: active
    
    To                         Action      From
    --                         ------      ----
    OpenSSH                    ALLOW       Anywhere                  
    plexmediaserver            ALLOW       Anywhere                  
    Tautulli                   ALLOW       Anywhere                  
    CIFS                       ALLOW       Anywhere                  
    OpenSSH (v6)               ALLOW       Anywhere (v6)             
    plexmediaserver (v6)       ALLOW       Anywhere (v6)             
    Tautulli (v6)              ALLOW       Anywhere (v6)             
    CIFS (v6)                  ALLOW       Anywhere (v6)
@Nilpo
Copy link
Author

Nilpo commented Mar 23, 2018

@Nilpo
Copy link
Author

Nilpo commented Apr 16, 2018

You can also grab the interface in one shot.

export IP=`hostname -I`
export GW=`netstat -nr | grep 'UG[ \t]' | awk '{print $2}'`
export NS=`netstat -nr | grep 'UG[ \t]' | awk '{print $2}'`
export IF=`ip route | awk 'END{print $3}'`
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
echo -e "interface `echo $IF`" | sudo tee -a /etc/dhcpcd.conf
echo -e "static ip_address=`echo $IP`/24" | sudo tee -a /etc/dhcpcd.conf
echo -e "static routers=`echo $GW`" | sudo tee -a /etc/dhcpcd.conf
echo -e "static domain_name_servers=`echo $NS`" | sudo tee -a /etc/dhcpcd.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment