LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

How to Setup a Highly Available Wordpress Site From Scratch, Part 1

How to Setup a Highly Available WordPress Site From Scratch, Part 1

In this tutorial series, we are setting up a highly available WordPress web site from scratch. 

Part 1 – Introduction, Considerations, and Architecture
Part 2 – Setting Up the VPSes
Part 3 – Setting Up MariaDB Multi-Master Replication
Part 4 – File Replication and Setting Up DRBD
Part 5 – Setting Up OCFS2
Part 6 – Round-Robin DNS, Let’s Encrypt, & Conclusion

Goals

  • Complete protection against a VPS or web server failure, so that if a node goes down, the web site will continue to be fully functional.
  • Full operations available on both nodes, not just a read-only copy or a cache but the entire site so authors can post, users can make updates, etc. 
  • Setup with https via Let’s Encrypt with the usual certbot self-renewing certificate.

High Availability Considerations

To achieve our goal, we’ll need to answer the following questions:

  • What if a VPS goes down, either fully or partially (for example, the VPS is up but its webserver is down)?
  • If we have multiple VPSes serving the same WordPress site, how do we keep them in sync?  We have to consider both the database and the content such as media uploaded, etc.
  • How rigorous does our replication need to be?  Is it acceptable if things get out of sync by a few minutes or do we want things always in sync?
  • If a node fails, how does the client (i.e., any random Internet user’s web browser) know which node to point to?

High Availability Architecture

We’re going to use the following setup:

Two Debian 10 VPSes, each with nginx and php-fpm to serve WordPress.  Nothing here is Debian-specific but to avoid making the tutorial twice as long, we’re only covering one distro.

I’ll be using two VPSes in Linode’s Fremont, CA dataceter.  There’s nothing special about the choice of Linode – these techniques should work for any VPSes.  We’re locating both VPSes in the same DC to make synchronization as quick as possible.  But this architecture will work for geographically separated VPSes (to protect against failure of a datacenter).  Because private IPs are not available from all providers, we are only going to use public IPs.  However, if you have private IPs available from your provider, you should use these for replication to potentially reduce bandwidth costs.

MariaDB’s native multi-master replication.  MariaDB’s Galera option is another good choice, though it’s meant for a minimum of three nodes.  You can use garbd to use Galera on two nodes if you want to go that route.

DRBD + OCFS2 to replicate a volume bi-directionally between the nodes.  There are other options we’ll explore including a quick-and-dirty rsync if your non-database updates are few or if you have a single-author WordPress site.  There are many replication options and we’ll talk about why some popular options don’t fully solve the problem.

Round-robin DNS for the client (a web browser).  RRDNS is a DNS feature where you say “for this DNS entry, hand out these responses and rotate among them”.  So the first time someone looks up the site, they’ll get node 1’s address, and the next time they’ll get node 2, etc.  In ages past, browsers would get one address and stick to it until DNS TTL expired, but most modern browsers are smart enough that if they get two IPs for a web site and one doesn’t answer, they’ll try the other.

Let’s Encrypt for https.  We’ll also solve the issue of how certbot can update when RRDNS can return either node’s address.

Here’s a diagram of the architecture:

Before You Begin

We’re using DRBD for synchronization between the nodes.  DRBD requires a dedicated partition, so if you’re setting up from KVM you should keep this in mind when setting up your VPS and installing the OS.  Alternatively, if your provider offers block storage, you can attach a new volume, which is what I’ve done here.

Next Part: Part 2 – Setting Up the VPSes

raindog308

5 Comments

  1. Arirang:

    What a good article. I’m most looking forward to Part 6.

    December 11, 2020 @ 7:51 am | Reply
  2. ernie88:

    Excellent read, can’t wait to see the following articles!

    December 12, 2020 @ 5:40 am | Reply
  3. This article is great. Can’t wait for the next part.

    December 14, 2020 @ 10:05 am | Reply
  4. Thank you for your information. It helps me to add a lot of new knowledge very well.

    June 1, 2022 @ 12:23 am | Reply

Leave a Reply

Some notes on commenting on LowEndBox:

  • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
  • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
  • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

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