> CentOS > CentOS服务器 > 环境配置 >

RHEL/CentOS 7中安装并配置 PowerDNS 和 PowerAdmin

PowerDNS是一个运行在许多Linux/Unix衍生版上的DNS服务器,它可以使用不同的后端进行配置,包括BIND类型的区域文件、关系型数据库,或者负载均衡/失效转移算法。它也可以被配置成一台DNS递归器,作为服务器上的一个独立进程运行。

PowerDNS授权服务器的最新版本是3.4.4,但是当前EPEL仓库中可以获得的版本是3.4.3。我推荐安装EPEL仓库中提供的那一个,因为该版本已经在CentOS和Fedora中测试过。那样,你也可以在今后很容易地更新PowerDNS。

本文用于向你演示如何安装并配置以MariaDB作为后端的PowerDNS,以及它的界面友好的 Web 管理工具 PowerAdmin。

出于本文的写作目的,我将使用以下服务器:


  1. 主机名: centos7.localhost
  2. IP地址: 192.168.0.102

第一部分: 安装带有MariaDB后端的PowerDNS

1、 首先,你需要为你的系统启用EPEL仓库,只需使用:


  1. # yum install epel-release.noarch

Enable Epel Repository

启用Epel仓库

2、 下一步是安装MariaDB服务器。运行以下命令即可达成:


  1. # yum -y install mariadb-server mariadb

Install MariaDB Server

安装MariaDB服务器

3、 接下来,我们将配置并启用MariaDB,并设置开机启动:


  1. # systemctl enable mariadb.service
  2. # systemctl start mariadb.service

Enable Start MariaDB System Boot

启用MariaDB开机启动

4、 现在MariaDB服务运行起来了,我们将为MariaDB设置密码进行安全加固,运行以下命令:


  1. # mysql_secure_installation

按照指示做


  1. /bin/mysql_secure_installation: line 379: find_mysql_client: command not found
  2.  
  3. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  4. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  5.  
  6. In order to log into MariaDB to secure it, we'll need the current
  7. password for the root user. If you've just installed MariaDB, and
  8. you haven't set the root password yet, the password will be blank,
  9. so you should just press enter here.
  10.  
  11. Enter current password for root (enter for none): Press ENTER
  12. OK, successfully used password, moving on...
  13.  
  14. Setting the root password ensures that nobody can log into the MariaDB
  15. root user without the proper authorisation.
  16.  
  17. Set root password? [Y/n] y
  18. New password: ← Set New Password
  19. Re-enter new password: ← Repeat Above Password
  20. Password updated successfully!
  21. Reloading privilege tables..
  22. ... Success!
  23.  
  24.  
  25. By default, a MariaDB installation has an anonymous user, allowing anyone
  26. to log into MariaDB without having to have a user account created for
  27. them. This is intended only for testing, and to make the installation
  28. go a bit smoother. You should remove them before moving into a
  29. production environment.
  30.  
  31. Remove anonymous users? [Y/n] y ← Choose “y” to disable that user
  32. ... Success!
  33.  
  34. Normally, root should only be allowed to connect from 'localhost'. This
  35. ensures that someone cannot guess at the root password from the network.
  36.  
  37. Disallow root login remotely? [Y/n] n ← Choose “n” for no
  38. ... skipping.
  39.  
  40. By default, MariaDB comes with a database named 'test' that anyone can
  41. access. This is also intended only for testing, and should be removed
  42. before moving into a production environment.
  43.  
  44. Remove test database and access to it? [Y/n] y ← Choose “y” for yes
  45. - Dropping test database...
  46. ... Success!
  47. - Removing privileges on test database...
  48. ... Success!
  49.  
  50. Reloading the privilege tables will ensure that all changes made so far
  51. will take effect immediately.
  52.  
  53. Reload privilege tables now? [Y/n] y ← Choose “y” for yes
  54. ... Success!
  55.  
  56. Cleaning up...
  57.  
  58. All done! If you've completed all of the above steps, your MariaDB
  59. installation should now be secure.
  60.  
  61. Thanks for using MariaDB!

5、 MariaDB配置成功后,我们可以继续去安装PowerDNS。运行以下命令即可轻易完成:


  1. # yum -y install pdns pdns-backend-mysql

Install PowerDNS with MariaDB Backend

安装带有MariaDB后端的PowerDNS

6、 PowerDNS的配置文件位于/etc/pdns/pdns,在编辑之前,我们将为PowerDNS服务配置一个MariaDB数据库。首先,我们将连接到MariaDB服务器并创建一个名为powerdns的数据库:


  1. # mysql -u root -p
  2. MariaDB [(none)]> CREATE DATABASE powerdns;

Create PowerDNS Database

创建PowerDNS数据库

7、 接下来,我们将创建一个名为powerdns的数据库用户:


  1. MariaDB [(none)]> GRANT ALL ON powerdns.* TO 'powerdns'@'localhost' IDENTIFIED BY tecmint123’;
  2. MariaDB [(none)]> GRANT ALL ON powerdns.* TO 'powerdns'@'centos7.localdomain' IDENTIFIED BY 'tecmint123';
  3. MariaDB [(none)]> FLUSH PRIVILEGES;

Create PowerDNS User

创建PowerDNS用户

注意: 请将“tecmint123”替换为你想要设置的实际密码。

8、 我们继续创建PowerDNS要使用的数据库表。像堆积木一样执行以下这些:


  1. MariaDB [(none)]> USE powerdns;
  2. MariaDB [(none)]> CREATE TABLE domains (
  3. id INT auto_increment,
  4. name VARCHAR(255) NOT NULL,
  5. master VARCHAR(128) DEFAULT NULL,
  6. last_check INT DEFAULT NULL,
  7. type VARCHAR(6) NOT NULL,
  8. notified_serial INT DEFAULT NULL,
  9. account VARCHAR(40) DEFAULT NULL,
  10. primary key (id)
  11. );

Create Table Domains for PowerDNS

创建用于PowerDNS的表domains


  1. MariaDB [(none)]> CREATE UNIQUE INDEX name_index ON domains(name);
  2. MariaDB [(none)]> CREATE TABLE records (
  3. id INT auto_increment,
  4. domain_id INT DEFAULT NULL,
  5. name VARCHAR(255) DEFAULT NULL,
  6. type VARCHAR(6) DEFAULT NULL,
  7. content VARCHAR(255) DEFAULT NULL,
  8. ttl INT DEFAULT NULL,
  9. prio INT DEFAULT NULL,
  10. change_date INT DEFAULT NULL,
  11. primary key(id)
  12. );

Create Table Records for PowerDNS

创建用于PowerDNS的表 records


  1. MariaDB [(none)]> CREATE INDEX rec_name_index ON records(name);
  2. MariaDB [(none)]> CREATE INDEX nametype_index ON records(name,type);
  3. MariaDB [(none)]> CREATE INDEX domain_id ON records(domain_id);

Create Index of Table

创建表索引


  1. MariaDB [(none)]> CREATE TABLE supermasters (
  2. ip VARCHAR(25) NOT NULL,
  3. nameserver VARCHAR(255) NOT NULL,
  4. account VARCHAR(40) DEFAULT NULL
  5. );

Create Table Supermaster

创建表supermasters

你现在可以输入以下命令退出MariaDB控制台:


  1. MariaDB [(none)]> quit;

9、 最后,我们可以继续配置PowerDNS了,以MariaDB作为后台。请打开PowerDNS的配置文件:


  1. # vim /etc/pdns/pdns.conf

在该文件中查找像下面这样的行:


  1. #################################
  2. # launch Which backends to launch and order to query them in
  3. #
  4. # launch=

在这后面放置以下代码:


  1. launch=gmysql
  2. gmysql-host=localhost
  3. gmysql-user=powerdns
  4. gmysql-password=user-pass
  5. gmysql-dbname=powerdns

修改“user-pass”为你先前设置的实际密码,配置如下:

Configure PowerDNS

配置PowerDNS

保存修改并退出。

10、 现在,我们将启动并添加PowerDNS到系统开机启动列表:


  1. # systemctl enable pdns.service
  2. # systemctl start pdns.service

Enable and Start PowerDNS

启用并启动PowerDNS

到这一步,你的PowerDNS服务器已经起来并运行了。要获取更多关于PowerDNS的信息,你可以参考手册http://downloads.powerdns.com/documentation/html/index.html



(责任编辑:IT)