网站搜索

如何在 RHEL/CentOS 7 中安装和配置“PowerDNS”(使用 MariaDB)和“PowerAdmin”


PowerDNS 是一个在许多 Linux/Unix 衍生产品上运行的 DNS 服务器。它可以配置不同的后端,包括 BIND 样式区域文件、关系数据库或负载平衡/故障转移算法。它还可以设置为 DNS 递归程序,作为服务器上的单独进程运行。

PowerDNS 权威服务器的最新版本是 3.4.4,但目前 EPEL 存储库中可用的版本是 3.4.3。我建议为 EPEL 存储库安装该版本,因为该版本已在 CentOS 和 Fedora 中进行了测试。这样您将来还可以轻松更新 PowerDNS

本文旨在向您展示如何安装和设置带有 MariaDB 后端的主 PowerDNS 服务器和 PowerAdmin(一个友好的 Web 界面管理工具) PowerDNS。

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

Hostname: centos7.localhost 
IP Address 192.168.0.102

第 1 步:安装 PowerDNS 和 MariaDB 后端

1. 首先,您需要为您的服务器启用 EPEL 存储库,只需使用:

yum install epel-release.noarch 

2.下一步是安装MariaDB服务器。这可以通过运行以下命令轻松完成:

yum -y install mariadb-server mariadb

3. 接下来我们将配置 MySQL 以在系统启动时启用并启动:

systemctl enable mariadb.service
systemctl start mariadb.service

4. 现在 MySQL 服务正在运行,我们将通过运行以下命令来保护 MariaDB 并设置密码:

mysql_secure_installation
按照指示
/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):  Press ENTER
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y     
New password:  ← Set New Password
Re-enter new password:  ← Repeat Above Password
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y ← Choose “y” to disable that user
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n ← Choose “n” for no
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y ← Choose “y” for yes
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y ← Choose “y” for yes
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

5.一旦MariaDB配置成功,我们就可以进一步安装PowerDNS。这可以通过运行轻松完成:

yum -y install pdns pdns-backend-mysql

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

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

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

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

注意:将“howtoing123”替换为您要用于设置的实际密码。

8. 我们继续创建 PowerDNS 使用的数据库表。逐块执行这些:

MariaDB [(none)]> USE powerdns;
MariaDB [(none)]> 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)
);

MariaDB [(none)]> CREATE UNIQUE INDEX name_index ON domains(name);
MariaDB [(none)]> 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)
);

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

MariaDB [(none)]> CREATE TABLE supermasters (
ip VARCHAR(25) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) DEFAULT NULL
);

您现在可以通过键入以下内容退出 MySQL 控制台:

MariaDB [(none)]> quit;

9. 最后,我们可以继续配置 PowerDNS,它将使用 MySQL 作为后端。为此,打开位于以下位置的 PowerDNS 配置文件:

vim /etc/pdns/pdns.conf 

在该文件中查找如下所示的行:

#################################
launch        Which backends to launch and order to query them in
#
launch=

之后添加以下代码:

launch=gmysql
gmysql-host=localhost
gmysql-user=powerdns
gmysql-password=user-pass
gmysql-dbname=powerdns

将“user-pass”更改为您之前设置的实际密码。我的配置如下:

保存更改并退出。

10. 现在我们将启动 PowerDNS 并将其添加到系统启动时启动的服务列表中:

systemctl enable pdns.service 
systemctl start pdns.service 

此时,您的 PowerDNS 服务器已启动并正在运行。有关 PowerDNS 的更多信息,您可以参阅 http://downloads.powerdns.com/documentation/html/index.html 上提供的手册