基于LAMP 搭建PowerDNS
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于LAMP 搭建PowerDNS相关的知识,希望对你有一定的参考价值。
PowerDNS 是一个跨平台的开源DNS服务组件,它是高性能的域名服务器,除了支持普通的BIND配置文件,PowerDNS还可以从mysql,Oracle,PostgreSQL等的数据库读取数据。PowerDNS安装了Poweradmin(基于php实现),能实现Web管理DNS记录,非常方便。
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
name=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‘;
https://doc.powerdns.com/md/authoritative/backend-generic-mysql/
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,
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);
#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上测试:
[[email protected] 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的主要内容,如果未能解决你的问题,请参考以下文章