Jonathan on August 31st, 2008

I recently needed to configure mysql failover on some of our test machines. Thanks to Sheeri’s helpful blog entry which provides a simple failover lua script, configuring failover is a simple matter. However, the machines are running centos-5.2 and centos doesn’t provide an rpm for mysql-proxy. This blog entry describes how to build your own.

The latest mysql-proxy (0.6.1) is apparently not backward-compatible with 0.6.0 and earlier. It incorrectly handles the case when one of the backend machines is down. Instead of just marking it as down, it errors out completely. This makes it rather difficult to use it for failover scenarios. People have complained about this for a while. Bugs 34793 and 35295 track the problem,  but the fix has not yet been made available in a pubicly downloadable release. Due to this problem, I recommend using mysql-proxy-0.6.0 instead.

mysql-proxy-0.6.0 has several package-level dependencies. It requires libevent-1.4.x or newer. If you want to use lua, then lua is of course required. Since centos ships with an old version of libevent and does not ship with lua at all, we will need to build those rpms as well.

There are several steps needed to build mysql-proxy:

  • prepare rpmbuild
  • build libevent-1.4.7
  • build lua-5.1.4
  • build mysql-proxy-0.6.0

Prepare rpmbuild

If you haven’t built your own rpms before, you need to specify the directory in which rpmbuild should do its work.

$ mkdir -p ~/rpmbuild/BUILD ~/rpmbuild/RPMS  ~/rpmbuild/RPMS/i386
$ mkdir -p ~/rpmbuild/SOURCES ~/rpmbuild/SPECS ~/rpmbuild/SRPMS
$ echo "%_topdir $HOME/rpmbuild" > ~/.rpmmacros

Install the rpm-build rpm so that you can run /usr/bin/rpmbuild.

$ sudo yum install rpm-build

Build libevent-1.4.7

The main site is http://monkey.org/~provos/libevent/

Unfortunately, libevent does not ship with an RPM spec file.This is rather irritating since it means users have to either build their own rpm spec file or find someone else who has written one. I found an old spec file on the dag.wieers.com site but it was out of date and did not work with libevent-1.4.7. It would be much better if the spec file were checked into the code repository with the code so that they could be versioned together.

I took the spec file from dag.wieers and then had to spend some time to update the RPM spec file so that it would work. It’s now available here for your convenience but I’m not planning on being an official maintainer for it.

First get the libevent source and unzip it.

$ wget http://monkey.org/~provos/libevent-1.4.7-stable.tar.gz
$ tar xzf libevent-1.4.7-stable.tar.gz
$ mv libevent-1.4.7-stable libevent-1.4.7

Copy the spec file:

$ cp /tmp/libevent.spec /tmp/libevent-1.4.7/

Tar up the libevent directory with the new spec file and build the RPMs:

$ tar zcf /tmp/libevent-1.4.7.tar.gz libevent-1.4.7
$ rpmbuild -ta /tmp/libevent-1.4.7.tar.gz

Install the libevent rpm:

$ sudo rpm -ivh /home/jcheyer/rpmbuild/RPMS/x86_64/libevent-1.4.7-1.x86_64.rpm

Build lua-5.1.4

The main site is http://www.lua.org/

Like with libevent, lua also does not ship with an RPM spec file. People have asked for it to be included, and there were the inevitable disagreements about whether it should go in or not. So once again I had to waste time updating the spec file on my own. I found a spec file on the dag.wieers.com site which of course was out of date. I’ve updated the spec file here.

First get the lua source tarball and unzip it:

$ wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
$ tar zxf lua-5.1.4.tar.gz
$ mv lua-5.1.4.tar.gz lua-5.1.4.tar.gz.0

Copy the RPM spec file:

$ cp ~/lua.spec /tmp/lua-5.1.4/

Tar up the lua directory with the new spec file.

$ tar zcf lua-5.1.4.tar.gz lua-5.1.4/

Build the RPMs. The lua package requires ncurses-devel and readline-devel (only while building the RPM).

$ sudo yum install ncurses-devel readline-devel
$ rpmbuild -ta /tmp/lua-5.1.4.tar.gz
$ sudo rpm -e --allmatches ncurses-devel readline-devel

Install the lua rpm.

$ sudo rpm -ivh ~/rpmbuild/RPMS/x86_64/lua-5.1.4-1.x86_64.rpm

Build mysql-proxy-0.6.0

Do not install mysql-proxy-0.6.1. As I mentioned earlier, it is broken and the failover lua scripts do not work with it. The main site and other useful info are available if you want to read up on mysql-proxy.

First download the file.

$ wget http://dev.mysql.com/get/Downloads/MySQL-Proxy/mysql-proxy-0.6.0.tar.gz/from/http://mysql.osuosl.org/

The mysql-proxy package requires mysql-devel (only while building the RPM).

$ sudo yum install mysql-devel

The mysql-proxy package also requires the libevent-devel RPM that you just built. It’s
only needed while building the mysql-proxy RPM.

$ sudo rpm -ivh ~/rpmbuild/RPMS/x86_64/libevent-devel-1.4.7-1.x86_64.rpm

The good news is that mysql-proxy ships with an up-to-date RPM spec file, so you don’t need to do
anything extra. Just build the rpm.

$ rpmbuild -ta /tmp/mysql-proxy-0.6.0.tar.gz
$ sudo rpm -e --allmatches libevent-devel mysql-devel

Now you can install mysql-proxy:

$ sudo rpm -ivh ~/rpmbuild/RPMS/x86_64/mysql-proxy-0.6.0-0.x86_64.rpm

Enjoy your new version of mysql-proxy compiled for centos-5.2!

Tags: , , , ,