PowerDNS配置不完全手册。

2022-11-22,,

Linux平台下配置DNS服务器,大家一定首选想到的是BIND,不错BIND绝对是DNS服务器软件的老大,全球13台根域名服务器中有10台使用的是BIND。不过使用开源软件有一个很大的好处就是无论你要做什么永远会有不止一种选择,如果你不想使用BIND配置DNS服务器,那么PowerDNS会是一个不错的选择。

PowerDNS(官方网站:http://www.powerdns.com/)是一个跨平台的开源DNS服务组件,PowerDNS同时有WindowsLinux/Unix的版本。PowerDNSWindows下可以使用Accessmdb文件记录DNS信息,而在Linux/Unix下则可以使用MySQL来记录DNS信息。

下面我们一起来看下在如下图所示一个简单的网络拓扑中,如何在Debian Square平台下通过PowerDNSPoweradmin(一个基于WebPowerDNS管理工具)配置一个DNS服务器。

 

 

1、    由于我们需要将PowerDNS的数据保存到MySQL数据库中,所以首先使用如下命令安装MySQL,在安装过程中需要设置MySQL管理员(root用户的密码)。

[email protected]:~# apt-get -y install mysql-server mysql-client

2、    使用如下命令注释MySQL配置文件(/etc/mysql/my.cnf)的bind-address参数,以便使MySQL可以侦听所有网络接口的访问语法。

[email protected]:~# netstat -tunlp | grep 3306

tcp    0   0 127.0.0.1:3306      0.0.0.0:*               LISTEN      3275/mysqld    

[email protected]:~# sed -i -e 's/bind-address/#bind-address/' /etc/mysql/my.cnf

[email protected]:~# /etc/init.d/mysql restart

Stopping MySQL database server: mysqld.

Starting MySQL database server: mysqld.

Checking for corrupt, not cleanly closed and upgrade needing tables..

[email protected]:~# netstat -tunlp | grep 3306                                 

tcp    0   0 0.0.0.0:3306        0.0.0.0:*               LISTEN      3600/mysqld 

3、    使用如下命令安装PowerDNS

[email protected]:~# apt-get -y install pdns-server pdns-backend-mysql

4、    使用mysql -u root -p命令登录到MySQL后,建立PowerDNS所需的数据库及表。

[email protected]:~# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 36

Server version: 5.1.49-3 (Debian)

 

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

#建立一个名为dnsdb的数据库用于存储PowerDNS的数据。

mysql> create database dnsdb;

Query OK, 1 row affected (0.00 sec)

 

#建立一个名为pdnsuser的用户,用于PowerDNS服务访问dnsdb数据库。

mysql> GRANT ALL ON dnsdb.* TO 'pdnsuser'@'localhost' IDENTIFIED BY 'tonyzhang';                    

Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL ON dnsdb.* TO 'pdnsuser'@'localhost.localdomain' IDENTIFIED BY 'tonyzhang';                       

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

 

#打开dnsdb数据库。

mysql> use dnsdb;  

Database changed

#建立PowerDNS所需的表。

mysql> 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)

    -> );

Query OK, 0 rows affected (0.09 sec)

 

mysql> 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)

    -> );

Query OK, 0 rows affected (0.06 sec)

 

mysql> CREATE TABLE supermasters (

    -> ip VARCHAR(25) NOT NULL,

    -> nameserver VARCHAR(255) NOT NULL,

    -> account VARCHAR(40) DEFAULT NULL

    -> );

Query OK, 0 rows affected (0.05 sec)

 

#为了提高PowerDNS查询数据库记录的速度,可以为表建立一些必要的索引。

mysql> CREATE UNIQUE INDEX name_index ON domains(name);

Query OK, 0 rows affected (0.05 sec)

Records: 0  Duplicates: 0  Warnings: 0

 

mysql> CREATE INDEX rec_name_index ON records(name);

Query OK, 0 rows affected (0.06 sec)

Records: 0  Duplicates: 0  Warnings: 0

 

mysql> CREATE INDEX nametype_index ON records(name,type);

Query OK, 0 rows affected (0.00 sec)

Records: 0  Duplicates: 0  Warnings: 0

 

mysql> CREATE INDEX domain_id ON records(domain_id);

Query OK, 0 rows affected (0.05 sec)

Records: 0  Duplicates: 0  Warnings: 0

 

mysql> quit;

 

5、    修改/etc/powerdns/pdns.conf文件如下内容,使PowerDNS使用MySQL数据库。

launch=gmysql

6、    /etc/powerdns/pdns.d/pdns.local文件中增加如下内容,配置PowerDNS访问MySQL数据库的信息。

gmysql-host=127.0.0.1

gmysql-user=powerdns

gmysql-password=tonyzhang

gmysql-dbname=dnsdb

7、    使用如下命令启动PowerDNS服务。

[email protected]:~# /etc/init.d/pdns restart

8、    为了使用PowerDNS的管理工具Poweradmin,使用如下命令安装ApachePHP

[email protected]:~# apt-get -y install apache2 libapache2-mod-php5 php5 php5-common  \

php5-curl php5-dev php5-gd php-pear php5-imap gettext   \

php5-mcrypt php5-mhash php5-ming php5-mysql php5-xmlrpc

[email protected]:~# pear install DB

[email protected]:~# pear install pear/MDB2#mysql

9、    使用如下命令下载Poweradmin后,存入/var/www目录中(这里只是为了演示所以简单的将Poweradmin放到Apache的默认站点中,在实际生产环境中可以根据情况配置)。

[email protected]:~# wget https://www.poweradmin.org/download/poweradmin-2.1.5.tgz

[email protected]:~# tar -xvzf poweradmin-2.1.5.tgz

[email protected]:~# mv poweradmin-2.1.5 /var/www/dnsadmin

[email protected]:~# chown -R www-data:www-data /var/www/dnsadmin

10、重新启动Apache服务后,在浏览器中访问http://192.168.13.10/dnsadmin/install/index.php会出现Poweradmin的配置向导页面,首选选择使用默认的英语(如下图所示);第2页是一个提示信息页,直接进入下一个配置页面。

 

11、    3页是配置MySQL数据库的信息,输入MySQLroot用户(注意是root用户)、密码、地址、端口、数据库名称,最后一个输入框是是指定以后登录Poweradmin时管理员(admin)的密码。

 

12、    4页指定为PowerDNS建立的MySQL用户的信息,输入在第4步中为建立的MySQL用户(本例中为pdnsuser)、密码以及SOANS记录(这二个记录全成为以后创建区域是的模板记录)。

 

 

13、    最后2页是提示信息。在完成配置后,使用如下命令将install目录删除(只有删除后Poweradmin才允许用户登录进行管理)。

[email protected]:~# rm -rf /var/www/dnsadmin/install/

14、    接下来就可以通过http://192.168.13.10/dnsadmin访问Poweradmin登录页面,输入管理用户(admin)以及密码(第11步“Poweradmin administrator password”中输入的内容)。

 

上图是登录后的Poweradmin管理页面,了解DNS服务的GGDD们应该很容易掌握Poweradmin的使用方法,这里就不一一介绍了。

转载于:https://blog.51cto.com/onlyzq/526504