Ensuring the scalability, high availability, and performance of a commercial product deployment is crucial, especially when the system handles multiple request entry points. Effective load balancing is essential for maintaining desired uptime and responsiveness. One approach is to use a DNS provider that includes health checks for the origin servers, eliminating potential single points of failure.
In this guide, we will demonstrate how to set up a Cloudflare DNS load balancer, incorporating health checks, to evenly distribute the workload across an enterprise-level WordPress cluster with multiple entry points. This approach can also be adapted for geo-distributed clusters, which we will cover in a future article.
Setting Up a WordPress Cluster with a Custom Domain
Imagine you have a WordPress application with a clustered stack. This setup includes two LiteSpeed Web ADC (load balancers) as the primary entry points (origins or endpoints).
Initially, you should create an A record at your domain registrar for each endpoint, pointing to a custom domain like wordpress-enterprise.jele.website.
Note: If you plan to scale your load balancers horizontally, add an additional A record for each new public IP address to the same custom domain.
Acquiring an SSL Certificate
- Link the custom domain to your environment and issue SSL certificates for the entry points using the Let’s Encrypt Free SSL Add-On.
- Replace the platform-generated domain name with your custom one and click Apply.
- Utilize the WordPress Site Address add-on to update all URLs on your website with the new custom domain.
Press the Site URL button and input your custom domain name.
Your site now operates using the DNS Round-Robin method. When resolving the domain name, all registered addresses, including unreachable ones, will be returned.
Implementing DNS Load Balancing
To enhance this setup, let’s create a DNS Load Balancer object in Cloudflare with health checks for your website’s endpoints.
Access the Traffic Load Balancing section in the Cloudflare dashboard and select Create Load Balancing. Enter the custom domain for which you have set up A records. Ensure traffic proxying is disabled, as we are only balancing DNS requests, not routing traffic through Cloudflare.
Setting Up Origin Pools
The next step involves setting up origin pools. Given that there are two A records, we will create two pools, each linked to one of the load balancers as its origin. You can either adhere to Cloudflare’s guidelines or choose arbitrary names for the Pool Name and Origin Name. Assign the Origin Address as the public IP of one of the load balancers, and set the Weight to one, indicating equal distribution since the load balancers are identical. Scroll to the Notification Email field to input an email address where you wish to receive notifications about the health checks. Finalize this setup by clicking the Save button. Here’s an example:
- For the second pool, use a distinct name and the IP address of the other load balancer as the origin. Then, assign a monitor for each origin to conduct health checks.
- Proceed by selecting Attach monitor +Create a Monitor.
Configuring the Health Check Monitor
You need to define the settings for the health checks on the newly created monitor. Note that some settings may incur additional charges depending on your subscription plan. By default, health checks are conducted every 60 seconds. Reducing this interval to 15 seconds will result in an additional charge of 15 USD.
For setting up, you can follow Cloudflare’s monitor tutorial or configure the monitor parameters as shown below:
After saving these settings, it’s essential to immediately link the monitor to the origin pool.
Once the monitor is linked, it starts functioning, displaying the real-time status of the origin. Connect the second origin to the same monitor as the first one.
Setting Up Health Check Notifications
Health check monitoring is complemented by email notifications, which you can set up during the pool creation or when attaching the monitor to the pool.
Ensure both entry points are functioning correctly before proceeding.
Implementing Traffic Steering
The next step is to configure traffic steering. This feature allows you to choose a load balancing algorithm based on your subscription level. For instance, with the basic $5 subscription, you can use:
- A standard failover method, where traffic is redirected from an unhealthy pool to the next operational one.
- Random selection, where traffic is randomly directed to a healthy pool.
For enterprise-level subscriptions, additional options are available:
- Dynamic steering, which identifies the fastest pool for a specific Cloudflare region or point of presence based on health check results.
- Geo steering, which routes traffic to pools based on the client’s geographic location. A region can have multiple pools, and the balancer will use them in a failover sequence.
Since we are not using a geo-distributed cluster and both origins are in the same region, we will opt for the standard failover method in this example. After setting this up, click Save and Deploy.
Testing DNS Load Balancing
It’s crucial to verify that DNS load balancing is functioning correctly in relation to the status of the endpoints. To do this, use the following commands on one of the load balancer nodes via Web SSH:
Resolve the custom domain to check which endpoint IP address is returned:
dig wordpress-enterprise.jele.website +short
Simulate a server failure by stopping the load balancer service in one of the containers:
sudo jem service stop
Wait 60 seconds for the health check interval to pass, then try resolving the custom domain name again. It’s also wise to test the application’s functionality in a web browser.
As you can see, only the IP address of the operational endpoint is returned. The Cloudflare dashboard will display the status of the cluster origins.
An email notification about the connection failure to one of the entry points will be sent to your inbox.
Don’t forget to reactivate the origin and check the health status after a minute.
You will receive a confirmation email indicating that the previously failed origin is now reachable and operational.
Fine-Tuning Your DNS Load Balancing
You have the flexibility to adjust additional features of your load balancer, such as:
- Origin Servers: Adjust the number of origin servers in use.
- Faster Checks: Modify the interval for health checks.
- Check From: Choose the number of regions from which health checks are conducted.
- Traffic Steering: Enable or disable specific traffic routing algorithms.
Well done on setting up your site! Your website is now efficiently managed by Cloudflare’s DNS load balancing.
Experience this service for free and without any commitment. Click here to try WordPress cluster cloud hosting on the Oxacloud platform. Benefit from cutting-edge performance with next-gen LiteSpeed application servers, a load balancer supporting the rapid HTTP/3 protocol, robust MariaDB Galera clusters, integrated CDN, and Let’s Encrypt SSL.
Should you have any questions or encounter any issues during your trial, our support team is readily available to assist you.