真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Shell腳本實(shí)戰(zhàn)——DNS主從同步腳本實(shí)例

DNS主從同步腳本實(shí)例

PS:兩個(gè)服務(wù)器起好后最好兩個(gè)服務(wù)都重啟一下

主服務(wù)器配置

#!/bin/bash
#DNS主從同步——主服務(wù)器

rpm -q bind
if [ $? -ne 0 ];then
    yum install bind -y
    systemctl start named
fi
#判斷DNS服務(wù)是否安裝

read -p "請(qǐng)輸入主服務(wù)器地址:" zhu
read -p "請(qǐng)輸入從服務(wù)器地址:" cong
read -p "域名(請(qǐng)帶后綴):" yu
quanju="/etc/named.conf"
quyu="/etc/named.rfc1912.zones"
[ ! -e $quanju.bak ] && cp $quanju $quanju.bak
sed -i -e "13s/127.0.0.1/$zhu/" -e '21s/localhost/any/' $quanju
[ ! -e $quyu.bak ] && cp $quyu $quyu.bak
#備份全局、區(qū)域配置文件

grep "$yu" $quyu &> /dev/null
while [ $? -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 $peizhi
done
#判斷域名是否存在,如果不存在進(jìn)行添加

sed -i -e '2d' -e "1a@       IN SOA  "$yu"\. admin\."$yu"\. (" /var/named/$yu.dns
sed -i '8d' /var/named/$yu.dns
sed -i '$d' /var/named/$yu.dns
sed -i -e "7a\      NS      $yu." -e "/A/s/127.0.0.1/$zhu/" /var/named/$yu.dns
#修改區(qū)域文件

while [ 1 -ge 0 ];do
read -p "請(qǐng)輸入自定義指針(例:www IN A 8.8.8.8)" zhen
  echo $zhen >> /var/named/$yu.dns
  read -p "是否繼續(xù)添加(y/n)" a
if [ $a != "y" ];then
  break
fi
done
#循環(huán)

systemctl stop firewalld.service
setenforce 0
systemctl restart named
jieguo=`systemctl status named | grep "active" &>/dev/null`
if [ $? -eq 0 ];then
  echo "服務(wù)啟動(dòng)"
else
  echo "啟動(dòng)失敗"
fi
#判斷服務(wù)是否能正常啟動(dòng)

sed -i -e '3d' -e "2anameserver $zhu" /etc/resolv.conf
#用于自檢

從服務(wù)器配置

#!/bin/bash
#DNS主從同步——從服務(wù)器

rpm -q bind
if [ $? -ne 0 ];then
    yum install bind -y
fi
#判斷DNS服務(wù)是否安裝

read -p "請(qǐng)輸入主服務(wù)器地址:" zhu
read -p "請(qǐng)輸入從服務(wù)器地址:" cong
read -p "域名(請(qǐng)帶后綴):" yu
quanju="/etc/named.conf"
quyu="/etc/named.rfc1912.zones"
[ ! -e $quanju.bak ] && cp $quanju $quanju.bak
sed -i -e "13s/127.0.0.1/$cong/" -e '21s/localhost/any/' $quanju
[ ! -e $quyu.bak ] && cp $quyu $quyu.bak
#備份全局、區(qū)域配置文件

grep "$yu" $quyu &> /dev/null
while [ $? -ne 0 ];do
  sed -i "18azone \"$yu\" IN {\n  type slave\;\n  file \"slaves\/$yu.dns\"\;\n    masters { $zhu\; }\;\n}\;\n" $quyu
done
#判斷域名是否存在,如果不存在進(jìn)行添加

systemctl restart named
systemctl stop firewalld.service
setenforce 0
jieguo=`systemctl status named | grep "active" &>/dev/null`
if [ $? -eq 0 ];then
  echo "服務(wù)啟動(dòng)"
else
  echo "啟動(dòng)失敗"
fi
#判斷服務(wù)是否能正常啟動(dòng)

網(wǎng)站名稱(chēng):Shell腳本實(shí)戰(zhàn)——DNS主從同步腳本實(shí)例
瀏覽地址:http://weahome.cn/article/jppssj.html

其他資訊

在線咨詢(xún)

微信咨詢(xún)

電話咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部