DNS Load Balancing for Highly Available Enterprise WordPress Cluster
Scalability, high availability, and performance are fundamental to the success of a commercial product deployment. And if the workload includes multiple entry points for requests, it is important to properly set up smooth load balancing in order to achieve the required uptime and speed. One of the solutions in this case is to use a DNS service with origin servers health checks. It eliminates a single point of failure and the entire load balancing algorithm continues to operate even if any endpoints crash, since it automatically routes requests to available ones only.
In this article, we will describe how to set up a Cloudflare DNS load balancer to distribute the workload for enterprise-level WordPress cluster with two or more entry points using a health checks mechanism. The same approach can be used for geo-distributed clusters that will be covered in our upcoming publications.
WordPress Cluster Custom Domain Setup
Let’s consider that you have a WordPress application with clusterization of all stack layers. It means that the cluster has two LiteSpeed Web ADC (load balancers) which serve as the entry points (origins or endpoints).
Note: If you are going to scale load balancers horizontally, register each newly provisioned public IP address under the same custom domain name as one more A record.
Issue SSL Certificate
Bind the custom domain to the environment and issue SSL certificate with help of Let’s Encrypt Free SSL Add-On for the entry points.
Replace platform-generated domain name with custom one and click Apply.
In order to replace an old domain name with a custom one in all URLs on your website use the add-on WordPress Site Address (URL).
Press Site URL button and provide URL with custom domain name.
At this point your site is served via DNS Round-Robin algorithm. If you try to resolve the domain name, every time you’ll get all addresses you have registered for it, even the unreachable ones.
DNS Load Balancing Setup
Let’s go further and set up a DNS Load Balancer entity for the website with endpoint health checks.
In the Cloudflare dashboard open the Traffic>Load Balancing>Create Load balancer. Then type the custom domain you have created the A records for. Make sure that traffic proxying is disabled to go through Cloudflare, since we are going to balance DNS requests only.
The next step is to create origin pools. Since there are two A records were created, we will create two pools specifying one load balancer in each as origin. You may follow Cloudflare documentation or just specify the Pool Name, Origin Name as arbitrary values. Use the public IP address of one of the load balancers as Origin Address and since the load balancers are equal, set up the Weight as 1. Scroll down and specify the Notification E-mail where you prefer to obtain the health check notifications. Press the Save button. For example:
Do the same with different names for the second pool using the IP address of the second load balancer as origin. After that specify a monitor to carry out the health checks for each origin.
So, click on Attach monitor>+Create a Monitor.
Health Check Monitor
New monitor requires to specify parameters to be used for the health checks. Some of them are dependent on your subscription and cost extra. For example the health check interval is 60 seconds by default. In case you want to make it shorter and set up to 15 seconds you will be charged an additional 15 USD.
So, you may follow Cloudflare monitor tutorial or as for our example just specify monitor parameters as follows:
Right after you save the changes it is necessary to attach the monitor to the origin pool.
Once the monitor is attached the health check starts working and displays the state of origin in real time. Attach the same monitor to the second origin.
Health Check Notification
The monitoring is complemented with an email notification which you can specify creating the pool or attaching monitor to that pool.
Make sure that both entry points are healthy and go further.
The next step is Traffic Steering. This option allows to define the load balancing algorithm based on current subscription. For example for the base 5 USD subscription plan you may use only:
- standard failover algorithm marked as Off, which routes traffic from unhealthy pool to the next healthy one
- Random: Route to a healthy pool at random
In case you are subscribed for enterprise level subscriptions the other options will be available:
- Dynamic steering — uses health check results to identify the fastest pool for a given Cloudflare Region or point of presence
- Geo steering — routes traffic to the pools based on the client’s region or point of presence. Users specify the pools to which the load balancer should direct traffic for a given geographical region or point of presence. Several pools can be specified to the same region, and the balancer will use them in failover order
Within the current example we use the standard failover because we don’t use a geo-distributed cluster and both origins are in the same region, so just leave it unchanged. Finally press Save and Deploy.
DNS Load Balancing Testing
Definitely it is necessary to make sure that DNS load balancing works properly depending on endpoints state. To do this, issue the commands as follows on one of load balancer nodes via Web SSH(see picture below):
1. Check which endpoint IP address is returned by resolving the custom domain:
dig wordpress-enterprise.jele.website +short
2. Stop load balancer service in one of the containers to imitate server failure:
sudo jem service stop
3. Wait 60 seconds to make sure the health check interval is expired and try to resolve the custom domain name once again. And it goes without saying you have to check the application workability in a web browser.
As you can see the IP address of the healthy endpoint is returned only. And respectively you may observe the cluster origins state in the Cloudflare dashboard.
A corresponding email will be sent to your mailbox with notification regarding the connection failure to one of the entry points.
Don’t forget to get the origin back into operation and check the health state after one minute.
The respective email will notify you with happy email that cluster failed origin is reachable and healthy.
DNS Load Balancing Tuning
If necessary you may change the additional load balancer features such as:
Origin Servers — number of origin servers
Faster Checks — health check interval
Check From — number of Regions the health checks can be performed from
Traffic Steering — enables/disables traffic routing algorithms
Congratulations! Now your website is maintained via DNS load balancer on Cloudflare.
Register at one of Jelastic cloud hosting providers and follow our tutorials to get highly available enterprise level WordPress hosting with smart load balancing distribution at DNS level.