WordPress High Availability

No comments

OLGPS

Introduction:

High Availability within WordPress is a complex issue. Unlike AEM and SiteCore, WordPress does not have an authoring node in its default design. So the challenge is whenever an author goes to /wp-admin and authors content, how do we make sure all nodes are in sync ?

In the past and in some current environments, we leverage GlusterFS to keep both front-end servers in sync or use rsync scripts but that proved to be an issue. GlusterFS service became a point of failure due to the amount of resources it takes and if one server goes down under a high load, that load is transferred to the other node due to those syncing scripts.
Basically, both nodes are not truly independent of each other whether you use rsync or glusterFS, which is not true high availability.


The Solution:

Introduce a Third server into the mix that will act as an authoring node. How that works is that whenever an author enters wp-admin into their browser, the traffic is routed to that one Authoring node. We can leverage a WAF for that or an Application Load balancer.

Now that Authoring node has a cron-job running that syncs the WordPress directories on its own server to each of the front-end node independently, it also syncs to our DR Author which in turn syncs to its front-end servers.

This results in the two front-end servers being totally independent of each other.

What you will need:

  • You will need a third server that will act as a Authoring node. This server will be running a cronjob with a small script that syncs its own wordpress directory to the other 2 front-end servers.
  • Make sure you exchange keys between the Authoring Node and the two front-end servers.
  • Create the script. A sample script is pasted below.
  • Permissions are a tricky issue. The user running the script must be in the apache group to be able to make changes. Meaning that the group will need write access to the directories, so maybe a 775.

 

And that is all. I hope I was able to help you address your wordpress high availability issues. Feel free to comment if you have any questions.

 

Sample rsync script:

if [ “$tmpstatus” != “0” ] ; then
echo “[$(hostname)] Author Rsync Job — $(date)\n\nRsync job failed for the following:\n\n/var/www/mysite/wp-content\n.\nStatus: $tmpstatus\n”
printf “$(date)\n\nRsync job failed for the following:\n\n/var/www/mysite/wp-content\n.\n\n This Jobs runs every 2 minutes. If more emails come in, Check /var/log/rsync.log ” | \
mailx -s “[$(hostname)] URGENT:Sync failed for Node 1” \
email@gmail.com\

else
echo “[$(hostname)] Node 1 Rsync Job successful. Status: $tmpstatus”

fi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s