1. 程式人生 > >Centos7.4下部署PowerDNS的操作記錄

Centos7.4下部署PowerDNS的操作記錄

b-s ive 服務 user rap access 一個 高性能 sbin

之前已經介紹了DNS環境的部署過程,這裏說下PowerDNS的使用及部署,PowerDNS 是一個跨平臺的開源DNS服務組件,它是高性能的域名服務器,除了支持普通的BIND配置文件,PowerDNS還可以從MySQL,Oracle,PostgreSQL等的數據庫讀取數據。PowerDNS安裝了Poweradmin,能實現Web管理DNS記錄,非常的方便。

一、部署以MariaDB作為後端數據的PowerDNS系統

1)關閉防火墻和selinux

[root@PowerDNS ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

[root@PowerDNS ~]# setenforce 0
[root@PowerDNS ~]# getenforce 
[root@PowerDNS ~]# cat /etc/sysconfig/selinux |grep "SELINUX=disabled"
SELINUX=disabled

[root@PowerDNS ~]# systemctl stop firewalld 
[root@PowerDNS ~]# systemctl disable firewalld 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@PowerDNS ~]# firewall-cmd --state
not running

2)啟用EPEL倉庫

[root@PowerDNS ~]# yum install -y epel-release yum-plugin-priorities

3)安裝並配置MariaDB服務器

[root@PowerDNS ~]# yum install -y mariadb-server mariadb
[root@PowerDNS ~]# systemctl enable mariadb.service
[root@PowerDNS ~]# systemctl start mariadb.service
[root@PowerDNS ~]# lsof -i:3306

設置密碼
[root@PowerDNS ~]# mysql_secure_installation
首先是設置密碼,會提示先輸入密碼
  
Enter current password for root (enter for none):<–初次運行直接回車
  
設置密碼
  
Set root password? [Y/n] <– 是否設置root用戶密碼,輸入y並回車或直接回車
New password: <– 設置root用戶的密碼(比如123456)
Re-enter new password: <– 再輸入一次你設置的密碼
  
其他配置
Remove anonymous users? [Y/n] <– 是否刪除匿名用戶,回車
Disallow root login remotely? [Y/n] <–是否禁止root遠程登錄,回車,
Remove test database and access to it? [Y/n] <– 是否刪除test數據庫,回車
Reload privilege tables now? [Y/n] <– 是否重新加載權限表,回車

使用密碼登錄MariaDB,查看字符集
[root@PowerDNS ~]# mysql -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+


接下來配置MariaDB的字符集,設置成utf8:
-> 首先是配置文件/etc/my.cnf,在[mysqld]標簽下添加
init_connect=‘SET collation_connection = utf8_unicode_ci‘
init_connect=‘SET NAMES utf8‘
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
  
-> 接著配置文件/etc/my.cnf.d/client.cnf,在[client]中添加
default-character-set=utf8
  
-> 然後配置文件/etc/my.cnf.d/mysql-clients.cnf,在[mysql]中添加
default-character-set=utf8
  
最後是重啟MariaDB,並登陸MariaDB查看字符集
[root@PowerDNS ~]# systemctl restart mariadb.service

再次登錄MariaDB,查看字符集,發現已是utf8了
[root@PowerDNS ~]# mysql -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+----------------------+-----------------+

4)接著繼續安裝PowerDNS

[root@PowerDNS yum.repos.d]# yum install -y pdns pdns-backend-mysql

PowerDNS的配置文件位於/etc/pdns/pdns.conf
[root@PowerDNS ~]# ll /etc/pdns/pdns.conf 
-rw-------. 1 root root 14007 Feb  2 00:33 /etc/pdns/pdns.conf

5)為PowerDNS服務配置一個MariaDB數據庫。

[root@PowerDNS ~]# mysql -p123456
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> CREATE DATABASE powerdns;
MariaDB [(none)]> GRANT ALL ON powerdns.* TO ‘powerdns‘@‘localhost‘ IDENTIFIED BY ‘powerdns‘;
MariaDB [(none)]> FLUSH PRIVILEGES;


繼續創建PowerDNS要使用的數據庫表。像堆積木一樣執行以下這些sql語句(即復制下面的語句直接粘貼到MariaDB中一起執行)
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)
) Engine=InnoDB;

CREATE UNIQUE INDEX name_index ON domains(name);


CREATE TABLE records (
  id                    BIGINT AUTO_INCREMENT,
  domain_id             INT DEFAULT NULL,
  name                  VARCHAR(255) DEFAULT NULL,
  type                  VARCHAR(10) DEFAULT NULL,
  content               VARCHAR(64000) DEFAULT NULL,
  ttl                   INT DEFAULT NULL,
  prio                  INT DEFAULT NULL,
  change_date           INT DEFAULT NULL,
  disabled              TINYINT(1) DEFAULT 0,
  ordername             VARCHAR(255) BINARY DEFAULT NULL,
  auth                  TINYINT(1) DEFAULT 1,
  PRIMARY KEY (id)
) Engine=InnoDB;

CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
CREATE INDEX recordorder ON records (domain_id, ordername);


CREATE TABLE supermasters (
  ip                    VARCHAR(64) NOT NULL,
  nameserver            VARCHAR(255) NOT NULL,
  account               VARCHAR(40) NOT NULL,
  PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;


CREATE TABLE comments (
  id                    INT AUTO_INCREMENT,
  domain_id             INT NOT NULL,
  name                  VARCHAR(255) NOT NULL,
  type                  VARCHAR(10) NOT NULL,
  modified_at           INT NOT NULL,
  account               VARCHAR(40) NOT NULL,
  comment               VARCHAR(64000) NOT NULL,
  PRIMARY KEY (id)
) Engine=InnoDB;

CREATE INDEX comments_domain_id_idx ON comments (domain_id);
CREATE INDEX comments_name_type_idx ON comments (name, type);
CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);


CREATE TABLE domainmetadata (
  id                    INT AUTO_INCREMENT,
  domain_id             INT NOT NULL,
  kind                  VARCHAR(32),
  content               TEXT,
  PRIMARY KEY (id)
) Engine=InnoDB;

CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);


CREATE TABLE cryptokeys (
  id                    INT AUTO_INCREMENT,
  domain_id             INT NOT NULL,
  flags                 INT NOT NULL,
  active                BOOL,
  content               TEXT,
  PRIMARY KEY(id)
) Engine=InnoDB;

CREATE INDEX domainidindex ON cryptokeys(domain_id);


CREATE TABLE tsigkeys (
  id                    INT AUTO_INCREMENT,
  name                  VARCHAR(255),
  algorithm             VARCHAR(50),
  secret                VARCHAR(255),
  PRIMARY KEY (id)
) Engine=InnoDB;

CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);

flush privileges;

執行完之後,檢查下:
MariaDB [powerdns]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| powerdns           |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [powerdns]> use powerdns;
Database changed
MariaDB [powerdns]> show tables;
+--------------------+
| Tables_in_powerdns |
+--------------------+
| comments           |
| cryptokeys         |
| domainmetadata     |
| domains            |
| records            |
| supermasters       |
| tsigkeys           |
+--------------------+


檢查下使用powerdns是否正常登錄
[root@PowerDNS ~]# mysql -upowerdns -hlocalhost -ppowerdns;
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| powerdns           |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> use powerdns;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [powerdns]> show tables;
+--------------------+
| Tables_in_powerdns |
+--------------------+
| comments           |
| cryptokeys         |
| domainmetadata     |
| domains            |
| records            |
| supermasters       |
| tsigkeys           |
+--------------------+
7 rows in set (0.00 sec)

MariaDB [powerdns]>

6)繼續配置PowerDNS,以MariaDB作為後臺。

[root@PowerDNS ~]# cp /etc/pdns/pdns.conf /etc/pdns/pdns.conf.bak
[root@PowerDNS ~]# vim /etc/pdns/pdns.conf
#查找類似:#launch= ;添加下面的內容: 
launch=gmysql
gmysql-host=localhost
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql-password=powerdns

將啟動並添加PowerDNS到系統開機啟動列表:
[root@PowerDNS ~]# systemctl enable pdns.service
[root@PowerDNS ~]# systemctl start pdns.service
[root@PowerDNS ~]# systemctl status pdns.service

[root@PowerDNS ~]# ps -ef|grep pdns
pdns     20036     1  0 16:54 ?        00:00:00 /usr/sbin/pdns_server --daemon
root     20056 18838  0 16:56 pts/1    00:00:00 grep --color=auto pdns
[root@PowerDNS ~]# lsof -i:53
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
pdns_serv 20036 pdns    5u  IPv4  41118      0t0  UDP *:domain 
pdns_serv 20036 pdns    6u  IPv4  41119      0t0  TCP *:domain (LISTEN)


到這一步,PowerDNS服務器已經起起並運行了

二、安裝PowerAdmin來管理PowerDNS

7)PowerAdmin,一個界面友好的PowerDNS服務器的 Web 管理器。由於它是用PHP寫的,我們將需要安裝PHP和一臺網絡服務器(Apache):

[root@PowerDNS html]# yum -y install httpd php php-devel php-gd php-mcrypt php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mhash gettext
 
安裝完成後,需要啟動並設置Apache開機啟動:
[root@PowerDNS ~]# systemctl enable httpd.service
[root@PowerDNS ~]# systemctl start httpd.service
[root@PowerDNS ~]# systemctl status httpd.service
[root@PowerDNS ~]# lsof -i:80
 
由於已經滿足PowerAdmin的所有系統要求,可以繼續下載軟件包,放到Apache默認的網頁目錄位於/var/www/html/
[root@PowerDNS ~]# cd /var/www/html/
[root@PowerDNS html]#  wget http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz
[root@PowerDNS html]# tar -zvxf poweradmin-2.1.7.tgz
[root@PowerDNS html]# ls
poweradmin-2.1.7  poweradmin-2.1.7.tgz
 
接著啟動PowerAdmin的網頁安裝器了,只需打開(192.168.10.239為本機ip):
http://192.168.10.239/poweradmin-2.1.7/install/

下面的頁面會要求你為PowerAdmin選擇語言,請選擇你想要使用的那一個,然後點擊"進入步驟 2"按鈕。

技術分享圖片

安裝器需要PowerDNS數據庫:

技術分享圖片

因為上面已經創建了一個數據庫,所以可以繼續進入下一步。接著會被要求提供先前配置的數據庫詳情,同時也需要為Poweradmin設置管理員密碼:

技術分享圖片

輸入這些信息後,進入步驟 4。你將創建為Poweradmin創建一個受限用戶。這裏你需要輸入的字段是:

技術分享圖片

用戶名(Username):PowerAdmin用戶名。
密碼(Password):上述用戶的密碼。
主機管理員(Hostmaster):當創建SOA記錄而你沒有指定主機管理員時,該值會被用作默認值(可以不寫)。這裏我寫的是部署機的主機名
主域名服務器:該值在創建新的DNS區域時會被用於作為主域名服務器。
輔域名服務器:該值在創建新的DNS區域時會被用於作為輔域名服務器。

在下一步中,Poweradmin會要求你在數據庫表中創建一個新的受限數據庫用戶,它會提供你需要在MariaDB控制臺輸入的代碼:

技術分享圖片

現在打開終端並運行(以下這段命令就是復制上圖步驟中的命令,進入數據庫粘貼即可。)

MariaDB [(none)]> GRANT SELECT,INSERT,UPDATE,DELETE ON powerdns.* TO ‘poweradmin‘@‘localhost‘ IDENTIFIED BY ‘poweradmin‘;
MariaDB [(none)]> flush privileges;

測試使用上面權限登錄數據庫
[root@PowerDNS inc]# mysql -upoweradmin -hlocalhost -ppoweradmin
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| powerdns           |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]>

現在,回到瀏覽器中並繼續下一步

技術分享圖片

安裝器將嘗試創建配置文件到/var/www/html/poweradmin-2.1.7/inc目錄下,文件名是config.inc.php。

[root@PowerDNS ~]# cd /var/www/html/poweradmin-2.1.7/inc
[root@PowerDNS inc]# vim config.inc.php
[root@PowerDNS inc]# cat config.inc.php
<?php

$db_host    = ‘localhost‘;
$db_user    = ‘poweradmin‘;
$db_pass    = ‘poweradmin‘;
$db_name    = ‘powerdns‘;
$db_type    = ‘mysql‘;
$db_layer   = ‘PDO‘;

$session_key    = ‘6swx#944CycA9F2GkOAM7c&z6vU=ay[oGFnZZF{TC1te}7‘;

$iface_lang   = ‘en_EN‘;

$dns_hostmaster   = ‘PowerDNS-server‘;
$dns_ns1    = ‘172.16.51.151‘;
$dns_ns2    = ‘172.16.51.152‘;

現在,進入最後頁面,該頁面會告知你安裝已經完成以及如何訪問安裝好的PowerAdmin:

技術分享圖片

然後,需要移除從PowerAdmin的根目錄中移除"install"文件夾,這一點很重要。使用以下命令:

[root@PowerDNS ~]# ll /var/www/html/poweradmin-2.1.7/install/
[root@PowerDNS ~]# rm -rf /var/www/html/poweradmin-2.1.7/install/

在此之後,你可以通過以下方式訪問PowerAdmin,訪問地址http://192.168.10.239/poweradmin-2.1.7/

如下圖,使用admin/poweradmin@123的用戶名和密碼(上面設置的密碼)進行登錄

技術分享圖片

在登錄後,你應該會看到PowerAdmin的主頁:

技術分享圖片

Centos7.4下部署PowerDNS的操作記錄