一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

CentOS 7 服务器安装配置DNS服务器PowerDNS/PowerAdmin

时间:2015-06-22 编辑:简简单单 来源:一聚教程网

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

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

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

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

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

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

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

    # yum install epel-release.noarch

Enable Epel Repository启用Epel仓库

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

    # yum -y install mariadb-server mariadb

Install MariaDB Server

安装MariaDB服务器

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

    # systemctl enable mariadb.service
    # systemctl start mariadb.service

Enable Start MariaDB System Boot

启用MariaDB开机启动

4、 现在MariaDB服务运行起来了,我们将为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

Install PowerDNS with MariaDB Backend

安装带有MariaDB后端的PowerDNS

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

    # mysql -u root -p
    MariaDB [(none)]> CREATE DATABASE powerdns;
Create PowerDNS 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;

Create PowerDNS User

创建PowerDNS用户

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

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

Create Table Domains for PowerDNS

创建用于PowerDNS的表domains

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

Create Table Records for PowerDNS

创建用于PowerDNS的表 records

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

Create Index of Table

创建表索引

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

Create Table Supermaster

创建表supermasters

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

    MariaDB [(none)]> quit;

9、 最后,我们可以继续配置PowerDNS了,以MariaDB作为后台。请打开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”为你先前设置的实际密码,配置如下:
Configure PowerDNS

配置PowerDNS

保存修改并退出。

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

    # systemctl enable pdns.service
    # systemctl start pdns.service

Enable and Start PowerDNS

启用并启动PowerDNS

到这一步,你的PowerDNS服务器已经起来并运行了。



我还在网上找了一篇关于PowerDNS的教程,也不错,值得参考

利用PowerDNS搭建免费DNS服务器 附PowerDNS安装配置全过程


出于各种原因,我们很多用户可能需要自己搭建DNS服务器,搭建的方法有各种,老左有幸接触到免费开源的PowerDNS系统,可以帮助我们在Windows和Linux上搭建免费DNS服务器。公众对于PowerDNS介绍是这样的,老左就复制原话"PowerDNS是一个跨平台的开源DNS服务组件,PowerDNS同时有Windows和Linux/Unix的版本。PowerDNS在Windows下可以使用Access的mdb文件记录DNS信息,然后在Linux/Unix下则可以使用MySQL来记录DNS信息。"

本来是在国外的博客中有看到介绍以及安装方法的,但由于信息可能过时,或者是老左技不如人琢磨了2天时间才完整的搭建成功,然后再重新安装一遍VPS,已完成这篇文章的撰写。至少我可以保证这篇PowerDNS搭建过程是自己成功演练下进行的,这篇文章是基于centos 6 32位完成的,记录如下。

第一、安装MYSQL服务组件

因为PowerDNS是需要用到MYSQL数据库存储数据的,所以需要搭建MYSQL数据库环境。

    yum -y install mysql mysql-server #安装MYSQL
    chkconfig --levels 235 mysqld on #设置开机启动
    /etc/init.d/mysqld start

修改root用户mysql密码

    mysqladmin -u root passwordmyrootpassword

第二、安装PowerDNS

    yum install wget
    wget http://soft.laozuo.org/powerdns/epel-release-6-8.noarch.rpm
    rpm -Uvh ./epel-release-6-8.noarch.rpm

    yum install pdns pdns-backend-mysql

连接MYSQL,创建数据库

    mysql -u root -p

连接之后,输入我们上面设置的密码登录MYSQL,之后开始创建数据库和用户

create database powerdns; #创建数据库

#创建数据库用户power_user ,并且设置www.laozuo.org为密码,我们设置的时候修改成自己的密码

grant all onpowerdns.* to'power_user'@'localhost' identified by'www.laozuo.org';
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);

#退出当前MYSQL管理

    quit;

第三、编辑vi /etc/pdns/pdns.conf配置文件

    launch=gmysql
    gmysql-host=127.0.0.1
    gmysql-user=power_user
    gmysql-password=www.laozuo.org
    gmysql-dbname=powerdns

添加上述至pdns.conf最后,注意修改上面的数据库用户名以及密码对照上面设置的。

PowerDNS配置MYSQL文件

设置开机自动启动PowerDNS

    chkconfig --levels 235 pdns on
    /etc/init.d/pdns start

到目前为止,我们POWERDNS已经安装完毕,我们后面需要安装WEB管理界面。

第四、安装PowerAdmin管理平台

A - 安装PHP环境

    yum -y install httpd php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mhash gettext

设置开机启动apache

    chkconfig --levels 235 httpd on
    /etc/init.d/httpd start

B - 安装环境需要的2个支持组件

    yum install php-pear-DB php-pear-MDB2-Driver-mysql

C - 安装PowerAdmin

以上A,B都完成PowerAdmin 需要支持的环境,这里我们安装最新poweradmin-2.1.7版本包

    cd /tmp
    wgethttp://soft.laozuo.org/powerdns/poweradmin-2.1.7.tgz

    tar zxvfpoweradmin-2.1.7
    mv poweradmin-2.1.7 /var/www/html/poweradmin
    touch /var/www/html/poweradmin/inc/config.inc.php
    chown -R apache:apache /var/www/html/poweradmin/

我们先导临时文件夹tmp中下载和解压最新版本poweradmin-2.1.7,然后移动到VAR/WWW/HTML目录下。

这样完毕之后,我们可以用自己VPS的IP地址/poweradmin/install/打开POWERDNS安装向导。

PowerDNS安装WEB向导

第五、安装PowerAdmin向导

这里我们看上图,选择第一个英文语言,后面我们在设置账户登录时候可以选择CHINESE。
PowerDNS输入之前设置的数据库信息

这里输入的是设置的数据库信息,以及设置Poweradmin面板密码。

PowerDNS-4

设置数据库用户信息,以及DNS的域名服务器信息。

然后一直确定到最后,需要删除install/目录文件,然后在ip地址/poweradmin/登录POWERDNS面板。

PowerDNS-5

面板管理用户名admin,密码为我们之前设置的,可以选择CHINESE中文面板。

PowerDNS-6

到目前为止,我们已经看到PowerDNS全部安装完毕,而且可以登录管理界面。因为是演示操作,所以数据库我这里用的root信息,如果我们真实搭建时候需要单独一个用户信息,确保账户的安全。对于如何使用,如果以后有时间写一篇补充应用方法,一般会用的朋友应该自己能琢磨。

热门栏目