其实一般使用redhat或centos中自带的rpm安装bind是十分简单的,但是源码安装可以让你对bind文件的整体结构有了更好的认识

先下载一个源码包:https://www.isc.org/downloads/bind/

DNS部署(3)---------源码bind安装_dns bind源码

直接下载即可。

DNS部署(3)---------源码bind安装_dns bind源码_02DNS部署(3)---------源码bind安装_dns bind源码_03

进入目录后就可以编译了,对于编译的模块就不细说了直接查询即可。

DNS部署(3)---------源码bind安装_dns bind源码_04

但是有几个模块是必须要装的gccopensslperl的相关组件,如果不想安装必须用--without把模块排除在外,下面开始编译:

DNS部署(3)---------源码bind安装_dns bind源码_05

DNS部署(3)---------源码bind安装_dns bind源码_06

直接安装即可

DNS部署(3)---------源码bind安装_dns bind源码_07

安装好后,就得到了这俩个文件夹

DNS部署(3)---------源码bind安装_dns bind源码_08


下面就开始写named的各种配置文件,相对于rpm包,源码包装出来什么都没有。。。

首先要创建一个named系统用户

DNS部署(3)---------源码bind安装_dns bind源码_09

完成脚本的链接:

DNS部署(3)---------源码bind安装_dns bind源码_10

写入后要记得用 ---------------source加载

1、在/etc/named/中创建named.conf文件

DNS部署(3)---------源码bind安装_dns bind源码_11

DNS部署(3)---------源码bind安装_dns bind源码_12

DNS部署(3)---------源码bind安装_dns bind源码_13

DNS部署(3)---------源码bind安装_dns bind源码_14

 

在配置文件的目录中就会有这么几个文件,修改它们权限为named!!!!

DNS部署(3)---------源码bind安装_dns bind源码_15

配置文件大致上就设置好了,下面就要根据named.conf中指定写zone文件了


DNS部署(3)---------源码bind安装_dns bind源码_16

DNS部署(3)---------源码bind安装_dns bind源码_17

 

一个个开始编写吧

DNS部署(3)---------源码bind安装_dns bind源码_18

 

在编写localhost.zone和named.local文件

DNS部署(3)---------源码bind安装_dns bind源码_19


开始服务即可

DNS部署(3)---------源码bind安装_dns bind源码_20

DNS部署(3)---------源码bind安装_dns bind源码_21


这样就算是安装完成了,当然还可以写一个启动脚本放到/etc/init.d/下面,就完美了

 

#/bin/bash
#chkconfig 2345 70 50
#description named
#author joe
[ -r /etc/init.d/functions ] && . /etc/init.d/functions
//判断functions库函数是否可读
Pidfile="/usr/local/bind9/var/run/named.pid"//默认pid路路径
Lockfile="/var/lock/subsys/named"//脚本锁文件
named="named"//服务
start() {
[ -x "/usr/local/bind9/sbin/$named" ] || exit 4
if [ -f $Lockfile ];then
echo  "the $named is already running"
exit 5
fi
echo -n "starting $named "
daemon --pidfile "$Pidfile"  /usr/local/bind9/sbin/$named -u named -4
RETAVL=$?
echo
if [ $RETAVL -eq 0 ];then
touch $Lockfile
return 0
else
rm -f $Lockfile $Pidfile
return 1
fi
}
stop(){
if [ ! -f $Lockfile ];then
echo "the $named is stopped.... "
exit 5
fi
echo -n "stopping the $named.."
killproc $named
RETAVL=$?
echo
if [ $RETAVL -eq 0 ];then
rm -f $Lockfile
fi
}
reload(){
if [ ! -f $Lockfile ];then
echo "the $named is stopped "
exit 5
fi
echo -n "reload the config file"
killproc $named -HUP
RETAVL=$?
echo
}
status(){
if pidof $named &>/dev/null && [ -f $Pidfile ];then
echo "the $named is starting"
else
echo "the $named is stopped"
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
sleep 1
start
;;
status)
status
;;
*)
echo "Usage:||"
;;
esac