DNS主从同步脚本实例
PS:两个服务器起好后最好两个服务都重启一下
主服务器配置
#!/bin/bash#DNS主从同步――主服务器rpm -q bindif [ $? -ne 0 ];then yum install bind -y systemctl start namedfi#判断DNS服务是否安装read -p "请输入主服务器地址:" zhuread -p "请输入从服务器地址:" congread -p "域名(请带后缀):" yuquanju="/etc/named.conf"quyu="/etc/named.rfc1912.zones"[ ! -e $quanju.bak ] && cp $quanju $quanju.baksed -i -e "13s/127.0.0.1/$zhu/" -e '21s/localhost/any/' $quanju[ ! -e $quyu.bak ] && cp $quyu $quyu.bak#备份全局、区域配置文件grep "$yu" $quyu &> /dev/nullwhile [ $? -ne 0 ];do sed -i "18azone /"$yu/" IN {/n type master/;/n file /"$yu.dns/"/;/n allow- transfer { $cong/; }/;/n}/;/n" $quyu peizhi="/var/named/$yu.dns"cp -p /var/named/named.localhost $peizhidone#判断域名是否存在,如果不存在进行添加sed -i -e '2d' -e "1a@ IN SOA "$yu"/. admin/."$yu"/. (" /var/named/$yu.dnssed -i '8d' /var/named/$yu.dnssed -i '$d' /var/named/$yu.dnssed -i -e "7a/ NS $yu." -e "/A/s/127.0.0.1/$zhu/" /var/named/$yu.dns#修改区域文件while [ 1 -ge 0 ];doread -p "请输入自定义指针(例:www IN A 8.8.8.8)" zhen echo $zhen >> /var/named/$yu.dns read -p "是否继续添加(y/n)" aif [ $a != "y" ];then breakfidone#循环systemctl stop firewalld.servicesetenforce 0systemctl restart namedjieguo=`systemctl status named | grep "active" &>/dev/null`if [ $? -eq 0 ];then echo "服务启动"else echo "启动失败"fi#判断服务是否能正常启动sed -i -e '3d' -e "2anameserver $zhu" /etc/resolv.conf#用于自检
从服务器配置
#!/bin/bash#DNS主从同步――从服务器rpm -q bindif [ $? -ne 0 ];then yum install bind -yfi#判断DNS服务是否安装read -p "请输入主服务器地址:" zhuread -p "请输入从服务器地址:" congread -p "域名(请带后缀):" yuquanju="/etc/named.conf"quyu="/etc/named.rfc1912.zones"[ ! -e $quanju.bak ] && cp $quanju $quanju.baksed -i -e "13s/127.0.0.1/$cong/" -e '21s/localhost/any/' $quanju[ ! -e $quyu.bak ] && cp $quyu $quyu.bak#备份全局、区域配置文件grep "$yu" $quyu &> /dev/nullwhile [ $? -ne 0 ];do sed -i "18azone /"$yu/" IN {/n type slave/;/n file /"slaves//$yu.dns/"/;/n masters { $zhu/; }/;/n}/;/n" $quyudone#判断域名是否存在,如果不存在进行添加systemctl restart namedsystemctl stop firewalld.servicesetenforce 0jieguo=`systemctl status named | grep "active" &>/dev/null`if [ $? -eq 0 ];then echo "服务启动"else echo "启动失败"fi#判断服务是否能正常启动
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。
新闻热点
疑难解答