Setting Up the Virtual Private Servers for High Availability
In previous articles we have discussed the concept of high availability and what it entails. Over the coming weeks we’ll be looking at how you can configure Virtual Private Servers on the VPS.net cloud to provide you with a highly available web server solution. To do this we’ll look into configuring a pair of Linux VPSs and setting them up so that they can act as a highly available pair.
Step 1: Configure Your VPS Pair
Obviously the first step is to configure your VPSs. For this to work well, both VPSs will need to be of equal specifications and will need to be in the same cloud. Select a number of nodes for each VPS suitable for the load you expect the server to come under. This can be changed at a later date if the performance requirements of your website change. When choosing the starting image for the VPSs, either go with a base CentOS, Debian or Ubuntu server image, or either of those operating systems with the LAMP stack pre-installed. Once you have your VPSs built, you can look at performing your usual security procedures to harden and secure them, such as firewall configuration, SSH settings, and user accounts. For the rest of these tutorials we’ll be assuming you have your two VPSs set up with a LAMP stack installed, and will be logged in as a user with sudo access.
Step 2: Adding a Public IP Address
With the VPSs configured, next you will need an additional public IP address. This can be purchased through your VPS.net dashboard. There is also a knowledgebase article here that helps explain the process. Note that the IP is assigned to your account and not to a particular server, so we can move this IP between the servers as needed.
The way that this system will work is that each VPS’s public IP will only be used for managing the individual VPS. The additional public IP will be the IP address used for people trying to access your website, so you will need to configure your DNS for the website’s domain to point to that IP address. With that done we can move the IP address from one VPS to the other in order for the traffic to the website to be directed to the correct server.
Fortunately, automatically moving the IP address is quite simple using a tool called heartbeat. This program can monitor the status of specific servers in a group and then perform actions based on the disappearance/reappearance of the servers. This allows the IP address to be moved between servers without requiring any input on your behalf at the time.
Step 3: MySQL Duplication and File Replication
There are a few other issues that need to be taken care of too. The first of these is ensuring that the MySQL database that your website is using is duplicated between both of the servers. To resolve this we will be configuring MySQL on both servers to use a Master-Master configuration. This kind of setup can be risky if writes are happening to both masters at the same time, but our setup design will ensure that writes only happen to one database at a time, with changes then replicated back to the other database. The other issue we will face is ensuring that any files uploaded to the primary server are replicated over to the other server, because at any time either server can be the master, we need to be able to replicate in either direction. To solve this problem we’ll be using the Unison file synchronization software.
In the next part, we’ll start to construct this by configuring the Master-Master replication between the MySQL servers on each VPS.