DNS服务作为生产环境的中必备的两个服务之一,是必须要部署的。在centos的base仓库中带有的bind可以做到简单的DNS服务的实现。但是PowerDns提供了一个非常通俗易懂的web界面,即使是没有部署过的小白用户也能够轻易上手。PowerDNS 是一个跨平台的开源DNS服务组件,它是高性能的域名服务器,除了支持普通的BIND配置文件,PowerDNS还可以从MySQL,Oracle,PostgreSQL等的数据库读取数据等。
部署环境准备
关闭selinux和防火墙
[[email protected] ~]#setenforce 0
[[email protected] ~]#systemctl stop firewalld
[[email protected] ~]#systemctl disable firewalld
配置yum源
[[email protected] ~]#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[[email protected] ~]#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] ~]#yum install -y epel-release
部署Mariadb数据库存储PowerDNS的后端数据
安装mariadb服务
[[email protected] ~]#yum install -y mariadb-server
修改配置文件
[[email protected] ~]#vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
#更改字符集和禁止主机名解析
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
skip_name_resolve=on
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
启动服务
[[email protected] ~]#systemctl enable mariadb.service
[[email protected] ~]#systemctl start mariadb.service
查看字符集是否修改成功
[[email protected] ~]#mysql
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 |
+----------------------+-----------------+
创建powerdns数据库
MariaDB [(none)]> CREATE DATABASE powerdns;
MariaDB [(none)]> GRANT ALL ON powerdns.* TO ‘powerdns‘@‘localhost‘ IDENTIFIED BY ‘centos‘;
MariaDB [(none)]> FLUSH PRIVILEGES;
创建必要的数据库表
#以下全部复制至数据库命令行中即可
MariaDB [(none)]>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 tables;
+--------------------+
| Tables_in_powerdns |
+--------------------+
| comments |
| cryptokeys |
| domainmetadata |
| domains |
| records |
| supermasters |
| tsigkeys |
+--------------------+
检查下使用powerdns是否正常登录
[[email protected] ~]#mysql -upowerdns -hlocalhost -pcentos;
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)
安装并配置PowerDNS
安装PowerDNS
[[email protected] ~]#yum install -y pdns pdns-backend-mysql
更改配置文件
[[email protected] ~]#vim /etc/pdns/pdns.conf
launch=gmysql
gmysql-host=localhost
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql-password=centos
启动服务
[[email protected] ~]#systemctl enable pdns.service
[[email protected] ~]#systemctl start pdns.service
安装PowerAdmin来管理PowerDNS
安装必要的软件包
[[email protected] ~]#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
启动http服务
[[email protected] ~]#systemctl start httpd.service
[[email protected] ~]#systemctl enable httpd.service
下载poweradmin放置到http的工作目录中
[[email protected] ~]#cd /var/www/html/
[[email protected] ~]#wget http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz
[[email protected] ~]#tar xf poweradmin-2.1.7.tgz
[[email protected] html]#mv poweradmin-2.1.7 dns
安装poweradmin,访问网页http://192.168.8.134/dns/install/
把上面的文件写入到文件中
[[email protected] html]#vim dns/inc/config.inc.php
<?php
$db_host = ‘localhost‘;
$db_user = ‘poweradmin‘;
$db_pass = ‘poweradmin‘;
$db_name = ‘powerdns‘;
$db_type = ‘mysql‘;
$db_layer = ‘PDO‘;
$session_key = ‘[email protected]~!&IN8i58qlp2B(bEMTxZ3DmdHJYIqOref%C&[email protected]$yh‘;
$iface_lang = ‘en_EN‘;
$dns_hostmaster = ‘‘;
$dns_ns1 = ‘192.168.8.134‘;
$dns_ns2 = ‘192.168.8.134‘;
删除安装目录
[[email protected] html]#rm dns/install/* -rf
登录界面
账号admin,密码为上面设置的密码123456
原文地址:https://blog.51cto.com/14163901/2419815
时间: 2024-10-03 18:35:02