DNS BIND之运维管理脚本

为了方便管理bind,编写shell脚本,实现bind的start、stop、restart、status操作,并可以将脚本复制到/etc/rc.d/init.d/,添加以服务启动,并设置bind服务为开机启动。

脚本bind:

#!/bin/bash
# bind 运行管理脚本,可以将该脚本复制到/etc/rc.d/init.d/,使用系统service维护
# chkconfig: 345 35 75

#启动用户
BIND_USER=slim
#chroot path
CHROOT_PATH=/home/slim/chroot
#bind install apth
BIND_PATH=/home/slim/bind

if [ `id -u` -ne 0 ]; then
        echo "ERROR:For bind to port 53,must run as root."
        exit 1
fi
case "$1" in
start)
if [ -x $BIND_PATH/sbin/named ];then
        $BIND_PATH/sbin/named -u $BIND_USER -t $CHROOT_PATH -c /etc/named.conf && echo "BIND Server is started."
fi
;;
stop)
        kill `cat $CHROOT_PATH/var/run/named.pid ` && echo "BIND Server is stopped."
;;
restart)
        echo "Restart BIND server."
        $0 stop
        sleep 3
        $0 start
;;
reload)
        $BIND_PATH/sbin/rndc -c $CHROOT_PATH/etc/rndc.conf reload
;;
status)
        $BIND_PATH/sbin/rndc -c $CHROOT_PATH/etc/rndc.conf status
;;
*)
        echo "Usage:$0 start | stop | restart |reload |status"
        exit 1
;;
esac
exit 0
添加执行权限:

chmod +x bind

复制脚本bind到cp bind /etc/rc.d/init.d/中使用service管理:

service bind start|stop|restart|reload|status

添加开机启动:

#cd /etc/init.d/

# chkconfig --add bind  /*将bind添加到chkconfig管辖之内

# chkconfig bind on   /*启用这个服务

# chkconfig --list bind     /*显示bind

chkconfig参数:

#chkconfig -h
chkconfig version 1.3.49.3 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage:   chkconfig [--list] [--type <type>] [name]
         chkconfig --add <name>
         chkconfig --del <name>
         chkconfig --override <name>
         chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>

你可能感兴趣的:(dns)