Two-Server HA MySQL Cluster
So…. I like MySQL… Most FOSS projects I play with use it as their backend, so other people must like it as well. Because of this, I soon found I was running a DB server on almost every server/workstation I have. This was kind of annoying so I decided to build a dedicated MySQL server to which everything else could connect.
It was nice for a while, it was easy to manage and easy to monitor, but it doesn’t take a college drop out to understand that this configuration creates a single point of failure for a handful of applications.
Simple solution? Build a minimal MySQL cluster across two machines.
Even more simple? Build a minimal MySQL cluster in two virtual machines and place them on two different physical servers.
Now, I know what you may be saying, “But Mike, I’m not a dba! I’m not awesome with sql, MySQL, or Unix! Can I do this?”
To be perfectly honest, yes. It really isn’t all that hard and I will try my best to explain it simply, yet effectively.
The first step is to build a pair of servers you can use. I would suggest CentOS, and I can even help you out!
Check out my post on how to build a small CentOS installation.
When you have two servers, you may now start to look at the four components of a MySQL cluster:
- Server
- Cluster Managemen
- Cluster Storage Engine
- Proxy/Load Balancer
The first three parts are included in the MySQL Cluster package.
For this installation, we are going to use the ‘Linux (non RPM packages)’ download for the sake of simplicity. This should be fine for testing, or an an x86 machine. Ideally, you’d be using a 64bit machine for production, in which case you’d either use distro specific packages or compile from source.
From here on in: Every step described should be done on both servers unless specified otherwise.
Download the MySQL cluster package to a directory on your server.
Create the mysql group and user
# groupadd mysql
# useradd -g mysql mysql
Unpack it to /usr/local/
# tar -C /usr/local/ -xzf ./mysql-cluster-gpl-6.3.17-linux-i686-glibc23.tar.gz
Link your installation to /usr/local/mysql
# ln -s /usr/local/mysql-cluster-gpl-6.3.17-linux-i686-glibc23 /usr/local/mysql
Create system databases
# cd /usr/local/mysql
# ./scripts/mysql_install_db –user=mysql
Set directory permissions
# cd /usr/local/mysql
# chown -R root .
# chown -R mysql ./data
# chgrp mysql .
Install sysconfig rc script
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig –add mysqld
That is enough for today, you basically have a working MySQL server at this point. Next we will create the configuration files and start up the NDB storage engine and cluster mangement nodes.
…to be continued!