How To Build The Ultimate PLEX VPS Using Google Drive

It’s no surprise that so many people use PLEX these days.  The one challenge I have had thus far is providing a decent server that my friends can access without the limitations of my upstream bandwidth.  While PLEX Pass gets you a Plex Cloud server, to be honest, the implementation has been less that stellar since its release.  I set out to build something myself on a Virtual Private Server (VPS) and decided to document the build after a couple tries that landed me on something that worked well.  I decided to use Google Drive for my media library storage so once it all was uploaded initially and setup to sync twice daily from my master library on premises this build process could start.  You really can’t start the VPS build until you get your media uploaded which is the longest part to wait for.  I’ve done this so many times and had so many notes it was high time to consolidate them.

Ultimate Plex VPS Step 1:  Choosing a Provider (UPDATED)

This is probably the worst part.  There is literally hundreds of options out there.  The problem is cost for what you get.  I personally tried about 5-6 different ones and the real problem is finding one at a decent price that also includes Unlimited Bandwidth.  The reason for this is when you connect to Google Drive your data will use double bandwidth for the pull from Google Drive and the push to the client, passing through the PLEX Server as a proxy.

NOTE:  As of July I have since dropped the original provider.  While they stated unmetered bandwidth they constantly traffic shaped my systems down to 15Mbit/s with no explanation.  They also would not bump it back up.  I have moved over to try another provider to see how they go called Direct Space who has KVM SSD options.  Their speed is not quite the same and they say it’s a fair share access port.  They also have a vCloud option that does not list the fair share use on the port I may test out as well.

Ultimate Plex VPS Step 2:  Choosing a Linux Distro

I have these both on Ubuntu and CentOS.  What I found I also liked about all providers is that they offer an ISO library that not only included both, but specifically CentOS 7 Minimal which I am personally a fan of to keep the installation as light as possible.  You can elect to spin up and install from the ISO yourself and that is what I did and the rest of this post will cover the steps to configure the PLEX VPS under CentOS 7 Minimal.

Configuring Plex VPS Step 1:  Install Dependencies

Based on the fact this is a minimal installation there is some packages you will want/need for some basic toolsets.  I will get into some of these later, but here is the list I compiled as I went through the installs.

#Install Core Packages
yum install -y python nano wget sudo zip git unzip fuse net-tools firewalld

#Install EPEL Repo
yum install epel-release -y

#Install ncdu from EPEL (Useful for finding large files)
yum -y install ncdu

#Install PIP from EPEL
yum -y install python-pip
pip install --upgrade pip

#Install Speedtest-CLI
pip install speedtest-cli

#Install OpenSSL for PlexPY
pip install pyopenssl

Next you will want to add a new user for plex and add it to the wheel group

adduser plex
usermod -aG wheel plex

Configuring Plex VPS Step 2:  Configure FirewallD

Most VPS installs I have found vary in what is allowed in the internal firewall.  CentOS now uses firewalld instead of iptables so here is the restricted settings I found worked well.  Port 8181 will be used later for the Tautulli application (Old PlexPY)

systemctl enable firewalld
systemctl start firewalld
firewall-cmd --zone=public --add-port=32400/tcp --permanent
firewall-cmd --zone=public --add-port=8181/tcp --permanent
firewall-cmd --zone=public --add-icmp-block=echo-reply --permanent
firewall-cmd --zone=public --add-icmp-block={echo-request,echo-reply,timestamp-reply,timestamp-request} --permanent
firewall-cmd --reload

Configuring Plex VPS Step 3:  Install and Configure PlexDrive

There are a number of ways to connect to Google Drive using fuse, but the easiest I have found is what id called PlexDrive.  It’s pretty well documented and easy to install.  For the purposes of this installation I will give you the required steps.  Before you can do this you do need to enable the Google Drive API.  In the computer with the web browser, create an OAuth2 application and credentials.  The following steps are what I did, based on my notes:

  1. Sign in to your Google account and create a project: https://console.cloud.google.com/
  2. Click “API Manager” then “Library” in the left-hand pane (will take you to https://console.cloud.google.com/apis/library). Click on “Drive API”, then “ENABLE API”.
  3. Click “Credentials” in the left hand pane, then click on the button “Create Credentials” (OAuth client ID)
    • Choose “Other”
    • Choose any product name, e.g “PlexDrive”
    • Click “Create”. You will get a Client ID, a Client Secret
cd ~
wget https://github.com/dweidenfeld/plexdrive/releases/download/5.0.0/plexdrive-linux-amd64
mv plexdrive-linux-amd64 plexdrive
mv plexdrive /usr/bin/
cd /usr/bin/
sudo chown root:root /usr/bin/plexdrive
sudo chmod 755 /usr/bin/plexdrive
mkdir /mnt/gdrive

#Run manually to setup connections to follow the prompts
plexdrive mount -c /root/.plexdrive -o allow_other /mnt/gdrive

#Once the credentials are saved you can CTL ^C out

Next you will want to create this as a service

nano /lib/systemd/system/plexdrive.service

#Edit the file and insert the following
[Unit]
Description=Plexdrive
AssertPathIsDirectory=/mnt/gdrive
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/plexdrive -o allow_other -v 2 --max-chunks=50 mount /mnt/gdrive/
ExecStop=/bin/fusermount -uz /mnt/gdrive
Restart=on-abort

[Install]
WantedBy=default.target

#Enable and start service
systemctl daemon-reload
systemctl start plexdrive.service
systemctl enable plexdrive.service

Configuring Plex VPS Step 4:  Install and Configure PLEX

There is an interesting note that the PLEX installation does add a repo for updates, but you do need to install manually first then update the repo the installer creates so you can easily update later without the manual hassle.  This is pretty straight forward, but the trick is connecting to it to set it up.

#Install from RPM then update repo
su plex
cd ~
wget [download-link]
sudo yum install plexmediaserver-xxx-Latest.rpm

#Edit the Repo
nano /etc/yum.repos.d/plex.repo

#change line 4 from enabled=0 to enabled=1. It should look like this:
[PlexRepo]
name=PlexRepo
baseurl=https://downloads.plex.tv/repo/rpm/$basearch/
enabled=1
gpgkey=https://downloads.plex.tv/plex-keys/PlexSign.key
gpgcheck=1

In order to access the server to add it to your account you will need to create a secure connection for access via localhost.  Since this is a remote server you need to create the connection.  I use a mac and found that the application Secure Pipes is the easiest way.  Below is the configuration you will need to access http://localhost:32400/web

Once you complete the setup to your existing account you can disconnect Secure Pipes and finish the setup from the regular PLEX.tv page and the new server should be connected.  You will need to enable remote access of course but if you setup the firewall settings above it should connect just fine.  At this point depending on the time it takes for PlexDrive to cache your Google Drive, you can then add libraries and access them in by browsing to /mnt/gdrive/[DIRECTORY].  At that point the PLEX server will start building the library.  You can also migrate library meta data using the process already documented by PLEX which take a little more work.

Configuring Plex VPS Step 5:  Install and Configure Tautulli (PlexPY)

This is an extra step but well worth it if you want to be able to see more detail on the streams happening and also see some analytics data and even get alerts via notifications.  I use this a lot to troubleshoot or get notified about upgrades as well.  You can find out more from the Tautulli Page here.  The setup is pretty easy though.

#Add User for Service
adduser --system --no-create-home tautulli

#Install From Git
cd /opt
git clone https://github.com/Tautulli/Tautulli.git
chown tautulli:nobody -R /opt/Tautulli
cp /opt/Tautulli/init-scripts/init.systemd /lib/systemd/system/tautulli.service

#Edit the GROUP to "nobody"  Other docs say nogroup which is not in CentOS
nano /lib/systemd/system/tautulli.service

#######
[Unit]
Description=Tautulli - Stats for Plex Media Server usage

[Service]
ExecStart=/opt/Tautulli/Tautulli.py --quiet --daemon --nolaunch --config /opt/Tautulli/config.ini --datadir /opt/Tautulli
GuessMainPID=no
Type=forking
User=tautulli
Group=nobody

[Install]
WantedBy=multi-user.target
#######

systemctl daemon-reload
systemctl enable tautulli.service
systemctl start tautulli.service

You can now point a browser to http://SERVERIP:8181 and you will see the setup screen for the application and you can go from there with the well documented information.

About Chris Colotti

Chris is active on the VMUG and event speaking circuit and is available for many events if you want to reach out and ask. Previously to this he spent close to a decade working for VMware as a Principal Architect. Previous to his nine plus years at VMware, Chris was a System Administrator that evolved his career into a data center architect. Chris spends a lot of time mentoring co-workers and friends on the benefits of personal growth and professional development. Chris is also amongst the first VMware Certified Design Experts (VCDX#37), and author of multiple white papers. In his spare time he helps his wife Julie run her promotional products as the accountant, book keeper, and IT Support. Chris also believes in both a healthy body and healthy mind, and has become heavily involved with fitness as a Diamond Team Beachbody Coach using P90X and other Beachbody Programs. Although Technology is his day job, Chris is passionate about fitness after losing 60 pounds himself in the last few years.

24 comments

  1. This is a great walkthrough, but I’m curious when you did this and if you’ve made any changes or have any follow-up since then?

  2. Thank you for this recent post. I may need to do this as I have family all over the US that connect and it kills my home network when I start getting 2-4 people on at a time.

    I have 3.5tb of data at the moment and Google jumps from 2tb@$20 to 10TB@$100. Do you know of a cheaper solution to run more like 4 or 5TB for storage?

  3. Great tutorial. I am having an issue starting Tautulli. This happens on Centos and Ubuntu. Any ideas?

    Traceback (most recent call last):
    File “./Tautulli.py”, line 35, in
    import plexpy
    File “/opt/Tautulli/plexpy/__init__.py”, line 37, in
    import activity_handler
    File “/opt/Tautulli/plexpy/activity_handler.py”, line 24, in
    import activity_processor
    File “/opt/Tautulli/plexpy/activity_processor.py”, line 21, in
    import database
    File “/opt/Tautulli/plexpy/database.py”, line 24, in
    import logger
    File “/opt/Tautulli/plexpy/logger.py”, line 30, in
    import helpers
    File “/opt/Tautulli/plexpy/helpers.py”, line 48, in
    from plexpy.api2 import API2
    File “/opt/Tautulli/plexpy/api2.py”, line 39, in
    import notification_handler
    File “/opt/Tautulli/plexpy/notification_handler.py”, line 43, in
    from newsletter_handler import notify as notify_newsletter
    File “/opt/Tautulli/plexpy/newsletter_handler.py”, line 29, in
    NEWSLETTER_SCHED = BackgroundScheduler()
    File “/opt/Tautulli/lib/apscheduler/schedulers/base.py”, line 82, in __init__
    self.configure(gconfig, **options)
    File “/opt/Tautulli/lib/apscheduler/schedulers/base.py”, line 121, in configure
    self._configure(config)
    File “/opt/Tautulli/lib/apscheduler/schedulers/background.py”, line 29, in _configure
    super(BackgroundScheduler, self)._configure(config)
    File “/opt/Tautulli/lib/apscheduler/schedulers/base.py”, line 689, in _configure
    self.timezone = astimezone(config.pop(‘timezone’, None)) or get_localzone()
    File “/opt/Tautulli/lib/tzlocal/unix.py”, line 108, in get_localzone
    _cache_tz = _get_localzone()
    File “/opt/Tautulli/lib/tzlocal/unix.py”, line 61, in _get_localzone
    return pytz.timezone(etctz.replace(‘ ‘, ‘_’))
    File “/opt/Tautulli/lib/pytz/__init__.py”, line 181, in timezone
    raise UnknownTimeZoneError(zone)
    pytz.exceptions.UnknownTimeZoneError: ”

    • I am not running it on the Linux box anymore I deployed it using Docker. There may be some people on the GitHub for it or there is support for Tautulli on Discord as well that is very helpful.

  4. Chris, why do you suggest KVM vs OpenVZ if ou’re using Linux as your OS?
    From my understanding, OpenVZ uses less resources and is generally cheaper for the same hardware than KVM access. I know it is limited to only using the base OS – i.e. Linux – but that is your OS of choice anyway.

    I do recall that root access is (typically? always?) not provided through OpenVZ, so that may be an issue, and I’m not sure if you are limited in which Linux distro you can use, which could be an issue depending on your familiarity.

    • OpenVZ usually requires the host to enable FUSE for the drive mounts to work KVM is a little easier as it does not require their intervention. I have found pure KVM seems to run a little better than OpenVZ as well. It’s more of a preference not a hard and fast rule. Both work OpenVZ just has extra steps specifically for FUSE.

  5. I’m trying this on their “cloud” (vCloud) server as you mentioned above. Using the VC4G version – 80GB SSD, 4GB RAM, 8 core proc, unmetered transfer.
    I initially started using the PlexGuide.com on Ubuntu. Got through a working system with TV and movies pulling from GDrive. However – it was unbearably slow, whether direct streaming or transcoding. The same files from the same GDrive location played almost instantly using Plex’s native cloud server.

    So, I am trying your setup to perhaps provide an apples to apples comparison. I’ll let you know how it performs.
    I note that you don’t list the specs on the service you’re using (unless I missed it) so I’m not sure if the service level I am using is comparable.

  6. I think I am using the $10/month ones for now.

  7. thanks for the guide, as a plex cloud user im looking into having a vps so i can keep using plex.

    I have a GSuite account, would you say this guide is a step by step to setup my plex vps, using direct space?

    not familiar with linux os that is why I ask

    Thanks

  8. Hi Chris,

    Thank for the details tutorials. I followed along the way. Almost get to the end. When I want to add the plexdrive server to startup, it said as below:

    systemctl enable plexdrive.service
    Failed to execute operation: Invalid argument

    These are the scripted I copied from your post:

    [Unit]
    Description=Plexdrive
    AssertPathIsDirectory=/mnt/gdrive
    After=network-online.target

    [Service]
    Type=simple
    ExecStart=/usr/bin/plexdrive -o allow_other -v 2 –max-chunks=50 mount /mnt/gdr$
    ExecStop=/bin/fusermount -uz /mnt/gdrive
    Restart=on-abort

    [Install]
    WantedBy=default.targe

    Am I missing something?

    • Not that I can think of unless the copy/paste inserted some other text. I just ran all this again myself a few weeks back to rebuild.

      • This like is wrong, it truncated the line. This:
        ExecStart=/usr/bin/plexdrive -o allow_other -v 2 –max-chunks=50 mount /mnt/gdr$

        Should be this:
        ExecStart=/usr/bin/plexdrive -o allow_other -v 2 –max-chunks=50 mount /mnt/gdrive

        And this:
        WantedBy=default.targe
        Should be this:
        WantedBy=default.target

  9. where would i get my “authorization code”

  10. I’ve followed this down to a T, But its creating the gdrive folder in the mnt folder

    I run plexdrive mount -c /root/.plexdrive -o allow_other /mnt/gdrive enter my details in and everything seems to work fine as it accepts it, But it doesnt show my files up in mnt/gdrive folder?

    • Depending on the size of your Google Drive it can take some time for it to index and b PlexDrive. I’ve noticed the folders don’t show up until the initial index process is complete.

  11. Awesome guide! Thank you, everything works great. One side note, I cloned my VM for safe keeping then did an in place upgrade of centos7 to 8 just to see if it would work. The upgrade went fine, neither service would start until I rebooted. Once rebooted, Plex would start but plexdrive would not. I had to modify the plexdrive.service execstart to:

    ExecStart=/bin/sh -c “/usr/123/bin/plexdrive…”
    User=123
    (Sub 123 for your login username)

    Without making this change I kept getting an exec error 203. Otherwise it’s working great on centos8 so far. If your doing the install from scratch on centos8, this guide should work with the above change, just substitute “yum” with “dnf”

    If your creating a VM on your own host, don’t forget to install your guest tools:
    Vmware: yum/dnf install open-vm-tools
    HyperV: yum/dnf install hyperv-daemons

    Thanks again. Not only was this a fun project but also a great way to start learning Linux in a fun way.
    Ed

  12. How to do the securepipes part on windows? thanks this guide is awesome

Leave a Reply

Your email address will not be published. Required fields are marked *