Friday, January 15, 2021

Ultimate Plex Performance Setup Guide for NAS

I've finally pulled the trigger and purchased a Synology DS1520+ along with a pair of 10TB NAS hard drives. It was finally time to move away from an old laptop with a pair of 4tb external USB drives onto something a little more permanent. This was a bit complicated, because I was planning to use the pair of 4tb drives as well as the new 10tb drives with a total capacity of 18tb and single drive failure. Because I didn't have an extra 4tb lying around, it required the following:

  1. Initialize the pair of 10tb drives as a volume.
  2. Copy the contents of the 4tb USB drive onto the 10tb volume.
  3. Initialize the pair of 4tb drives as a volume (you cannot add smaller drives into a volume with existing larger drives)
  4. Copy the 4tb of content from the 10tb volume over to the 4tb volume.
  5. Remove the 10tb volume.
  6. Add the pair of 10tb drives to the 4tb volume. 

In the end, it took 5 days of copying (no joke), but I now have an 18tb storage volume that allows for a single drive failure without loosing any data, and without a single file of data loss.


Now onto the purpose of this post.... There are several things you can do to optimize your Plex media server to run at maximum capacity. I am making the assumption that you have at least a working knowledge of how to use DSM as well as Plex, so I'll be skipping some of the rudimentary steps and instead focus my time on the more complicated pieces. 

Please note, we'll be installing the entire Plex app on the SSD. If you already have Plex installed and configured, you can always just configure your transcoding and metadata library to run on the SSD instead.

Also note, we'll be running both the metadata AND transcoding on the SSD...  "But wait!!!", you might be shouting, "Won't transcoding destroy my SSD!?!". In the long run, yes, transcoding on an SSD will eventually kill the drive... But, it will take multiple years of constant transcoding for this to occur. Its a risk I'm willing to take. Also, we'll be backing up the contents of the SSD onto the primary RAID, so if/when it ever does die, we'll just purchase a new SSD and restore the drive like new.


Step 1 - Single drive SSD volume for Plex

Reading many a blog, everyone agrees, using an SSD for your Plex metadata is a key factor in getting the most from your Plex server. With this in mind, I added a 120GB SSD I had laying around into the fifth drive bay. This is one of several reasons I choose the DS1520+ instead of the DS920+... That plus the 8GB of ram and ability to expand to 15 disks instead of just 9.

Simply set up a single drive volume with the SSD. This can be done by opening your Storage Manager, followed by the Storage pool and click Create.


I chose "Basic" as the RAID time for maximum performance

Chose the correct drive and work through the rest of the prompts.


Next, Create the volume. On the Volume Tab, click create, choose custom, select an existing pool, which is your newly created SSD, the follow the prompts to finish.



Step 2 - Install Plex Media Server

If Plex is already installed & configured, skip to the end and I'll show you how to configure the transcoding & metadata settings to run on the SSD instead. If you don't mind recreating things, installing the entire plex app on the SSD is a much cleaner way to go.


Open the Package Center, but before we start, make sure you can choose which volume to install on. You can do this by clicking on the Settings button


Under General, Default Volume, Choose "Always ask me", and click the OK button. This way you can decide where to install Plex.


Next, click to install Plex Media Server. The first screen will be the option to Select a destination volume to install the package. Choose your SSD volume.



Finish the Plex install and that's it! Plex will automatically use the SSD for Metadata and Transcoding!

One last step, you may want to use the SSD for other rapid disk items, so go ahead and add a shared folder to the volume. In my case, I called it SSD. To do this, open the File Station, click Create -> Create New Shared Folder. Give it a name, select the SSD location, I unchecked Restrict access to administrators only and click next. I chose not to encrypt data, but I did choose the data integrity option. Finally, make set the appropriate read/write permissions.



This is now ready to go!


Step 2 - Set up auto-backups

Because this is a single disk volume, if/when it fails, you will loose everything on it. To accommodate for this single point of failure, simply setup an automated backup. This way if/when it fails, simply replace the drive and restore the backup, and you'll be back up and running!

For this task, I chose to use Snapshot Replication. To install, open your Package Center, find Snapshot Replication, and click install. Once finished, open it up.

Inside the Snapshot Replication app, Choose the Snapshops tab and use CTRL + Click to select both the Plex shared folder, as well as the SSD shared folder, then click the Settings button.


On the Schedule tab, uncheck "Keep the original" and Check "Enable snapshot schedule" instead. I set my snapshot to run daily at 3am.


Next under Retention, I choose to only retain the last 5 snapshots (5 days worth), and to delete old snapshots at 5am.


Finally, under Advanced, I chose to "Make snapshot visible".

Finally click OK to save the settings. You will now see the snapshots are scheduled! If your SSD ever fails, you'll be able to restore the backup!


Step 3 - Update Plex

While Synology does offer automatic updates, I can tell you from experience, They are quite a few versions behind! Thankfully Plex makes this incredibly easy! Start by visiting this page: https://www.plex.tv/media-server-downloads/#plex-media-server and choose Synology from the drop down menu, click Choose Package. I chose Intel 64-bit.



This will download a .spk file. Back to the Package Center, Click the "Manual Install" button, browse for the .spk file and click next. Follow the prompts and you will have the newest version of Plex installed!

In my case, the newest version of plex from the package center was 1.18.5... I was able to upgrade it to 1.21.1 with just a few clicks.


Bonus options:

Tanscoding driver fix

Thanks to NASCompares YouTube channel for this one. A full write-up can be found here. It turns out, the default driver is not able to take full advantage of the Intel Celeron J4125 processor! This is especially true with H265 video files. So, to improve transcoding, we will want to change the default driver to the i965 video driver.

Keep in mind, if you update to a newer version of the Plex Media Server, you may have to install the i965 video driver again.

First, install the Text Editor package from the Package Center.


Next, stop the Plex Media Center. You can do this via the Package Center, choose Plex and click the drop down next to open and click "Stop".


Open File Station. You will brows to Plex -> Library -> Application Support -> Plex Media Server. From there, you will click on the file Preferences.xml. This will open up in the Text Editor. Scroll right to the very end of the line, you will see the characters "/>"

You will want to add a space, followed by: VaapiDriver="i965"


Then click File -> Save


Now Return to the Package Center and click run on the Plex Media Center


That's it! Thanks Rob for doing the legwork on this one!

Pre-Transcoding

If you find that you are doing a lot of transcoding, and you have storage to spare, considering enabling offline transcoding. Essentially Plex with pre-transcode your videos so that when you want to stream, the plex will send the appropriate version without needing to engage your cpu.

To do this, simply click the ellipses for each video you would like to optimize and select "Optimize...". 


Move Plex Database to your SSD

If you already have plex setup and configured, but would still like to take advantage of the speed boost of an SSD, you can follow this guide. I could type that up, but honestly that guide has done a better job explaining it than I could have!


Move Temporary Transcoding to your SSD

If you already have plex setup and configured, but would still like to take advantage of the speed boost of an SSD, here is how it's done:

Open your File Station, Choose the SSD shared directory, and create a folder to store the temporary transcoding in. Then right click the folder and choose Properties. From there, you can copy the location which you will need for the next step.




Next, open your plex server, click settings, choose your server, click Transcoder under your server settings, then click the "Show Advanced" button. This will reveal the "Transcoder temporary directory" option. There you can paste in the directory of the newly created folder on your SSD. Click Save Changes, and you are all set!








Wednesday, September 14, 2016

How to install Laravel Spark on Centos 7

So I spent more hours than I care to admit, just trying to get Laravel Spark up and running on my brand new Centos server. I have to say, it was less than enjoyable.

To that end, I thought I'd type up a quick tutorial on how to make it happen.

The primary problem I've run into is all centered on the fact that Centos does not seem to do a great job of keeping their repos up to date. I'm finding more and more, if you are trying to support newer technologies, you are simply forced to add newer repositories, like webtatic, or simply compile things on your own. This is especially true when I decided to implement http2 support on my servers. In fact, I'm in the process of finishing a blog post on setting up Centos7 to support http2.


This script assumes you already have a working nginx/apache & php 5.6+ webserver up and running. I have tried to commented my script to explain what is going on. My intention, like many other things I do, is to write a script to automate the process if when I have to do it again.


You can find the script on my github page.


That should be it! Feel free to ask questions or leave comments if you have any suggestions. I am hoping to refine this script a bit more to accept user input and be a bit more automated.

Thursday, July 7, 2016

Creating an FTP server on AWS with Centos

So I needed a micro server that would host files for a VERY dump ftp server. The use case was simple. Protect our production server while opening up ftp access for one specific client to one specific set of files. On my production server, I'll setup an rsync with a cron job, and I'll be all set.

What I found, however was a configuration nightmare. OK, truly, it wasn't that bad, but my inexperience with setting up FTP servers really became a bottleneck. So for future reference, and for anyone attempting the same, here is the script I came up with, after much trial and error.

  1. Create your ec2 instance:
    1. In my case, I used "CentOS 7 (x86_64) - with Updates HVM" from the marketplace as it is my goto AMI. 
    2. I selected a t2.nano, as I know the traffic to this server will be minimal. 
    3. I chose the correct VPC and Subnet to ensure public accessability.
    4. I then chose a moderately sized magnetic volume as I know that the load will be minimal.
    5. For security groups, I have configured a security group for each use case. This allows me to easily add and remove security groups to each server as needed. Simply looking at the list of groups shows me what permissions have been added. I added my internal group, FTP for port 21 & 22, and FTP - passv for the port range that I selected in pasv mode (see step x below). Depending on your setup, you may also want to add port 22 to allow ssh access. That is built into my internal group.
    6. Next I added the appropriate keys and launched my server.
    7. Then, I added an elastic IP address so that I can easily swap instances if needed.
    8. Finally, I added a dns record pointing to the elastic ip.
  2. Configure your instance:
    1. SSH into your instance and give yourself root access: sudo su
    2. Update the server: yum -y update
    3. Install vsfptd: yum -y install vsftpd
    4. Configure vsftpd by editing vsftpd.conf, adding the following to the bottom of the config file, replacing the min/max ports with whatever range you would like, and the pasv_address to the elastic ip you assigned above:
      1. anonymous_enable=NO
        local_enable=YES
        chroot_local_user=YES
        pasv_enable=yes
        pasv_min_port=1224
        pasv_max_port=1248
        pasv_address=xxx.xxx.xxx.xxx
    5. Add an FTP user: useradd -d /home/ftpuser -s /sbin/nologin ftpuser
    6. Set the Password: passwd ftpuser.
    7. You could stop there, but you might get an error like this: "500 OOPS: vsftpd: refusing to run with writable root inside chroot ()" 
      1. To fix that, adjust the permissions of the directory: chmod a-w /home/ftpuser
      2. Then run: setsebool -P allow_ftpd_full_access 1


That should be it! In my case I also setup an rsync script in my production server's crontab to populate the files onto the ftp server.

Friday, March 18, 2016

Custom phone car mount

I was over at microcenter a couple weeks ago and picked up a generic phone mount for my truck. It mounts in the vent and has a nice ball joint for adjusting. Similar to this:


Perfect, I thought. Then I installed it and headed down the road...

One problem, while the vent may seem like an attractive mount point, what happens when you have a vent that pivots? With every turn your phone flings to the right or left. I was about to return it but then remembered I have a buddy with a 3d printer =D

30 minutes later, with the help of SketchUp, I designed this: (.stl file)


It's a simple block with two screw holes for mounting and a hole to receive the peg end of the ball joint. My buddy recommended separating the parts to reduce the amount of scaffolding needed to print the parts. A bit of acetone on the peg, insert that into the block, and the parts will naturally fuse together.

I will screw this into a useless pocket in my truck's dashboard and the phone mount will secure nicely.


Lastly, I will run a usb cable power supply, hard wired, out of a small hole in the bottom of that pocket, allowing for a convenient power supply for my device.

I'll update with pictures once the install is complete!

Wednesday, March 16, 2016

Postgresql upgrade issues - Checking for reg* system OID user data types

So I am prepping for an upgrade of postgres from version 9.2 to 9.4. Since this is a major version upgrade, I chose to use pg_upgrade to try and minimize downtime. My first attempt in one of our dev environments went fairly well, up until I actually launched the upgrade process.

My stopwatch was ready, my commands were ready, my server was ready!

Start the stopwatch...
#/etc/init.d/postgresql-9.2  stop#sudo -u postgres /usr/pgsql-9.4/bin/pg_upgrade --old-datadir=/var/lib/pgsql/9.2/data/ --new-datadir=/var/lib/pgsql/9.4/data/ --old-bindir=/usr/pgsql-9.2/bin/ --new-bindir=/usr/pgsql-9.4/bin/


HERE WE GO!

Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is a superuser                       ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for reg* system OID user data types                fatal

NOOOOOO!!!!




Quick.....
#/etc/init.d/postgresql-9.2 start

Thank goodness that was only dev... So what now?? Running cat of tables_using_reg.txt, showed me that there were several tables affected:

  public.pg_ts_dict.dict_init
  public.pg_ts_dict.dict_lexize
  public.pg_ts_parser.prs_start
  public.pg_ts_parser.prs_nexttoken
  public.pg_ts_parser.prs_end
  public.pg_ts_parser.prs_headline
  public.pg_ts_parser.prs_lextype

The good news is, it looks like these are remnants of the old pgsql 8.x days when tsearch2 was not part of the distribution.

My solution? Drop pg_ts_dict & pg_ts_parser. Once upgraded, I'll test everything, as long as there are not any issues, we are good to go. Worst case scenario, I can dump those two tables (5 rows total between them) and run an import post upgrade.

Monday, March 14, 2016

First go with AliExpress

So in search of some components for some arduino/rasp-pi hacking, I was getting frustrated with cost of some of the most basic components. I should not have to spend $10-15 on a simple Temperature & Humidity sensor! Sadly, that is one of the cheaper components.
Humidity and Temperature Sensor - RHT03


After some digging, I stumbled upon AliExpress!

www.aliexpress.com

They are basically the Amazon of China. Loads of great deals on about anything you can think of... but this is especially true of electronic components. That sensor alone, also known as a DHT22, is priced at a full 1/4 of the US based outlets (that's $2.50 if you don't want to do the math)!

And that's not all! They also have dozens of component kits on the seriously cheap, like this 37 sensor kit for just over $12! Or how about 600 misc. resistors for $2.60!
http://g03.a.alicdn.com/kf/HTB1DcfKLpXXXXa8XFXXq6xXFXXXN/37-IN-1-SENSOR-KITS-FOR-ARDUINO-HIGH-QUALITY-FREE-SHIPPING-Works-with-Official-for-Arduino.jpghttp://g02.a.alicdn.com/kf/HTB1z17WKFXXXXc8XXXXq6xXFXXXO/Free-Shipping-600-Pcs-30-Kinds-Each-Value-Metal-Film-Resistor-pack-1-4W-1-resistor.jpg

I feel like a kid in a penny candy store!!!

Here's the best part, most of these components come with free shipping!

So what's the catch? Can you have your cake and eat it too? Is this all a bit scam?

The great new is, like amazon, this site is made up of hundreds of sellers, each trying to make a living, and their reputation will make or break their AliExpress store. On top of this, AliExpress seems to have some great dispute tools. In fact, they even hold your payment from the seller until after you have indicated that you have received your order and are satisfied with it!

The downsides? It's all being shipped from China, so unless you want to pay boatloads on shipping, you are not going to enjoy the same second day delivery that Amazon Prime has spoiled us with! We'll see how long things end up taking, so far, 5 of my 7 orders have shipped within 2 days of ordering. They still have to travel over the ocean and through our post office. At these crazy low prices though, they are totally worth the extra wait!

What can I say??? Crazy cheap prices! Free shipping! Excited to make something with my 7 year old!

Paper making: Take 1

So yesterday, I took my first stab at making paper. It's part of a larger goal of making my own Journal. It wasn't perfect, but you've gotta start somewhere. Unfortunately, I did not take pictures of the process, only the results. When I run my second trial, I'll be sure to take pictures of the whole process to share.

My observations thus far are:
  • I need a better frame. 
  • My frame size needs to accommodate for trimming the edges.
  • I need to figure out a better way to regulate the paper thickness. 
  • I need a bucket that is sized closer to my frame.
  • I need to figure out how to whiten the paper, if I am going to continue to use non-white recycling.

I'll give some details about the process after the pictures. Without further ado:

Here is my paper. It's about the thickness and texture of construction paper. It was made primarily of recycled paper bags plus a few old homework pages that were headed to the trash.

Here is the frame I used. It worked ok, but I sized it according to the page size I wanted, not counting for edge trimming. Also, because you need the frame to "catch" the pulp, I need to modify the frame so that the pulp cannot seep between the screen and the frame, which made paper removal very difficult. For my next trial, I will add some furring strips to the top of the frame, screwing the two pieces of wood together. I may actually end up using the furring strip side for the paper making, as the shallow depth might help with paper removal as well.

 Here is the back side of the frame. You can see that I just stapled the screen material to the frame.


Now for the process:

Making the pulp, Part 1:
To make the pulp, you have to start by tearing  and soaking the paper. I did this first so that it would have time to become nice and saturated.
  1. I gathered some misc. paper from the recycle bin. I had some brown paper bags and some old homework. I knew that the paper bag would cause the end result to be brown, I figured for this stage, that didn't matter much.
  2. Put a kettle of water on to boil. This is optional, but I've read that it greatly speeds up the soaking process.
  3. Tear the paper into shreds. I got my kids to help with this part, they loved it! Breaking the paper up like this will help it to saturate faster.
  4. Place the paper into a large boiling-water-safe bowl and pour the boiling water on top and give it a quick stir.
  5. We'll come back to the soaking paper later.

Build the frame:
  1. I cut a 1x2 we had lying around with 90deg. angles to the desired size. One mistake here was, I should have added a margin for error so that I had room for trimming the edges when the paper finished drying. I think an extra 1/2" in width and length would be plenty for trimming. Also, I used a skill saw instead of taking the time to break out our chop saw. It's hard (at least for me) to make accurate cuts, let alone accurate diagonal cuts using hand power tools. I knew this was a trial, so I just went with it.
  2. Next, I screwed the four sides at the corners. I used a 2x4 block to help keep things square during the screwing process. 
  3. I then measured diagonally for square and had to make a couple of minor adjustments by slightly loosening and tightening specific screws.
  4. I salvaged the screen material from an old window screen we had lying behind our shed. It was not perfect, but was good enough for the learning process. Like with the chop saw, when I get ready to build a set of production frames, I'll run to the big box and buy some new window screen.
  5. I attached the screen to one side of the frame with far more staples than I probably needed.
  6. Then stretched the screen around the front of the frame and attached the opposite side. I should have rinsed the screen first, as this turned out to be a dirty set of steps.
  7. I stretched the next side and secured it, then I folded the corners to keep everything nice an neat.
  8. Next, I stretched and attached the last side. 
  9. Lastly, I washed the whole frame, hoping the dirt and grim would not attach itself to my soon to be paper.
 Making the pulp, Part 2:
  1. Take the now saturated pulp and drop it into your favorite blender/food processor. I kept the batches to less than half our blender at a time.
  2. Add enough water to be sure the paper will blend.  I don't think there is any danger to using too much water in this step, though this was my first attempt, so....
  3. Blend away, until you have a nice smooth sludge.
  4. Pour the sludge into another bowl for safe keeping.
  5. Rinse & repeat, until you have blended all of your pulp.
Making the paper:
  1. Get a water proof box of some sort, I used a plastic bin we had in our garage, and fill it with a few inches of water. 
  2. Add a bit of liquid starch. This is not corn starch. You can find it in the cleaning section of the store, near the ironing stuff. This will "final" or "finish" the paper, allowing the ink to stick to the page without it bleeding and soaking through. I did not have any on hand, so I skipped it this time. I'll get some for my next attempt.
  3. Add your pulp. For my first attempt, I made the mistake of just adding it all. I think a measured amount will be key for making a consistent page thickness.
  4. Give your water/pulp a gentle stir to thin out the pulp and watch for big clumps. You'll want to remove any you find.
  5. Submerge your frame in the concoction and give the water a few seconds to settle. You'll see the pulp even out on the surface of the water. 
  6. Slowly lift the screen. Since mine is made of wood, it was buoyant and naturally floated. I found it helped if I left the screen *just* submerged, maybe an 1/8th of an inch to allow the pulp to settle on the screen.
  7. Slowly lift the screen out of the water and let the water drain out.
  8. Lay a towl on your counter and set the frame on top.
  9. Carefully lay another towel on top and start gently pressing the towel onto the paper.  Once you have the initial amount of water pressed out, it seems safe to start pressing harder. The goal here is to draw out as much of the water as possible. I've seen some people recommend using a sponge on top of the towel to draw out even more water. I'm thinking I'll get one of those squeegee towels that are super absorbent and wring out well.
  10. When you feel like you have removed as much of the moisture as you can, it's time to carefully pull the paper off the screen. One blog I read said to flip the frame and the paper should genitally fall off. This was not the case for me. Either my screen was too course, or the pulp that bleed between the screen and the frame prevent this all together. Either way, I had to get in there with a butter knife to peel up a corner, then I slowly pulled the paper off the screen. While the paper was somewhat fragile, it held together much better than I feared.
  11. Place the freshly peeled page onto a towel or parchment paper to dry a bit longer. From here, some people suggested hang-drying. I was impatient, so I heated the oven to 170 degrees, placed my pages inside and turned the oven off. This worked pretty well, though I will probably skip that with my next trail.
  12. Finally, when your paper is thoroughly and completely dry, trim your paper! My wife had a crafting paper cutter with a blade that follows a track. This made for nice clean edges all the way around.

What are my takeaways. I still have more to figure out. I need to fix the process of making and removing the fresh paper. Then I can focus on getting a consistent thickness. Finally, I'll start playing with pulp materials to work on the texture and color. I'm happy with using recycled paper, but I may experiment with plant based pulp as well.