The goal of this guide is to setup a PowerDNS master with mySQL as backend, then use mySQL replication to update the slaves.
When the master/slave is done, we will add Poweradmin as webinterface for the admin/users to update their dns-zones.
Everything running on Debian (ofcourse 🙂 )
This guide will only cover the installation, no optimisation. That is another topic.
The usernames/password in this guide is only used as reference, do NOT use the same username/password in your production installation.
Master DNS Server Install
Install PowerDNS and MySQL
1 |
apt-get install mysql-server pdns-server pdns-backend-mysql |
During the installation you will set the password for the mysql root user (mysqlpassword is used in this guide)Â , write this down or memorize it. Whenever you find the password below, change t to the one you have chosen.
Now we need to create the database, create an mySQL user that we later on will use to connect with.
1 2 3 4 5 6 7 8 |
mysql -u root -p Create database pdns; CREATE USER 'pdns'@'localhost' IDENTIFIED BY 'mypass'; GRANT ALL PRIVILEGES ON pdns.* TO 'pdns'@'localhost'; quit; |
Ok, database and user created, time to populate the database.
Download this  sql file here, it will help you create all needed tables.
1 2 3 |
wget http://www.lowendguide.com/pdns.sql mysql -u root -pmysqlpassword pdns < pdns.sql |
Database populated, time to edit the configuration files. First out is the Powerdns configuration file
pdns.conf
Edit /etc/powerdns/pdns.conf and add  your database details at the end of the file:
1 2 3 4 5 |
launch=gmysql gmysql-host=127.0.0.1 gmysql-user=pdns gmysql-password=mypass gmysql-dbname=pdns |
Then it’s time to change some existing values
Find and update accordingly:
1 2 3 |
default-soa-name=a.misconfigured.powerdns.server |
Close and save then start powerdns in monitored mode to check your configuration :
1 2 3 |
/etc/init.d/pdns monitor |
We will now check that our installation is working by running a few commands:
Open a new terminal and run this  command (it should reurn an error)
1 2 3 |
host www.lowendguide.com 127.0.0.1 |
if you get a “command not found” error,
1 2 3 |
apt-get install dnsutils |
The proper response to your “host” command should be something like this:
1 2 3 4 5 6 7 8 |
Using domain server: Name: 127.0.0.1 Address: 127.0.0.1#53 Aliases: Host www.lowendguide.com not found: 2(SERVFAIL) |
and our monitor terminal shows this :
1 2 3 |
Not authoritative for 'www.lowendguide.com', sending servfail to 127.0.0.1 (recursion was desired) |
Why does it fail you may ask? Because we haven’t enabled recursion on our DNS server.
If you want to enable recursion, edit /etc/powerdns/pdns.conf and find this :
1 2 3 |
# Â recursor= |
and change to this:
1 2 3 |
recursor= 8.8.8.8 |
if you want to use googles DNS server.
[alert style=”green”] Note that if this will be a public DNS server, the recommendations are NOT to enable recursion. The only time recursion should be used is by DNS-servers on your own internal network. [/alert]
Now we have a working PowerDNS server that we will use as MASTER in our DNS-Cluster.
Slave DNS Server Install
Same steps as for out MASTER PowerDNS server:
1 |
apt-get install mysql-server pdns-server pdns-backend-mysql |
Create database and mysql user
1 2 3 4 5 |
mysql -u root -p Create database pdns; CREATE USER 'pdns'@'localhost' IDENTIFIED BY 'mypass'; GRANT ALL PRIVILEGES ON pdns.* TO 'pdns'@'localhost'; quit; |
Download and populate the database
1 2 3 |
wget http://www.lowendguide.com/pdns.sql mysql -u root -pmysqlpassword pdns < pdns.sql |
Edit /etc/powerdns/pdns.conf
1 2 3 4 5 |
launch=gmysql gmysql-host=127.0.0.1 gmysql-user=pdns gmysql-password=mypass gmysql-dbname=pdns |
If you want to enable recursion on the slave also, find this :
1 2 3 |
# Â recursor= |
and change to this:
1 2 3 |
recursor= 8.8.8.8 |
Check that everything was entered correct by running
1 |
/etc/init.d/pdns monitor |
write
1 |
quit |
the exit the monitor mode and start PowerDNS with
1 |
/etc/init.d/pdns start |
By now we have two working DNS server, time to make sure that they will have the same information.
MySQL Replication to Slaves
This part is really important and needs to be done correctly. All the slaves need to contact the master to get the MySQL updates and keep in sync. It may seem complicated but once it’s setup you don’t need to touch it again and you will achieve instant DNS updates across your cluster.
Master Replication Setup
This part needs to be performed on the MASTER dns server only.
Edit /etc/mysql/my.cnf with the following settings:
1 2 3 4 5 6 7 |
server-id = 1 log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M binlog_do_db = pdns |
Also find this:
1 2 3 |
bind-address       = 127.0.0.1 |
and change it this:
1 2 3 |
bind-address       = 0.0.0.0 |
Exit, save and restart MySQL:
1 |
/etc/init.d/mysql restart |
MySQL Replication User
A new SQL user needs to be created on the master:
1 |
mysql -u root -p |
After entering the SQL root password:
Here is an important part that I noticed, I could not get the replication to work if I set a wildcard host to the mysql user. I had to use the IP of the slave. If you get it to work, leave a comment on how you did it.
1 2 3 4 |
grant replication slave on *.* to 'pdnsslave'@'<ip or dnsname of your slave>' identified by 'mynewpassword'; flush privileges; |
Next we need some information from the master SQL that we will use on the slave later on:
while still connected to the mysql server, run this command:
1 2 3 |
show master status; |
You should see something like this:
1 2 3 4 5 6 7 8 |
+------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 106 | pdns | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) |
Make a note of the File and Position values.
Slave Replication Setup
This part needs to be performed on the slave dns server(s) only.
Edit my.cnf
Edit /etc/mysql/my.cnf with the following settings:
1 2 3 4 5 |
server-id=2 master-connect-retry=60 relay-log=slave-relay-bin relay-log-index=slave-relay-bin.index replicate-do-db=pdns |
[alert style=”green”]
The server-id variable needs to be different on each of the slave dns servers. i.e server-id=2, server-id=3
[/alert]
Restart MySQL:
1 2 3 |
/etc/init.d/mysql restart |
Request Replication Access from the Master
1 2 3 |
mysql -u root -p |
After entering the password:
(remember the filename and position from the master server? It’s time to enter them below)
1 2 3 4 5 6 7 |
change master to master_host='DNS_MASTER_IP', master_user='pdnsslave', master_password='mynewpassword', master_log_file='mysql-bin.000001', master_log_pos=106; start slave; |
You can see the status by using the following command:
1 2 3 |
show slave status; |
Thats it! Replication is setup on the slave. When showing the status on the slave, if it says error anywhere, you need to troubleshoot the reason for the failure.
If you need to setup more DNS slaves, just follow the instructions again.
Common errors:
* Creating the pdnsslave user with * as host, I couldn’t get this to work. The slave wasn’t allowed to connect to the master! So when adding a new slave to the cluster you might need to add a new pdnsslave user for each new host.
Next step: Setup the webinterface so you easily can edit your DNS-entries.
I have decided to use Poweradmin 2.1.6, which was released on May 7th, 2012 in this guide.
Prerequisites
* MySQL or PostgreSQL.
* A webserver. Apache 2.2.3 has been tested. ( I used nginX for this guide )
* PHP. It needs the mysql or pgsql extension and the PHP modules: session, gettext, mcrypt.
* PEAR and its packages PEAR::MDB2, PEAR::MDB2_Driver_mysql or PEAR::MDB2_Driver_pgsql.
Installation steps (using the installer)
Using the installer is the recommended way of installing Poweradmin and I see no other reason not to.
Here are the steps needed to get it running. On the vps where you have installed your MASTER PowerDNS server. (I assume you have installed the webserver of your choice already)
First off is to change directory to your web accesible directory, then:
1 2 3 4 5 6 7 8 9 |
wget https://github.com/downloads/poweradmin/poweradmin/poweradmin-2.1.6.tgz tar zxvf poweradmin-2.1.6.tgz mkdir poweradmin cd poweradmin-2.1.6.tgz mv * ../poweradmin/ cd .. rm -rf poweradmin-2.1.6 |
That will create a subdirectory (poweradmin) where your installation will be.
If you are installing this in an already running PowerDNS environment, create a backup of your current PowerDNS database and files. Better safe than sorry.
The installer also expects you to have never ran Poweradmin before, it will therefore overwrite any already existing Poweradmin parts of the database. If you have had Poweradmin running before, any data in the following tables will be destroyed: perm_items, perm_templ, perm_templ_items, users and zones.
This installer will, of course, not touch the data in the PowerDNS tables of the database.
Point your browser to the install directory, e.g. “http://example.net/poweradmin/install”, and follow the instructions on the screen.
If you followed the complete guide, on step3 in the installer, the database settings use the pdns mySQL user settings that we used before.
Don’t forget to set the Poweradmin administrator password.
Finally, remove the “install/” directory from the Poweradmin directory.
Point your browser to “http://example.net/poweradmin/” and login using the username “admin” and the password you have provided during the installation process.
Â
6 comments for “PowerDNS Cluster with PowerAdmin Web-Interface”