编译安装
1、下载并安装Centos6 64位系统,记住不要最小化安装,最好安装带图形界面。内核2.6
2、系统安装好后,配置阿里云yum源,可连接外网。如果是内网自己去找yum源,这里简单介绍下配置阿里云yum源
直接给出命令
cd /etc/yum.repos.d
mkdir files
mv *repo* files
vim base.repo
[base]
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
保存退出VIM编辑器
执行yumclean all
执行yummakecache
执行yumrepolist all
注意;如果报错根据报错信息,逐个排错
典型的故障是yum安全锁,执行
rm -rf /var/run/yum.pid
3、安装开发包组
1 | # yum groupinstall "Development Tools"
|
4、bind源码包,请致3w.isc.org官网下载(我自己选择的编译版本是bind-9.10.1-P1.tar.gz)
5、下载(这里是内网下载的,上面isc地址,自己去下)及解压
1 2 | # wget -q ftp: //10.1.0.1/pub/Sources/sources/bind/bind-9.10.1-P1.tar.gz
# tar -xf bind- 9.10.1-P1 .tar.gz
|
6、检查并准备编译环境
1 2 3 4 5 6 7 8 9 10 11 | # cd bind-9.10.1-P1 # ./configure --prefix=/usr/local/bind9 --sysconfdir=/etc/named/ --enable-threads --enable-epoll --disable-chroot
# 程序安装路径 配置文件路径 开启多线程 多路复用IO 不使用chroot
checking for OpenSSL library... configure: error: OpenSSL was not found in any of /usr /usr/local /usr/local/ssl /usr/pkg /usr/sfw ; use --with-openssl= /path
If you don‘t want OpenSSL, use --without-openssl
# 缺少openssl 库,一般来讲编译环境缺少的都会是开发包,安装openssl开发包
# 注意;为避免重复报错,请执行以下openssl*的参数。全部安装关于openssl软件
# yum -y install openssl*
...
Complete! # openssl安装完成
# 重新检查编译环境
# ./configure --prefix=/usr/local/bind9 --sysconfdir=/etc/named/ --enable-threads --enable-epoll --disable-chroot
|
7、编译
8、安装
9、编辑配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # vim /etc/named/named.conf
# 写入下面的内容
options {
directory "/var/named" ;
pid- file "/usr/local/bind9/var/run/named.pid" ;
};
zone "." IN {
type hint;
file "named.ca" ;
};
zone "localhost" IN {
type master;
file "named.localhost" ;
allow-transfer { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback" ;
allow-transfer { none; };
};
|
10、编辑数据文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # mkdir /var/named
# dig -t NS . @114.114.114.114 > /var/named/named.ca
# 注意;这条命令的意思是;从DNS114域里去抓取13条根记录,抓取的内容并追加到named.ca文件内 # vim /var/named/named.localhost
# 写入下面内容
$TTL 86400
@ IN SOA localhost. admin.localhost. (
20160927
2H
10M
7D
1D
)
IN NS localhost.
localhost. IN A 127.0.0.1
# vim /var/named/named.loopback
# 写入下面的内容
$TTL 86400
@ IN SOA localhost. admin.localhost. (
20160927
2H
10M
7D
1D
)
IN NS localhost.
1 IN PTR localhost.
|
11、设置运行环境
1 2 3 4 | # groupadd -g 53 -r named
# useradd -g named -r named
# chown root:named /etc/named/named.conf /var/named/*
# chmod 640 /etc/named/named.conf /var/named/*
|
12、导出环境变量
1 2 3 4 5 6 7 8 9 10 11 12 13 | # PATH环境变量
# echo ‘export PATH=/usr/local/bind9/bin:/usr/local/bind9/sbin:$PATH‘ > /etc/profile.d/named.sh
# source /etc/profile.d/named.sh
# 创建头文件
# ln -sv /usr/local/bind9/include /usr/include/named
# 创建库文件
# vim /etc/ld.so.d/named.conf
/usr/local/bind9/lib64
# 创建并指定man帮助文档
# man -M /usr/local/bind9/share/man named
# 或者
# vim /etc/man.config
MANPATH /usr/local/bind9/share/man
|
13、试启动
1 2 3 4 5 6 | # named -u named
# 以named用户运行程序
# 查看监听端口
# ss -tnul
# 查看日志
# tail /var/log/messages
|
14、配置rndc(远程管理工具,很显然需要密钥)。
1 2 3 4 5 | # 生成密钥
# rndc-confgen -r /dev/urandom > /etc/named/rndc.conf
# 改变密钥文件属性
# chown root:named /etc/named/rndc.conf
# chmod 640 /etc/named/rndc.conf # 其他用户没有任何权限
|
15、打开rndc.conf按要求操作。
1 | # vim /etc/named/rndc.conf
|
16、重启服务,并测试rndc(本地测试)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # killall named
# named -u named
# rndc status
version: 9.9.5 < id :f9b8a50e>
CPUs found: 2
worker threads: 2
UDP listeners per interface: 2
number of zones: 100
debug level: 0
xfers running: 0
xfers deferred: 0
soa queries in progress: 0
query logging is OFF
recursive clients: 0 /0/1000
tcp clients: 0 /100
server is up and running
|
17、编辑服务配置脚本。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | # vim /etc/init.d/named
# 写入脚本
#!/bin/bash
# description: daemon named
# chkconfig: 345 20 50
#
pidFile= /usr/local/bind9/var/run/named .pid
lockFile= /var/lock/subsys/named
confFile= /etc/named/named .conf
[ -r /etc/rc .d /init .d /functions ] && . /etc/rc .d /init .d /functions
start() {
if [ -e $lockFile ]; then
echo "named is already running..."
else
echo -n "Starting named:"
daemon --pidfile "$pidFile" /usr/local/bind9/sbin/named -u named -c "$confFile"
RETVAL=$?
if [ $RETVAL - eq 0 ]; then
touch $lockFile
success
else
rm -f $lockFile $pidFile
failure
fi
echo
fi
}
stop() {
if [ ! -e $lockFile ]; then
echo "named is stopped."
else
echo -n "Stopping named:"
killproc named
RETVAL=$?
if [ $RETVAL - eq 0 ]; then
rm -f $lockFile $pidFile
success
else
echo "Cannot stop named."
failure
fi
echo
fi
}
restart() {
stop
sleep 2
start
}
reload() {
echo -n "Reloading named: "
killproc named -HUP
echo
}
status() {
if pidof named &> /dev/null ; then
echo -n "named is running..."
else
echo -n "named is stopped..."
fi
echo
}
usage() {
echo "Usage: named {start|stop|restart|status|reload}"
}
case $1 in
start)
start ;;
stop)
stop ;;
restart)
restart ;;
status)
status ;;
reload)
reload ;;
*)
usage
;;
esac
|
18、将脚本添加到服务中去并启动。
1 2 3 4 5 6 7 | # chmod +x /etc/init.d/named # 给脚本增加执行权限
# chkconfig --add /etc/init.d/named
# chkconfig --list named
named 0:off 1:off 2:off 3:on 4:on 5:on 6:off
# service named start
Starting named: [ OK ]
# ss -tnul | grep ":53"
|
19、压力测试
在编译安装BIND的时候,安装程序中有个文件叫查询性能的,是第三方提供的性能测试工具。这个程序包一般是不会安装。也是需要手动去编译,我们切换去queryperf目录下、直接编译:
cd/testdir/bind-9.10.1-P1/contrib
# ./configure
# make
完成、生成一个叫queryperf、直接cp到/usr/bin下:
# cp queryperf /usr/bin
# cp /usr/bin/ queryperf
接下来我们去创建一个查询的域名的测试文件,在root的家目录下创建一个query.txt文件;
用vim创建query.txt文件并填入以下内容
www.magedu.com A
magedu.com NS
magedu.com MX
pop3.magedu.com A
web.magedu.com A
添加这些内容、然后复制N次保存退出、再测试一下你的DNS服务器每秒可以执行的查询次数是多少次、用时多少、看一下我的query.txt文件中有多少条:
# wc -l query.txt
要是你觉得不够多再加,加到你满意为止,最少几十万行。才能测试出效果。那我们就来测试一下吧。
# queryperf -d query.txt -s 127.0.0.1
测试时你可以用htop看一下cpu占用率:
# htop
20、打开日志功能
rndc querylog
rndc status
queryperf -d test.txt -s 127.0.0.1
wc -l /var/log/message
故障排错于一九四三,BIND测试自此结束!!!
21、附上需要手动创建的文件,如有遗漏后续补上(等Centos7测试完毕后,来更新此文档。)
编译安装bind需要手动创建的文件
vim/etc/named/named.conf
mkdir/var/named
vim/var/named/named.ca
vim/var/named/named.localhost
vim/var/named/named.loopback
创建组groupadd -g 53 -r named
创建用户useradd -g named -r named
vim/etc/named/rndc.conf
vim/etc/init.d/named
环境变量自己创建,创建头文件,创建库文件此,创建man帮助文档
本文出自 “51eA” 博客,请务必保留此出处http://51eat.blog.51cto.com/11892702/1857535
Centos6编译安装bind文件,注意事项