编译安装bind练习
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编译安装bind练习相关的知识,希望对你有一定的参考价值。
启动前检查环境: 网络、root用户、是否存在配置,rndc.conf,/var/named目录,及权限配置
服务脚本
#!/bin/bash ##编译方法: ./configure --prefix=/usr/local/bind9 --sysconfdir=/etc/named --disable-ipv6 --disable-chroot --enable-threads # chkconfig: - 13 87 # description # . /etc/init.d/functions check_env() { echo -n "Sysinit:" #root用户 [ $UID -eq 0 ] || exit 4 #网络打开 [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network [ "${NETWORKING}" == "no" ] && exit 1 #初始化 if [ ! -e /etc/named/named.conf ]; then cat > /etc/named/named.conf << EOF options { directory "/var/named"; allow-query { any; }; recursion yes; }; zone "." IN { type hint; file "named.ca"; }; zone "localhost" IN { type master; file "named.localhost"; allow-update { none; }; }; zone "0.0.127.in-addr.arpa" IN { type master; file "named.loopback"; allow-update { none; }; }; EOF [ -d /var/named ] || install -d /var/named [ -e /var/named/named.ca ] || cat > /var/named/named.ca << EOF ; <<>> DiG 9.10.6 <<>> -t NS . ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52658 ;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 13 ;; QUESTION SECTION: ;. IN NS ;; ANSWER SECTION: . 5 IN NS c.root-servers.net. . 5 IN NS i.root-servers.net. . 5 IN NS d.root-servers.net. . 5 IN NS f.root-servers.net. . 5 IN NS b.root-servers.net. . 5 IN NS e.root-servers.net. . 5 IN NS k.root-servers.net. . 5 IN NS a.root-servers.net. . 5 IN NS m.root-servers.net. . 5 IN NS h.root-servers.net. . 5 IN NS l.root-servers.net. . 5 IN NS j.root-servers.net. . 5 IN NS g.root-servers.net. ;; ADDITIONAL SECTION: m.root-servers.net. 5 IN A 202.12.27.33 m.root-servers.net. 5 IN AAAA 2001:dc3::35 f.root-servers.net. 5 IN A 192.5.5.241 f.root-servers.net. 5 IN AAAA 2001:500:2f::f b.root-servers.net. 5 IN A 192.228.79.201 b.root-servers.net. 5 IN AAAA 2001:500:200::b j.root-servers.net. 5 IN A 192.58.128.30 j.root-servers.net. 5 IN AAAA 2001:503:c27::2:30 c.root-servers.net. 5 IN A 192.33.4.12 c.root-servers.net. 5 IN AAAA 2001:500:2::c a.root-servers.net. 5 IN A 198.41.0.4 a.root-servers.net. 5 IN AAAA 2001:503:ba3e::2:30 e.root-servers.net. 5 IN A 192.203.230.10 ;; Query time: 6 msec ;; SERVER: 192.168.206.2#53(192.168.206.2) ;; WHEN: Sat Sep 23 13:15:05 CST 2017 ;; MSG SIZE rcvd: 508 EOF [ -e /var/named/named.localhost ] || cat > /var/named/named.localhost <<EOF $TTL 1D $ORIGIN localhost. @ IN SOA @ lccnx.foxmail.com. ( 20170923 1H 10M 1W 1D ) IN NS localhost. IN A 127.0.0.1 EOF [ -e /var/named/named.loopback ] || cat > /var/named/named.loopback <<EOF $TTL 1D $ORIGIN 0.0.127.in-addr.arpa. @ IN SOA @ lccnx.foxmail.com. ( 20170923 1H 10M 1W 1D) IN NS localhost. 1 IN PTR localhost. EOF fi #/etc/named/rndc.conf存在 if [ ! -e /etc/named/rndc.conf ]; then /usr/local/bind9/sbin/rndc-confgen -r /dev/urandom > /etc/named/rndc.conf tail /etc/named/rndc.conf | sed -n ‘$!p‘ | sed ‘[email protected]^#[[:space:]]@@‘ >> /etc/named/named.conf fi chown root.named /etc/named/{named.conf,rndc.conf} /var/named/* chmod 640 /etc/named/{named.conf,rndc.conf} /var/named/* success echo } ##检查环境 check_env prog=$(echo $0 | tr -s ‘/‘ | sed ‘s,/$,,‘ | sed -r ‘[email protected](^.*/)([^/]+$)@\[email protected]‘) lockfile="/var/lock/subsys/$prog" ##需要修改 start() { echo -n "starting $prog:" if [ -e $lockfile ]; then success echo else /usr/local/bind9/sbin/named -u named touch $lockfile success echo fi } stop() { echo -n "stopping $prog:" rm -rf $lockfile if killall -0 named &> /dev/null; then /usr/local/bind9/sbin/rndc stop &> /dev/null success echo else failure echo fi } reload() { echo -n "reloading $prog:" if [ -e $lockfile ]; then /usr/local/bind9/sbin/rndc reload &> /dev/null || kill -SIGHUP named success echo fi } restart() { stop start } status() { [ -x /usr/local/bind9/sbin/rndc ] && /usr/local/bind9/sbin/rndc status } case $1 in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status ;; condrestart|try-restart) if [ -e /var/lock/subsys/named ]; then restart; fi ;; *) echo "Usage: $prog [start|stop|restart|reload|status|condrestart|try-restart]" esac
安装脚本
#!/bin/bash # # isc.org # # named(BIND) # . /etc/init.d/functions a=0 scriptFile=‘/tmp/named‘ dir=‘/tmp‘ package=‘bind-9.10.6.tar.gz‘ ##+++++++++++++++++++++++++++++ path=${dir}/${package} src_path=${package%%.tar*} [ ! \( -f $path -a -f $scriptFile \) ] && echo "no package or srvcript in /tmp" && exit 4 [ $UID -eq 0 ] || exit 4 installofnamed() { echo -n "Install starting:" if ! id named &> /dev/null; then groupadd -r -g 53 named useradd -r -g 53 -u 53 named fi /bin/tar xf $path -C $HOME && cd ${HOME}/${src_path} && ./configure --prefix=/usr/local/bind9 --sysconfdir=/etc/named --disable-ipv6 --disable-chroot --enable-threads > /dev/null && make > /dev/null && make install > /dev/null success echo } SysInit() { echo -n "SysInit:" rm -rf ${HOME}/${src_path} rm -rf /usr/local/bind9 /usr/bin/yum -y -q groupinstall "Development Tools" "Server Platform Development" > /dev/null userdel -r named success echo } SysInit && installofnamed [ $? -eq 0 ] || exit 2 ##安装后 if [ -e /etc/profile.d/named.sh ]; then ! grep -q ‘/usr/local/bind9/sbin:/usr/local/bind9/bin‘ /etc/profile.d/named.sh && cat > `mktemp -u /etc/profile.d/named.XXX`.sh << EOF declare -x PATH=/usr/local/bind9/bin:/usr/local/bind9/sbin:$PATH EOF else cat > /etc/profile.d/named.sh << EOF declare -x PATH=/usr/local/bind9/bin:/usr/local/bind9/sbin:$PATH EOF fi declare -x PATH=/usr/local/bind9/bin:/usr/local/bind9/sbin:$PATH cat > /etc/ld.so.conf.d/named.conf << EOF /usr/local/bind9/lib EOF ldconfig ln -s /usr/local/bind9/include /usr/include/named [ -r /tmp/named ] && install /tmp/named /etc/init.d/named chkconfig --add named
本文出自 “Reading” 博客,请务必保留此出处http://sonlich.blog.51cto.com/12825953/1967967
以上是关于编译安装bind练习的主要内容,如果未能解决你的问题,请参考以下文章