PowerDNS
一种 DNS 服务器, 优点, 支持 PHP 网页管理, 支持直接在数据库中添加 DNS 地址记录, 比较灵活, 方便
参见信息
主机名 | PDNS 中记录的主机名 | 本机 ip 地址 | 浮动 IP 地址 | 操作系统版本 | 备注 1 | 备注2 |
---|---|---|---|---|---|---|
gd02-qa-plxt2-nodomain.ddns.vclound.com | pdnsweb.vclound.com | 10.0.3.105 | 192.168.86.172 | centOS 5.8 | 网页服务器(nginx, php) | NULL |
gd02-qa-plx2-ddns-web-99.vclound.com | pdnsdb.vclound.com | 10.0.3.99 | null | centOS 6.5 | pdns 服务器+mysql5.5 | NULL |
下载 ddns 软件包
http://downloads.powerdns.com/releases/pdns-3.3.1.tar.gz
下载网页管理页面
wget https://github.com/downloads/poweradmin/poweradmin/poweradmin-2.1.6.tgz
解压至 /apps/dat/web 目录下
[root@gd02-qa-plxt2-nodomain web]# cd /apps/dat/web
[root@gd02-qa-plxt2-nodomain web]# tar xf poweradmin-2.1.6.tgz
[root@gd02-qa-plxt2-nodomain web]# mv poweradmin-2.1.6 pdns
注明: 当前编译方法只适合于我的生产环境, 各位可参考并进行自行调整
参见 下面 ddns-3.3.1.spec 文件, 该 rpm 包整合了 pdns (程序) 与 poweradmin (网页管理) 的自动安装
程序名称 | 安装路径 | 作用 |
---|---|---|
poweradmin | /apps/dat/web/pdns/ | 网页管理 |
pdns | /apps/sh/pdns | 启动进程 |
NULL | /apps/conf/pdns/pdns.sql | 数据库自动添加表脚本 |
NULL | /apps/conf/pdns/pdns.conf | 配置文件 |
pdns_server | /apps/lib/pdns-3.3.1/sbin/pdns_server | 服务端程序 |
ddns-3.3.1.spec 文件
Name: pdns
Version: 3.3.1
Release: 20140129.vipclound.centos65
Summary: use for monitor openstack VM.
Group: Applications/System
License: GPL
URL: http://downloads.powerdns.com/releases/pdns-3.3.1.tar.gz
Source0: pdns-3.3.1.tar.bz2
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
#BuildRequires:
#Requires:
%define _prefix /apps/svr/pdns-3.3.1
%define _exec-prefix /apps/svr/pdns-3.3.1
%define _bindir /apps/svr/pdns-3.3.1/bin
%define _sbindir /apps/svr/pdns-3.3.1/sbin
%define _sysconfdir /apps/lib/pdns-3.3.1
%define _includedir /apps/lib/pdns-3.3.1
%define _libexecdir /apps/lib/pdns-3.3.1
%define _infodir /apps/lib/pdns-3.3.1
%define _oldincludedir /apps/lib/pdns-3.3.1
%define _libdir /apps/lib/pdns-3.3.1
%define _defaultdocdir /apps/lib/pdns-3.3.1
%define _docdir /apps/lib/pdns-3.3.1
%define _mandir /apps/lib/pdns-3.3.1
%define _datadir /apps/lib/pdns-3.3.1
%define _sharedstatedir /apps/lib/pdns-3.3.1
%define _localstatedir /apps/lib/pdns-3.3.1
%define _datarootdir /apps/lib/pdns-3.3.1
%define _infodir /apps/lib/pdns-3.3.1
%define _localedir /apps/lib/pdns-3.3.1
%define _htmldir /apps/lib/pdns-3.3.1
%define _dvidir /apps/lib/pdns-3.3.1
%define _pdfdir /apps/lib/pdns-3.3.1
%define _psdir /apps/lib/pdns-3.3.1
%description
use for dns server.
%prep
%setup -q
%build
%configure --enable-pdns_server --enable-tools --with-lua --with-boost=/usr --enable-pdns_server --enable-tools --with-dynmodules="gmysql" --with-mysql=/apps/svr/mysql
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
make %{?_smp_mflags}
%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
mkdir %{buildroot}/apps/dat/web/pdns -p
mkdir %{buildroot}/apps/sh -p
mkdir %{buildroot}/apps/conf/pdns -p
mkdir %{buildroot}/apps/run/zabbix -p
cp -rp $RPM_BUILD_DIR/pdns-3.3.1/padmin/* %{buildroot}/apps/dat/web/pdns/.
cp -rp $RPM_BUILD_DIR/pdns-3.3.1/conf/pdns.conf %{buildroot}/apps/conf/pdns/pdns.conf
cp -rp $RPM_BUILD_DIR/pdns-3.3.1/sh/pdns %{buildroot}/apps/sh/pdns
cp -rp $RPM_BUILD_DIR/pdns-3.3.1/conf/pdns.sql %{buildroot}/apps/conf/pdns/pdns.sql
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%doc
%config /apps/dat/web/pdns/*
%config /apps/conf/pdns/pdns.conf
%config /apps/sh/pdns
%config /apps/conf/pdns/pdns.sql
%{_libdir}/*
%{_mandir}/man8/*
%{_bindir}/*
%{_sbindir}/*
%changelog
* Wed Jan 29 2014 terrytsang
-- use for vipclound.com ddns service
注:
lnmp 架构编译(忽略描述)
所有的软件, 库文件都安装到 /apps 与 /apps/lib 目录中
当前使用 mysql-5.5 版本
1. 安装依赖包
yum install -y lua-devel.x86_64 boost-devel
2. rpm 方法安装 pdns (注意使用 --nodeps 参数)
[root@gd02-qa-plx2-ddns-web-99 ~]# rpm -ivh --nodeps pdns-3.3.1-20140128.vipclound.centos65.x86_64.rpm
Preparing... ########################################### [100%]
1:pdns ########################################### [100%]
3. 参见下面编译时的 $SOURCE/sh/pdns 文件
#!/bin/sh
# chkconfig: - 80 75
# description: PDNS is a versatile high performance authoritative nameserver
### BEGIN INIT INFO
# Provides: pdns
# Required-Start: $remote_fs $network $syslog
# Required-Stop: $remote_fs $network $syslog
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: PowerDNS authoritative server
# Description: PowerDNS authoritative server
### END INIT INFO
set -e
configdir=/apps/conf/pdns
prefix=/apps/svr/pdns-3.3.1
exec_prefix=${prefix}
BINARYPATH=${exec_prefix}/bin
SBINARYPATH=${exec_prefix}/sbin
SOCKETPATH=/apps/run/pdns/
[ -f "$SBINARYPATH/pdns_server" ] || exit 0
[ -r /etc/default/pdns ] && . /etc/default/pdns
cd $SOCKETPATH
suffix=$(basename $0 | cut -d- -f2- -s)
if [ -n "$suffix" ]
then
EXTRAOPTS=--config-name=$suffix
PROGNAME=pdns-$suffix
else
PROGNAME=pdns
fi
pdns_server="$SBINARYPATH/pdns_server $EXTRAOPTS"
doPC()
{
ret=$($BINARYPATH/pdns_control $EXTRAOPTS $1 $2 2> /dev/null)
}
NOTRUNNING=0
doPC ping || NOTRUNNING=$?
case "$1" in
status)
if test "$NOTRUNNING" = "0"
then
doPC status
echo $ret
else
echo "not running"
exit 3
fi
;;
stop)
echo -n "Stopping PowerDNS authoritative nameserver: "
if test "$NOTRUNNING" = "0"
then
doPC quit
echo $ret
else
echo "not running"
fi
;;
force-stop)
echo -n "Stopping PowerDNS authoritative nameserver: "
killall -v -9 pdns_server
echo "killed"
;;
start)
echo -n "Starting PowerDNS authoritative nameserver: "
if test "$NOTRUNNING" = "0"
then
echo "already running"
else
if $pdns_server --daemon --guardian=yes --config-dir=$configdir
then
echo "started"
else
echo "starting failed"
exit 1
fi
fi
;;
force-reload | restart)
echo -n "Restarting PowerDNS authoritative nameserver: "
if test "$NOTRUNNING" = "1"
then
echo "not running, starting"
else
echo -n stopping and waiting..
doPC quit
sleep 3
echo done
fi
$0 start
;;
reload)
echo -n "Reloading PowerDNS authoritative nameserver: "
if test "$NOTRUNNING" = "0"
then
doPC cycle
echo requested reload
else
echo not running yet
$0 start
fi
;;
monitor)
if test "$NOTRUNNING" = "0"
then
echo "already running"
else
$pdns_server --daemon=no --guardian=no --control-console --loglevel=9
fi
;;
dump)
if test "$NOTRUNNING" = "0"
then
doPC list
echo $ret
else
echo "not running"
fi
;;
show)
if [ $# -lt 2 ]
then
echo Insufficient parameters
exit
fi
if test "$NOTRUNNING" = "0"
then
echo -n "$2="
doPC show $2 ; echo $ret
else
echo "not running"
fi
;;
mrtg)
if [ $# -lt 2 ]
then
echo Insufficient parameters
exit
fi
if test "$NOTRUNNING" = "0"
then
doPC show $2 ; echo $ret
if [ "$3x" != "x" ]
then
doPC show $3 ; echo $ret
else
echo 0
fi
doPC uptime ; echo $ret
echo PowerDNS daemon
else
echo "not running"
fi
;;
cricket)
if [ $# -lt 2 ]
then
echo Insufficient parameters
exit
fi
if test "$NOTRUNNING" = "0"
then
doPC show $2 ; echo $ret
else
echo "not running"
fi
;;
*)
echo pdns [start\|stop\|force-reload\|reload\|restart\|status\|dump\|show\|mrtg\|cricket\|monitor]
;;
esac
文件已修复之前上一版本不可以正常启动 PDNS 问题
安装后启动方法
/apps/sh/pdns start
关闭
/apps/sh/pdns stop
4. 确保系统中使用到 mysqlclient.18.0 库文件, 数据库授权并导入 sql 脚本
*授权 pdns 用户能够访问 pdns 数据库
mysql> create database pdns;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on pdns.* to 'pdns'@'localhost' identified by 'pdns';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on pdns.* to 'pdns'@'127.0.0.1' identified by 'pdns';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on pdns.* to 'pdns'@'0.0.0.0' identified by 'pdns';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
2. 确保系统中使用到 mysqlclient.18.0 库文件, 数据库授权并导入 sql 脚本
*授权 pdns 用户能够访问 pdns 数据库
mysql> create database pdns;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on pdns.* to 'pdns'@'localhost' identified by 'pdns';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on pdns.* to 'pdns'@'127.0.0.1' identified by 'pdns';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on pdns.* to 'pdns'@'0.0.0.0' identified by 'pdns';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
导入 pdns 所需要的 sql
[root@station140 mysql5]# /apps/svr/mysql5/bin/mysql -u pdns -ppdns pdns < /apps/conf/pdns/pdns.sql
5. 配置 pdns 服务器
/apps/conf/pdns/pdns.conf
daemon=yes
recursor=192.168.86.37
launch=gmysql
gmysql-host=127.0.0.1
gmysql-user=pdns
gmysql-dbname=pdns
gmysql-password=pdns
6. 启动 pdns 服务器
/apps/sh/pdns start
7. 测试方法
a. 检测端口 53/tcp 是否使用中
b. 检测防火墙关闭, selinux 关闭
c. /etc/resolv.conf 是否指向自己
d. nslookup localhost 是否能够返回 127.0.0.1
8. nginx 启动配置忽略, 但需要吧 webroot 指向 /app/dat/web 下
9. 配置 php
只修改下面 /apps/conf/php5/php.ini 两部分
session.save_path = "/tmp/session"
date.timezone Asia/Chongqing
执行命令
mkdir /tmp/session
chown apps:apps /tmp/session
10. 启动 nginx, (启动 php 略)
[root@gd02-qa-plxt2-nodomain /]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 3105 root 7u IPv4 42727 0t0 TCP *:http (LISTEN)
nginx 3106 apps 7u IPv4 42727 0t0 TCP *:http (LISTEN)
可通过界面方法进行配置管理
安装完成后可看见这个管理页面
添加主域
添加主机记录方法
调用 ADD RECORD 按钮可以添加多个域名
完成数据添加后可马上调用 nslookup 进行验证. 非常方便