基於LAMP 搭建PowerDNS
PowerDNS官網:https://www.powerdns.com/
PowerDNS文檔:https://doc.powerdns.com/
Poweradmin官網:http://www.poweradmin.org/
準備一臺主機centOS 7.5 (192.168.21.104)
配 EPEL 源
#vim epel.repo
baseurl=http://mirror.sohu.com/fedora-epel/7/x86_64/
gpgcheck=0
enabled=1
安裝包:基於EPEL源
#yum -y install pdns pdns-backend-mysql
#rpm -q mariadb-server
#systemctl start mariadb
#systemctl enable mariadb
#mysql
利用下面兩條sql語句和鏈接創建pdsql.sql的腳本:準備mariadb中的數據庫,表和用戶
create database powerdns;
grant all on powerdns.* to ‘powerdns‘@‘localhost‘ identified by ‘magedu‘;
vim pdsql.sql //創建pdsql.sql, 添加下面內容
create database powerdns;
grant all on powerdns.* to ‘powerdns‘@‘localhost‘ identified by ‘magedu‘;
use powerdns
CREATE TABLE domains (
id INT AUTO_INCREMENT,
name VARCHAR(255) NOT 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);
#mysql < pdns.sql
配置PowerDNS使用mariadb作為後臺數據存儲
#vim /etc/pdns/pdns.conf //查找到包含launch= 的行,修改並添加下面的內容
launch=bind //刪除此行
launch=gmysql
gmysql-host=localhost
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql-password=magedu
啟動pdns服務前,確保53端口未被占用
#ss -ntl
#lsof -i:53 //顯示所有打開53端口的進程
#kill -9 1382
#systemctl start pdns
#systemctl enable pdns
安裝httpd和php相關包
#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-mhash gettext
#systemctl start httpd
#systemctl enable httpd
#cd /var/www/html
#wget http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz
#tar xvf poweradmin-2.1.7.tgz
#mv poweradmin-2.1.7 pdns
瀏覽器輸入下面地址,按提示進一步配置:
http://192.168.21.104/pdns/install/
操作進行到第5步:
登陸mariadb,執行以下語句:
MariaDB [powerdns]> GRANT SELECT, INSERT, UPDATE, DELETE
-> ON powerdns.*
-> TO ‘powerdnsadmin‘@‘localhost‘
-> IDENTIFIED BY ‘centos‘;
Query OK, 0 rows affected (0.00 sec)
操作進行到第6步:
#cd /var/www/html/pdns
#vim inc/config.inc.php
<?php
$db_host = ‘localhost‘;
$db_user = ‘powerdnsadmin‘;
$db_pass = ‘centos‘;
$db_name = ‘powerdns‘;
$db_type = ‘mysql‘;
$db_layer = ‘PDO‘;
$session_key = ‘lPubca)P32J)*9b5JTX0MiqE^erq948PI[0[Zt=0%x)Oc0‘;
$iface_lang = ‘en_EN‘;
$dns_hostmaster = ‘powerdnsserver‘;
$dns_ns1 = ‘192.168.21.104‘;
$dns_ns2 = ‘‘;
操作進行到第7步,配置完成:
#rm -rf /var/www/html/pdns/install/
登陸powerdns:
http://192.168.21.104/pdns/
添加域:b.com
給b.com這個域添加一條記錄: www.b.com 8.8.8.8
在DNSserver上測試:
[root@centos7 pdns]#dig www.b.com @192.168.21.104
; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> www.b.com @192.168.21.104
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12657
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1680
;; QUESTION SECTION:
;www.b.com. IN A
;; ANSWER SECTION:
www.b.com. 86400 IN A 8.8.8.8
;; Query time: 2 msec
;; SERVER: 192.168.21.104#53(192.168.21.104)
;; WHEN: Tue Mar 05 15:19:35 CST 2019
;; MSG SIZE rcvd: 54
基於LAMP 搭建PowerDNS