Shell脚本实战之DNS主从同步脚本实例
程序员文章站
2023-09-04 22:40:01
dns主从同步脚本实例
ps:两个服务器起好后最好两个服务都重启一下
主服务器配置
#!/bin/bash
#dns主从同步——主服务器
rpm -q...
dns主从同步脚本实例
ps:两个服务器起好后最好两个服务都重启一下
主服务器配置
#!/bin/bash #dns主从同步——主服务器 rpm -q bind if [ $? -ne 0 ];then yum install bind -y systemctl start named fi #判断dns服务是否安装 read -p "请输入主服务器地址:" zhu read -p "请输入从服务器地址:" cong read -p "域名(请带后缀):" 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 #备份全局、区域配置文件 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 #判断域名是否存在,如果不存在进行添加 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 #修改区域文件 while [ 1 -ge 0 ];do read -p "请输入自定义指针(例:www in a 8.8.8.8)" zhen echo $zhen >> /var/named/$yu.dns read -p "是否继续添加(y/n)" a if [ $a != "y" ];then break fi done #循环 systemctl stop firewalld.service setenforce 0 systemctl restart named jieguo=`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 bind if [ $? -ne 0 ];then yum install bind -y fi #判断dns服务是否安装 read -p "请输入主服务器地址:" zhu read -p "请输入从服务器地址:" cong read -p "域名(请带后缀):" 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 #备份全局、区域配置文件 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 #判断域名是否存在,如果不存在进行添加 systemctl restart named systemctl stop firewalld.service setenforce 0 jieguo=`systemctl status named | grep "active" &>/dev/null` if [ $? -eq 0 ];then echo "服务启动" else echo "启动失败" fi #判断服务是否能正常启动
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: Vue脚手架编写试卷页面功能