Quantcast
Viewing all articles
Browse latest Browse all 151235

[Guide] Plex Media Server with Intel NUC and Ubuntu 16.04 LTS

I recently switched my Plex Media Server from Nvidia Shield Pro 2017 to a dedicated Intel NUC. My media contents are stored on a Synology DiskStation. The reason why I switched was that I had huge troubles to setup a stable Plex Media Server on the Shield. The main problem here is that Plex users are enforced to use the SMB/CIFS protocol for file sharing. In early 2017 the Shield randomly ignored folders on the NAS (there are a lot of forum posts about this topic, for example this one). This problem was solved in mid 2017 but still another very annoying issue remained. My mounted SMB/CIFS drives kind of crashed on the shield randomly with no reason. The only solution to fix this was to reboot the Shield, un-mounting and re-mounting did not help. Recently I had this issue 10 times on a single day, so I decided to kick this device out of my house.

I got positive feedback for my setup from friends, so I decided to share this guide maybe it helps anyone else. Feedback, tips and suggestions are pretty much appreciated! Image may be NSFW.
Clik here to view.
:smile:

My work is based on that guide from 2014 but changes some things and adds some more features as for example RAM transcoding. Even if there are that many steps it only took me 30-60 minutes to setup the NUC, so don't worry^^ I wanted this guide to be complete and step by step understandable Image may be NSFW.
Clik here to view.
;)



HARDWARE

  • Intel NUC (BOXNUC7I5BNK, i5-7260U 2,20 GHz, Link)
  • 2 x 8GB DDR4 RAM (CT2K8G4SFD8213, Link)
  • 250GB M.2 PCIe NVMe SSD (Samsung 960 EVO MZ-V6E250BW, Link)



STEP 1: Assemble NUC

  • Insert RAM
  • Insert M.2 SSD
  • Update BIOS with latest from Intel's website



STEP 2: Prepare Ubuntu installation

  • Download Ubuntu 16.04 64bit server version as .img file! from releases.ubuntu.com
  • Prepare your USB drive with that image
  • There's a nice quick guide from OpenELEC that shows how you can do that
  • Don't use unetbootin for creating a bootable USB drive as this could lead to some problems during the installation!


As the OpenELEC guys removed the guide I'll give you an example for macOS:

  • Open Terminal and navigate to your download folder: cd ~/Downloads
  • Print a list of devices: diskutil list
  • This will result in something like this:
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *8.0 GB     disk1
   1:                 DOS_FAT_32 UNTITLED                8.0 GB     disk1s1
  • Find your USB drive and remember the name (e.g. /dev/disk3). In the following steps replace "x" with your disk number
  • Unmount the disk: diskutil unmountDisk /dev/diskx
  • Next we need to zero out the partition map, macOS has an issue if you don't do this: sudo dd if=/dev/zero of=/dev/rdiskx bs=1024 count=1
  • Write the image to the disk: sudo dd if=ubuntu-16.04.3-server-amd64.img of=/dev/rdiskx bs=4m
  • Ensure the changes are synced: sync



STEP 3: Install Ubuntu

  • I used the following partitions:

    • #1: 536MB, ESP, bootable (size was suggested by Ubuntu)
    • #2: 64GB, swap (much bigger than usual because of RAM transcoding)
    • #3: 185,5GB, ext4
  • During software selection select "standard system utilities" and "OpenSSH server"

  • Remove USB drive and reboot your NUC
  • Assign your NUC a static IP address in your router's DHCP configuration



STEP 4: Remote connect to your NUC

  • All following steps can be done directly on the NUC as well, but from that point on I will only use SSH
  • Login from a client
    • ssh <username>@192.168.0.100



STEP 5: Main configuration

  • As I had issues with Ubuntu 16.04 and IPv6 I enforce apt to use IPv4

    • echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4
  • Update Ubuntu system

    • sudo apt-get dist-upgrade
  • Add plex repository as source

    • echo deb https://downloads.plex.tv/repo/deb/ public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
    • curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
    • sudo apt-get update
  • Install Plex Media Server dependencies

    • sudo apt-get install avahi-daemon avahi-utils
  • Install Plex Media Server

    • sudo apt-get install plexmediaserver
    • During installation you will be asked if you want to override the plex repository source with the one from the package. Here you can select "yes".
  • Re-enable plex repository as source

    • nano /etc/apt/sources.list.d/plexmediaserver.list
    • Uncomment the last line deb https://... by removing the #



STEP 6: SSH configuration

  • If you don't connect to your NUC via SSH you can skip this step
  • I setup the NUC to only allow SSH access with authorized public keys
  • On you client machine close the SSH connection to the NUC and run ssh-copy-id <username>@192.168.0.100. This will copy your public key to the NUC
  • Login again on the NUC using SSH. There shouldn't be any password request
  • Change SSH configuration: sudo nano /etc/ssh/sshd_config
PubkeyAuthentication yes
RSAAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys (uncomment this line)
PasswordAuthentication no
Port xxxx (I also use a not-default port for SSH)
  • Restart SSH

    • sudo systemctl restart ssh
  • If you changed the SSH port you need a different login call from now on

    • ssh <username>@192.168.0.100 -p <port>



STEP 7: Enable autologin

  • I read somewhere that Plex Media Server sometimes runs into problems, if there's no user logged in on the machine. In order to prevent that I setup autologin
  • sudo mkdir /etc/systemd/system/getty@tty1.service.d
  • sudo nano /etc/systemd/system/getty@tty1.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin <username> tty1




STEP 8: Setup NFS and Autofs

  • I use NFS in order to connect to my NAS
  • Install dependencies

    • sudo apt-get install autofs nfs-common
  • Create mount directory (in my case I replaced nas with the hostname of my NAS in all the following steps, for example in /nas or auto.nas)

    • sudo mkdir /nas
  • Configure Autofs

    • sudo nano /etc/auto.master
    • Append the following at the end of the file:
/nas      /etc/auto.nas
  • Create Autofs configuration file for your NAS
    • sudo cp /etc/auto.misc /etc/auto.nas
    • Append all your mount points at the end of the file, for example (replace the IP with the IP of your NAS):
movies    -fstype=nfs4    192.168.0.99:/volume1/Movies
music     -fstype=nfs4    192.168.0.99:/volume1/Music
  • Restart Autofs

    • sudo systemctl restart autofs
  • All you mount points are now available at /nas/...

  • Autofs will automatically unmount all mount points if there is no access within 5 minutes and remount if you try to access the mount point. You can keep ghost references to the mount points by adding --ghost in auto.master at the end of the appended line



STEP 9: Configure Plex Media Server

  • Open http://192.168.0.100:32400/web in your browser and configure your server



STEP 10: Setup RAM transcoding

  • In order to prevent heavy SSD usage (and because of better performance) I setup RAM transcoding for my server. As my RAM is limited to 16GB I setup a RAM disk, so if I reach the limit of my RAM the system will make use of the swap
  • Create transcoding directory

    • sudo mkdir /tmp/transcoding
  • Setup the system to mount the RAM disk on every boot

    • sudo nano /etc/fstab
    • Append the following line:
tmpfs    /tmp    tmpfs    defaults,noatime,nosuid,nodev,noexec,size=64G,mode=1777    0    0
  • Grant writing permissions for the transcoding directory

    • sudo chown -R <username>:<username> /tmp/transcoding
  • Use /tmp/transcoding in Plex Media Server > Settings > Server > Transcoder > Temporary directory



STEP 11: Schedule reboot

  • I schedule a weekly reboot as all machines need a reboot occasionally
  • sudo crontab -e
  • Append at the end:
# Reboot at 04:00 every sunday
0 4 * * 0 /sbin/reboot



STEP 12: Configure firewall

  • Please check out the Plex reference for which ports you need to allow
  • sudo ufw reset
  • sudo ufw allow <port>/tcp comment 'ssh'
  • sudo ufw allow 32400/tcp comment 'plex media server'
  • sudo ufw allow 32410/udp comment 'plex gdm network discovery'
  • sudo ufw allow 32412/udp comment 'plex gdm network discovery'
  • sudo ufw allow 32413/udp comment 'plex gdm network discovery'
  • sudo ufw allow 32414/udp comment 'plex gdm network discovery'
  • sudo ufw allow 3005/tcp comment 'plex companion'
  • sudo ufw allow 111 comment 'nfs'
  • sudo ufw allow 2049 comment 'nfs'
  • sudo ufw enable



STEP 13: Setup monitoring

  • It took me a while to find an "all in one" monitoring solution for CPU, memory, swap, load, network, disk I/O, temperatures and top processes
  • I ended up with Glances
  • Installation:

    • sudo apt-get install python-pip
    • pip install --upgrade pip
    • pip install glances
  • I also created a shortcut for glances in my user directory:

    • mkdir ~/bin
    • echo 'glances --percpu --process-short-name --disable-bold' | tee ~/bin/gtop
    • chmod +x ~/bin/gtop
  • Now I just have to run gtop



STEP 14: Configure swap usage

  • Swappiness defaults to 60 so I adjusted it a little bit
    • sudo sysctl vm.swappiness=85



CONCLUSION

I did a couple of performance tests and my server did very well. When the Shield crashed (really. it hung up and rebooted) trying to play a 60GB 4K HDR movie my new server just plays it without any delay. CPU load during that was at round about 25-35% (transcoding HVEC to H264). As the CPU supports hardware transcoding for H264 transcoding that also runs totally smooth (CPU load below 10%).
Regarding loudness, the NUC isn't really noisy, I have it in my living room you cannot really hear it.

As I said in the beginning I would be very happy for feedback, tips or suggestions! Image may be NSFW.
Clik here to view.
:smiley:

Cheers,
grogster


Viewing all articles
Browse latest Browse all 151235

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>