Installing Bind9 with DLZ and MySQL backend on Ubuntu Jaunty (9.04) and Lucid (10.04)

Submitted by Hannes Schmidt on Thu, 12/24/2009 - 15:48.

Update 06/27/2010: This is still necessary for Lucid (10.04 LTS) and these instructions still work with minor adjustments.

This forum post got me started but I got stuck in various places and thought I'd summarize what worked for me. I'm not going to explain much but if you're going to work with Bind and DLZ you probably know what you're dealing with. I also won't go into configuring DLZ because that depends on your particular DB schema and there is sufficient documentation on the DLZ website.

We need MySQL of course:

root@foo:~# apt-get install mysql-server

Make a directory to hold the source package for bind9,

root@foo:~# mkdir -p /usr/local/src/bind9

and change into it:

root@foo:~# cd /usr/local/src/bind9

Bison and fakeroot are needed. Not sure if these are a build-time only dependencies.

root@foo:/usr/local/src/bind9# apt-get install fakeroot bison

My sources.list was lacking a required deb-src entry:

root@foo:/usr/local/src/bind9# vim /etc/apt/sources.list

Make sure the following deb-src line is present and active:

deb-src http://us.archive.ubuntu.com/ubuntu/ jaunty main

On Lucid, replace jaunty with lucid, of course.

If you modified sources.list, update the package index.

root@foo:/usr/local/src/bind9# apt-get update

Get the build tools:

root@foo:/usr/local/src/bind9# apt-get install build-essential

Get the Bind9 source package:

root@foo:/usr/local/src/bind9# apt-get source bind9

This is what you should get:

root@foo:/usr/local/src/bind9# ls -1
bind9-9.5.1.dfsg.P2
bind9_9.5.1.dfsg.P2-1.diff.gz
bind9_9.5.1.dfsg.P2-1.dsc
bind9_9.5.1.dfsg.P2.orig.tar.gz

On Lucid, the package verison is bind9-9.7.0.dfsg.P1 instead.

We also need the MySQL client headers when building Bind9 with DLZ and MySQL:

root@foo:/usr/local/src/bind9# apt-get install libmysqlclient15-dev

On Lucid, install libmysqlclient-dev instead.

Cd into the unpacked source tree:

root@foo:/usr/local/src/bind9# cd bind9-9.5.1.dfsg.P2/

On Lucid, the directory is bind9-9.7.0.dfsg.P1 instead.

Modify the Debian build script:

root@foo:/usr/local/src/bind9/bind9-9.5.1.dfsg.P2# vim debian/rules

Change --with-dlz-mysql=no to --with-dlz-mysql=yes or add a line --with-dlz-mysql=yes (don't forget preceding backslash).

Install more build-time requirements. I didn't find out that I needed these until the dpkg-buildpackage step below complained about them being missing.

root@foo:/usr/local/src/bind9/bind9-9.5.1.dfsg.P2# apt-get install \
libkrb5-dev \
libkrb5-dev \
libssl-dev \
libtool \
libdb-dev \
libldap2-dev \
libldap2-dev \
libcap2-dev \
hardening-wrapper \
debhelper \
libxml2-dev

Build the binary packages. If dpkg-buildpackage complains about unmet dependencies, apt-get install what's missing, rinse and repeat.

root@foo:/usr/local/src/bind9/bind9-9.5.1.dfsg.P2# dpkg-buildpackage -rfakeroot -b

Back out one directory.

root@foo:/usr/local/src/bind9/bind9-9.5.1.dfsg.P2# cd ..

You should have roughly the following binary packages:

root@foo:/usr/local/src/bind9# ls -1
bind9-9.5.1.dfsg.P2
bind9_9.5.1.dfsg.P2-1_amd64.changes
bind9_9.5.1.dfsg.P2-1_amd64.deb
bind9_9.5.1.dfsg.P2-1.diff.gz
bind9_9.5.1.dfsg.P2-1.dsc
bind9_9.5.1.dfsg.P2.orig.tar.gz
bind9-doc_9.5.1.dfsg.P2-1_all.deb
bind9-host_9.5.1.dfsg.P2-1_amd64.deb
bind9utils_9.5.1.dfsg.P2-1_amd64.deb
dnsutils_9.5.1.dfsg.P2-1_amd64.deb
libbind9-40_9.5.1.dfsg.P2-1_amd64.deb
libbind-dev_9.5.1.dfsg.P2-1_amd64.deb
libdns45_9.5.1.dfsg.P2-1_amd64.deb
libisc45_9.5.1.dfsg.P2-1_amd64.deb
libisccc40_9.5.1.dfsg.P2-1_amd64.deb
libisccfg40_9.5.1.dfsg.P2-1_amd64.deb
liblwres40_9.5.1.dfsg.P2-1_amd64.deb
lwresd_9.5.1.dfsg.P2-1_amd64.deb

Install the binary packages on your system.

root@foo:/usr/local/src/bind9# dpkg -i *.deb

Update (12/30/2009)

I seem to be running into a problem connected with leaking or intermittedly dying connections to the MySQL server. Bind logs "mysql driver unable to return result set for findzone query" and eventually dies. This matches a problem description I found in a discussion on the DLZ mailing list with some interesting findings. I have not applied the suggested patch yet and am trying to fix the problem solely by forcing Bind to run in a single thread which has also been suggested in that thread.
root@foo:~# vim /etc/default/bind9
Change OPTIONS to include -n 1:
OPTIONS="-u bind -n 1"

Update (01/01/2010)

The order in which the bind9 and mysql init scripts are started by default does not reflect the fact that there now is a dependency of Bind9 on MySQL. Rebooting the system will start bind before mysql which causes bind to exit. Changing the boot order of init scripts is a bit involved so bare with me.
root@foo:~# apt-get install insserv
Edit the mysql init scripts and remove the $named from the two lines beginning with # Should-Start: and # Should-Stop:
root@foo:~# vim /etc/init.d/mysql-ndb
root@foo:~# vim /etc/init.d/mysql-ndb-mgm 
root@foo:~# vim /etc/init.d/mysql
Append mysql to the Should-Start and Should-Stop lines. The 3rd file does not exsist on Lucid. Ignore it.
root@foo:~# vim /etc/init.d/bind9
Run insserv to set up the necessary symlinks in /etc/rcX.d.
root@foo:~# insserv mysql
root@foo:~# insserv bind9
Reboot to make sure everything is in order.

Update (6/27/2010)

This one makes me very angry: Lucid's version of Bind includes a patch that changes the interpolation character in DLZ's configuration file from % to $ for whatever reason. This isn't mentioned anywhere (the DLZ website still documents the old syntax) and what's worse: the error messages haven't been patched. Even though DLZ is looking for $zone$, the syslog entries complain about %zone% being missing. Let me vent: To whoever is responsible for this mess: What is wrong with you? How hard can it be to replace one character with another? The percent sign doesn't occur that frequently in C code. How could you have missed that? You cost me an hour of my life. Let's raise the bar a bit, ok?

Anyways, I was getting this:

...
    Jun 27 21:14:12 a named[25385]: Loading 'Dynamic zone' using driver mysql
    Jun 27 21:14:12 a named[25385]: Required token %zone% not found.
    Jun 27 21:14:12 a named[25385]: Could not build all nodes query list
    Jun 27 21:14:12 a named[25385]: mysql driver could not create database instance object.
    Jun 27 21:14:12 a kernel: [ 2027.484135] named[25386]: segfault at 58 ip ...

Notice the segfault at the end? Yum!

After replacing % with $ in named.conf.local everything worked.

( categories: Unix )