Installing Galera MySQL clustering on Ubuntu 10
Posted: January 16th, 2012 | Author: Laurie | Filed under: Uncategorized | No Comments »Galera is a patch and a library for MySQL that work together at the engine level to provide simple, multi-master replication between MySQL instances. It promises to be easier to set up than ordinary MySQL replication, and allow you to write to more than one machine, a feature currently unavailable from vanilla MySQL.
The documentation is laughably sparse, but I found a helpful post on the mailing list which gave me the clues I needed to get it up and running on a trio of local virtual machines. Once I’ve run some more tests I’ll give a more thorough review of the tech, but the smoke-test confirms: yes, you can get replication between 3 masters that survives the loss of any one of the machines, and even supports auto-incrementing indexes! If this tech turns out to be stable, it’s pretty much the holy grail of MySQL.
Installing Galera
You need to install both the mySQL deb with the wsrep patch, and the galera library itself:
wget http://launchpad.net/codership-mysql/5.1/5.1.59-22.2/+download/mysql-server-wsrep-5.1.59-22.2-i386.deb
wget http://launchpad.net/galera/1.x/22.1.1/+download/galera-22.1.1-i386.deb
Install the packages. dpkg will complain that things are broken, so get apt-get to install the dependencies for you:
dpkg -i galera-22.1.1-i386.deb mysql-server-wsrep-5.1.59-22.2-i386.deb
apt-get -f install
Now you need to temporarily start the server so you can configure it (you’ve missed the usual mySQL setup wizard):
/usr/bin/mysqld_safe &
Run the secure installation setup to configure your root password, etc.:
/usr/bin/mysql_secure_installation
Now, set MySQL to bind to the external adapter instead of localhost (127.0.0.1), for example:
nano /etc/mysql/my.cnf
bind: 10.0.1.109
Now that’s done, kill your temporary server. I’m dumb, so I did it this messy way:
ps axf | grep mysqld
kill -9 any pids from above
Now start mySQL properly:
service mysql restart
Now you need to configure galera itself. Galera config is under mySQL’s:
nano /etc/mysql/conf.d/wsrep.cnf
First, tell it where you’ve installed the galera lib:
wsrep_provider=/usr/lib/galera/libgalera_smm.so
Now give it the cluster address. For the very first node, that address is just:
wsrep_cluster_address="gcomm://"
For any subsequent nodes, set it to point at the first node:
wsrep_cluster_address="gcomm://10.0.1.109"
At the moment it’s not clear to me why this works this way, since if the first node falls over the other two nodes seem to remain capable of syncing with each other, i.e. there is no “master” node. I’ll understand better once I’ve done more reading, I guess.
You will need to provide a replication username/password between the nodes:
wsrep_sst_auth=username:password
And restart mysql again.
Finally, connect to MySQL and grant permissions to your replication user (NB: you need to run these two commands as a single line — galera seems to do weird things with connections to clients).
set wsrep_on = OFF; grant all on *.* to 'username'@'%' identified by 'password';
Done! Repeat these steps for as many nodes as you want, changing only the gcomm address, and you’ll get that many replicated nodes. Amazing!
Fun facts
I’m just starting to get to grips with the features of Galera, but so far the cool things I’ve noticed are:
- New nodes can sync from empty, i.e. no need to take a mysqldump snapshot beforehand
- Database and table creates (and drops!) are respected and synced to all boxes
- Tables with auto_increment indexes create non-conflicting IDs (although they are no longer strictly sequential, so you will get gaps in your numerical sequence).
- Any of the nodes can drop out temporarily and will catch back up
- Restarting MySQL seems to fix most syncing problems
I’ll write more about pros and cons once I’ve had a chance to play with Galera some more.