PowerDNS: Instalasi Master dan Slave sekaligus jadi satu

From OnnoWiki
Revision as of 16:05, 1 June 2015 by Onnowpurbo (talk | contribs)
Jump to navigation Jump to search

Dalam tutorial ini akan di coba untuk mengkonfigurasi powerdns agar bisa berjalan sebagaiu master dan slave.

For this tutorial purpose, master powerdns host will have ip address 192.168.56.3 and hostname ns1.example.com, slave ip: 192.168.56.4 and hostname: ns2.example.com


Instalasi powerdns

apt-get install pdns-server pdns-backend-mysql pdns-recursor mysql-server



Konfigurasi Database

Create a file pdns-schema.sql and change password for poweradmin user in GRANT line:

CREATE DATABASE powerdns character set utf8; GRANT ALL ON powerdns.* TO 'poweradmin'@'localhost' IDENTIFIED BY 'yoursecretpassword'; FLUSH PRIVILEGES; USE powerdns; CREATE TABLE domains (

id INT auto_increment,
name VARCHAR(255) NOT NULL,
master VARCHAR(128) DEFAULT NULL,
last_check INT DEFAULT NULL,
type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL,
primary key (id)

); CREATE UNIQUE INDEX name_index ON domains(name); CREATE TABLE records (

id INT auto_increment,
domain_id INT DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
type VARCHAR(6) DEFAULT NULL,
content VARCHAR(255) DEFAULT NULL,
ttl INT DEFAULT NULL,
prio INT DEFAULT NULL,
change_date INT DEFAULT NULL,
primary key(id)

); CREATE INDEX rec_name_index ON records(name); CREATE INDEX nametype_index ON records(name,type); CREATE INDEX domain_id ON records(domain_id); CREATE TABLE supermasters (

ip VARCHAR(25) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) DEFAULT NULL

);

Load that structure to mysql server on both hosts:

mysql -u root -p < pdns-schema.sql

3.Powerdns configuration

Edit /etc/powerdns/pdns.d/pdns.local file and add

gmysql-host=127.0.0.1 gmysql-user=poweradmin gmysql-password=yoursecretpassword gmysql-dbname=powerdns

Now, move original files in /etc/powerdns directory and create new one with parameters shown in following sections:

cd /etc/powerdns mv pdns.conf pdns.conf.orig mv recursor.conf recursor.conf.orig

On ns1.example.com pdns.conf configuration file should look like:

allow-recursion=0.0.0.0/0 allow-axfr-ips=192.168.56.4/32 chroot=/var/spool/powerdns config-dir=/etc/powerdns daemon=yes disable-axfr=no disable-tcp=no guardian=yes launch=gmysql lazy-recursion=yes local-address=192.168.56.3 local-port=53 log-dns-details=on log-failed-updates=on loglevel=3 module-dir=/usr/lib/powerdns master=yes slave=no recursor=127.0.0.1 setgid=pdns setuid=pdns socket-dir=/var/run version-string=powerdns include=/etc/powerdns/pdns.d

Recursor.conf configuration on ns1.example.com:

allow-from=0.0.0.0/0 dont-query= local-address=127.0.0.1 local-port=53 quiet=yes setgid=pdns setuid=pdns

On ns2.example.com pdns.conf configuration file should look like:

allow-recursion=0.0.0.0/0 chroot=/var/spool/powerdns config-dir=/etc/powerdns daemon=yes disable-axfr=yes disable-tcp=no guardian=yes launch=gmysql lazy-recursion=yes local-address=192.168.56.4 local-port=53 module-dir=/usr/lib/powerdns recursor=127.0.0.1 setgid=pdns setuid=pdns master=no slave=yes slave-cycle-interval=60 socket-dir=/var/run version-string=powerdns include=/etc/powerdns/pdns.d

Recursor configuration on ns2.example.com (same as ns1.example.com):

allow-from=0.0.0.0/0 dont-query= local-address=127.0.0.1 local-port=53 quiet=yes setgid=pdns setuid=pdns

Poweradmin installation

Poweradmin will be installed on powerdns master host, so we need to install necessary packages:

apt-get install apache2-mpm-prefork php5-mysql libapache2-mod-php5 php-pear php-mdb2 php-mdb2-driver-mysql

Then download, unpack and make some preparations before installation process:

cd /var/www wget --no-check-certificate https://www.poweradmin.org/download/poweradmin-2.1.4.tgz tar zxvf poweradmin-2.1.4.tgz ln -s poweradmin-2.1.4 poweradmin chown www-data.www-data -R poweradmin-2.1.4 cp /var/www/poweradmin/inc/config-me.inc.php /var/www/poweradmin/inc/config.inc.php

With default apache2 configuration, type in web browser address http://192.168.56.3/poweradmin/install and follow steps to finish poweradmin installation

Instead of what is shown in step 6 use below listed grant for user poweradmin:

GRANT SELECT, INSERT, UPDATE, DELETE ON powerdns.* TO 'poweradmin'@'localhost'; FLUSH PRIVILEGES;

After successful installation remove install directory.

rm -rf /var/www/poweradmin/install

There is a small bug in latest stable release of poweradmin-2.1.4, which has been explained in ticket https://www.poweradmin.org/trac/ticket/346.To repair that replace line 196 with $retcount++; in inc/templates.inc.php file. Poweradmin usage

Type in your web browser http://192.168.56.3/poweradmin and login as admin with password you typed in installation (step 3)

Easiest way to manage domains is to create zone template or templeates. Got to List zone templates > Add zone template > fill Name('default' in that case)

Then edit 'default' zone template by adding new records:

  1. examples

[ZONE] SOA ns1.example.com hostmaster.example.com [SERIAL] 10800 3600 604800 600 [ZONE] A 192.168.56.3 86400 www.[ZONE] A 192.168.56.3 86400 mail.[ZONE] A 192.168.56.3 86400 [ZONE] NS ns1.example.com 86400 [ZONE] NS ns2.example.com 86400 [ZONE] MX mail.[ZONE] 10 86400

Make some tests with adding new domain using created zone template by adding master zone (choose type: master)

Don't forget to add ns1.example.com and ns2.example.com A type records.

Finally add into slave mysql server direction where master powerdns server is located by adding proper ip and master ns domain name.

use powerdns; insert into supermasters values ('192.168.56.3', 'ns1.example.com', 'admin');

Migration from bind

Use zone2sql script to migrate domains from bind to powerdns

zone2sql --gmysql --named-conf=/etc/bind/named.conf > bind.sql

If domain type is NATIVE, change it into MASTER using example sed command

sed 's/NATIVE/MASTER/g' bind.sql > bind.master.sql

Thats all folks. If you have any questions don't hesitate to write ;-)



Referensi