Get the App
SLTechnology News&Howtos  ›  Servers  › 

Shell script practice-- DNS Master-Slave synchronization script example

Shulou Source: shulou.com Published: 2022-06-03 04:32:52 09月29日 Update

DNS master-slave synchronization script instance PS: After the two servers are up, it is best to restart both services. The master server configuration #!/ bin/bash#DNS master-slave synchronization--master server rpm -q bindif [ $? -ne 0 ];then yum install bind -y systemctl start namedfi#Determine whether DNS service is installed read -p "Please enter the master server address: " zhurad-p "Please enter the slave server address: " aggread-p "Domain name (please include suffix):" 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#Backup global, zone profiles 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#Determine whether the domain name exists, if not add 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#modify the zone file while [ 1 -ge 0 ];doread -p " Please enter a custom pointer (e.g. www IN A 8.8.8.8)" zhen echo $zhen > /var/named/$yu.dns read -p " Continue adding (y/n)" aif [ $a != "y" ];then breakfidone#loop systemctl stop firewalld.servicesetenforce 0systemctl restart namedjieguo=`systemctl status named| grep "active" &>/dev/null`if [ $? -eq 0 ];then echo "service startup"else echo "startup failure"fi#determine whether the service can start normally sed -i -e '3d' -e "2anameserver $zhu" /etc/resolv.conf#used for self-test slave server configuration #!/ bin/bash#DNS master-slave synchronization--slave server rpm -q bindif [ $? -ne 0 ];then yum install bind -yfi#Determine whether DNS service is installed read -p "Please enter the primary server address: " zhurad-p "Please enter the secondary server address: " aggread-p "Domain name (please include suffix):" 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#Backup global, zone profiles 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#Determine whether the domain name exists, if not add systemctl restart namedsystemctl stop firewalld.servicesetenforce 0jieguo=`systemctl status named| grep "active" &>/dev/null`if [ $? -eq 0 ];then echo "service startup"else echo "startup failure"fi#determine whether the service can start normally

Tags: Service server input address domain name configuration master-slave synchronization zone file two global suffix backup instance script pointer best loop actual combat Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL Apple Shulou Technology Shulou Tech Info