Skip to content

Commit 50853ca

Browse files
author
Patrick M
committed
add plex post
1 parent fca8284 commit 50853ca

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
layout: post
3+
title: 'Setting up Plex'
4+
date: 2022-12-18 23:00:00 -0500
5+
category: 'Service Setup'
6+
tags: ['plex']
7+
---
8+
9+
After setting up a new server, I wanted to migrate my plex install to the more powerful machine. This will be a jump from an i3-2100 to an i5-12500T. A substantial leap in performance.
10+
11+
<!--more-->
12+
13+
## Provisioning
14+
15+
Previously I was running plex as a container in unraid. Then as a container on another VM. Both were somewhat problematic for me because plex is a hog and takes up all the resources of the VM during transcoding. So I wanted to try and install it in a LXC environment instead. To start, I provitioned the environment with 2 CPU cores, 3 GB of RAM, 16 GB of disk space, and a static IP. While this seemed like enough at first, I doubled the CPU coure count to 4 as it was running steadily at 98% utilization with only 2. I also had to convert the environment to a privledged container to get CIFS automount to work correctly.
16+
17+
Final provisioned LXC environment is as follows:
18+
19+
- 4 CPU Cores
20+
- 3 GB RAM
21+
- 16 GB Disk
22+
- Static IP
23+
- Privledged Container
24+
25+
## Mounting Media from Network Share
26+
27+
Mounting my media share from a storage device was easy enough, once I realized I had to make the container privledged. I configured `fstab` to automount the share when the environment started, and used a credential file stored in /root for security.
28+
29+
> Privledged Container must be set to true to mount a network share
30+
{: .prompt-tip }
31+
32+
Lets start with the credential file. It's a simple file that needs to live somewhere fstab can access. I used /root because `fstab` will run as root so I know it will have access.
33+
34+
```bash
35+
sudo nano /root/.cifscreds
36+
```
37+
38+
```text
39+
username=<username>
40+
password=<password>
41+
```
42+
43+
You'll need to provide the username and password for the network share. Once the credentials file is created, you can create the mount point folder and add the command to `fstab`.
44+
45+
```bash
46+
sudo mkdir /mnt/media
47+
sudo nano /etc/fstab
48+
```
49+
50+
```
51+
//192.168.1.10/media /mnt/media cifs uid=0,credentials=/root/.cifscreds,iocharset=utf8,vers=3.0,noperm 0 0
52+
```
53+
54+
Once you've added the configuration save the file and run
55+
56+
```bash
57+
sudo mount -a
58+
```
59+
60+
You should now see your media mounted under /mnt/media. Restart the environment to make sure it is remounter after a reboot.
61+
62+
## Creating /transcode
63+
64+
For transcoding, there are three approaches, each with pros and cons. The default transcoding location is `/tmp`. This is the slowest of the recommended methods, and can wear out SSDs quickly with the number of writes required. For this reason alone I would not use it. The next recommended method is `/dev/shm`. This is a system mounted tmpfs directory that offers a place for shared memory between processes. It's maximum size if typically configured to be half the system memory. This can problematic though because transcoding can quickly use up lots of memory if allowed, and can starve out other processes running. This is bad for a shared host running multiple services especially. For this reason I decided to use tmpfs to create my own share.
65+
66+
While this approach is technically the most complicated to configure, it's still relatively easy and is what I would recommend. Start by creating the mount point like before and adding another line to `fstab`
67+
68+
```bash
69+
sudo mkdir /mnt/transcode
70+
sudo nano /etc/fstab
71+
```
72+
73+
```
74+
tmpfs /mnt/transcode tmpfs rw,size=2G 0 0
75+
```
76+
77+
I set the size to 2 GB, but this can be configured to whatever you like. During heavy transcoding, or when Plex is handling multiple streams, this will certainly fill up. Plex will recycle memory as needed based on memory pressure and available space.
78+
79+
When you've added the configuration, don't forget to run mount again.
80+
81+
```bash
82+
sudo mount -a
83+
```
84+
85+
## Installing Plex
86+
87+
Now that the environment is ready, lets install plex. This can be done by downloading the `deb` file directly from plex or by adding [downloads.plex.tv](https://downloads.plex.tv) as a package source for `apt`.
88+
89+
```bash
90+
echo "deb https://downloads.plex.tv/repo/deb public main" | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
91+
```
92+
93+
Then add the package signatures so packaged can be verified.
94+
95+
```bash
96+
curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
97+
```
98+
99+
Now installing plex is as easy as running the following command
100+
101+
```bash
102+
sudo apt update && sudo apt install plexmediaserver
103+
```
104+
105+
Once Plex finishes installing, you can access it from the static IP configured at port 42300. Remember to update your transcode location to `/mnt/transcode` in <u>Settings</u> > <u>Transcoder</u> > <u>Transcoder temporary directory</u>. You should also see your media in `/mnt/media` when you add libraries.
106+
107+
## Migrating Configuration
108+
109+
As I mentioned in the beginning, I am migrating from an existing plex environment, and thus I want to move my cache to the new environment rather than recreate it. The benefit of this is that I won't lose all of my custom metadata, nor collections and other settings. To make this move, you will need to find your Library folders and copy the content to the new environment. I used rsync to do this but, you can use winscp or any other method you like. I found my Library files in the config folder I mounted for the container I was using. Installing Plex in the LXC node, I found it in `/var/lib/plexmediaserver/`
110+
111+
I would recommend stopping Plex as a service before you migrate the files.
112+
113+
```bash
114+
sudo systemctl stop plexmediaserver
115+
```
116+
117+
Then you should be able to copy the files and restart the service.
118+
119+
```bash
120+
sudo systemctl start plexmediaserver && systemctl status plexmediaserver
121+
```

0 commit comments

Comments
 (0)