CentOS 7 伺服器安裝配置DNS伺服器PowerDNS/PowerAdmin

來源:互聯網
上載者:User

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

啟用Epel倉庫

2、 下一步是安裝MariaDB伺服器。運行以下命令即可達成:

    # yum -y install mariadb-server mariadb

安裝MariaDB伺服器

3、 接下來,我們將配置並啟用MariaDB,並設定開機啟動:

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

啟用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

安裝帶有MariaDB後端的PowerDNS

6、 PowerDNS的設定檔位於/etc/pdns/pdns,在編輯之前,我們將為PowerDNS服務配置一個MariaDB資料庫。首先,我們將串連到MariaDB伺服器並建立一個名為powerdns的資料庫:

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

建立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;

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

建立用於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)
    );

建立用於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);

建立表索引

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

建立表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”為你先前設定的實際密碼,配置如下:

配置PowerDNS

儲存修改並退出。

10、 現在,我們將啟動並添加PowerDNS到系統開機啟動列表:

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

啟用並啟動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

    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安裝嚮導。

第五、安裝PowerAdmin嚮導

這裡我們看上圖,選擇第一個英文語言,後面我們在設定賬戶登入時候可以選擇CHINESE。

這裡輸入的是設定的資料庫資訊,以及設定Poweradmin面板密碼。

設定資料庫使用者資訊,以及DNS的網域名稱伺服器資訊。

然後一直確定到最後,需要刪除install/目錄檔案,然後在ip地址/poweradmin/登入POWERDNS面板。

面板系統管理使用者名admin,密碼為我們之前設定的,可以選擇CHINESE中文面板。

到目前為止,我們已經看到PowerDNS全部安裝完畢,而且可以登入管理介面。因為是示範操作,所以資料庫我這裡用的root資訊,如果我們真實搭建時候需要單獨一個使用者資訊,確保賬戶的安全。對於如何使用,如果以後有時間寫一篇補充應用方法,一般會用的朋友應該自己能琢磨。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.