This is usually a work around for DNS clustering on two Plesk servers.
But should work without problems on any Linux server, just some paths will need to be modified.
1. Install the following script in /var/named/run-root/etc on the primary server:
——————————————————————————————————————————–
#!/bin/sh
MASTER=CHANGEME
NAMED_ROOT=/var/named/run-root/etc
HTTPDOCS=/var/www/vhosts/default/htdocs/
egrep “^zone” $NAMED_ROOT/named.conf |egrep -iv “arpa|\”\.” | awk -F\” ‘{print $2}’ > $NAMED_ROOT/domains
echo > $HTTPDOCS/secondaries.include
for i in `cat $NAMED_ROOT/domains`; do
echo “zone \”$i\” {” >> $HTTPDOCS/secondaries.include
echo ” type slave;” >> $HTTPDOCS/secondaries.include
echo ” file \”slave/$i\”;” >> $HTTPDOCS/secondaries.include
echo ” masters { $MASTER; };” >> $HTTPDOCS/secondaries.include
echo ” allow-transfer { none; };” >> $HTTPDOCS/secondaries.include
echo “};” >> $HTTPDOCS/secondaries.include
echo >> $HTTPDOCS/secondaries.include
done
chmod 644 $HTTPDOCS/secondaries.include
———————————————————————————————————————————–
Name the script gen-secondaries.sh, chmod to 755
Once installed, edit line “MASTER=CHANGEME” in the script, where CHANGEME put the IP address of the primary server.
2.Edit the named.conf on primary nameserver and add the following line:
acl common-allow-transfer {
NS2 IP address;
};
NOTE: If “acl common-allow-transfer” exists already then simply put in the IP of the secondary name server in there.
3.(Only on Plesk Servers)Add a global allow rule into the PSA database
mysql -u admin -p`cat /etc/psa/.psa.shadow` psa
insert misc values (’DNS_Allow_Transfer01′,’IPofsecondarynameserver’) ;
Note: Replace ‘IPofsecondarynameserver’ with the IP of the secondary nameserver and make sure to do this on BOTH the nameservers.
4. Put in the following crons on the primary server:
0 12 * * * /var/named/run-root/etc/gen-secondaries.sh > /dev/null 2>&1
5 12 * * * /etc/init.d/named restart > /dev/null 2>&1
5. Install the following script in /var/named/run-root/etc on the secondary nameserver :
———————————————————————————————————————————–
#!/bin/sh
MASTER=CHANGEME
FILE=secondaries.include
rm $FILE.tmp
wget http://$MASTER/$FILE -O $FILE.tmp
# works on RH9
#SIZE=`stat -c%s $FILE.tmp`
# works on everything
SIZE=`stat $FILE.tmp |grep Size |awk ‘{print $2}’`
if [ $SIZE = 0 ]; then
echo “ERROR! The secondary file is 0 length!”
exit 1
else
mv $FILE.tmp $FILE
chmod 644 $FILE
fi
———————————————————————————————————————————-
Name the script to xfer-config.sh and chmod to 755
Again edit the CHANGEME to the ip address of the PRIMARY Name server.
6. Edit named.conf on the secondary nameserver and add the following:
acl common-allow-transfer {
NS2 IP address;
};
NOTE: If “acl common-allow-transfer” exists already then simply put in the IP of the secondary name server in there.
and
include “/etc/secondaries.include”;
at the bottom of named.conf
7. Create a symlink for secondaries.include in /etc
cd /etc
ln -s /var/named/run-root/etc/secondaries.include secondaries.include
8.Install the following cron on the secondary nameserver:
10 12 * * * /var/named/run-root/etc/xfer-config.sh > /dev/null 2>&1
20 12 * * * /etc/init.d/named restart > /dev/null 2>&1
9.(Only on Plesk Servers) In Plesk control panel, login as ‘admin’ username and choose Server from
the menu on the left -> DNS -> Add NS records for secondary nameserver on both nameservers.
How to check if it works:
1. Create a test account on the primary nameserver.
2.Run the scripts in the following order:
a.gen-secondaries.sh (on primary)
b./etc/init.d/named reload (on primary)
c.xfer-config.sh (on secondary)
d./etc/init.d/named reload (on secondary)
You should see the zone file for the domain on the secondary domain created at /var/named/run-root/var/.