首页 > 代码库 > 编译安装bind9

编译安装bind9

编译安装named:
前提:配置好开发环境,安装包组
1、下载源代码,编译安装
# tar xf bind-9.9.5.tar.gz
# cd bind-9.9.5
# ./configure --prefix=/usr/local/bind9 --sysconfdir=/etc/named/ --enable-threads --enable-epoll --disable-chroot
# make && make install

2、创建主配置文件
# 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; };
};

3、创建区域数据文件

3.1 named.ca
# dig -t NS . @172.16.0.1 > /var/named/named.ca

3.2 named.localhost
$TTL 86400
@ IN SOA localhost. admin.localhost. (
2014031101
2H
10M
7D
1D )
IN NS localhost.
localhost. IN A 127.0.0.1

3.3 named.loopback
$TTL 86400
@ IN SOA localhost. admin.localhost. (
2014031101
2H
10M
7D
1D )
IN NS localhost.
1 IN PTR localhost.

4、创建用户,并测试启动
# groupadd -g 53 -r named
# useradd -g named -r named
# chown root:named /etc/named/* /var/named/*
# chmod 640 /etc/named/named.conf /var/named/*

# echo ‘export PATH=/usr/local/bind9/bin:/usr/local/bind9/sbin:$PATH‘ > /etc/profile.d/named.sh
# source /etc/profile.d/named.sh

测试启动:
# named -u named

5、rndc
# rndc-confgen -r /dev/urandom > /etc/named/rndc.conf
# chown root:named /etc/named/rndc.conf
# chmod 640 /etc/named/rndc.conf

把rndc.conf文件的后半部分复制到named.conf中并按指示启用;

6、提供服务脚本
#!/bin/bash
#
# description: named daemon
# chkconfig: - 25 80
#
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..."
exit 0
fi

echo -n "Starting named:"
daemon --pidfile "$pidFile" /usr/local/bind9/sbin/named -u named -c "$confFile"
RETVAL=$?
echo

if [ $RETVAL -eq 0 ]; then
touch $lockFile
return $RETVAL
else
rm -f $lockFile $pidFile
return 1
fi
}

stop() {
if [ ! -e $lockFile ]; then
echo "named is stopped."
# exit 0
fi

echo -n "Stopping named:"
killproc named
RETVAL=$?
echo

if [ $RETVAL -eq 0 ];then
rm -f $lockFile $pidFile
return 0
else
echo "Cannot stop named."
failure
return 1
fi
}

restart() {
stop
sleep 2
start
}

reload() {
echo -n "Reloading named: "
killproc named -HUP
#killall -HUP named
RETVAL=$?
echo
return $RETVAL
}

status() {
if pidof named &> /dev/null; then
echo -n "named is running..."
success
echo
else
echo -n "named is stopped..."
success
echo
fi
}

usage() {
echo "Usage: named {start|stop|restart|status|reload}"
}

case $1 in
start)
start ;;
stop)
stop ;;
restart)
restart ;;
status)
status ;;
reload)
reload ;;
*)
usage
exit 4
;;
esac

7、性能测试
benchmark, tcpcopy

queryperf, dnstop

编译安装bind9