[BETA] DNS master2slave

I wrote it for RedHat variations. I thought that they used standard locations; evidently I'm wrong.

You'll have to make the adjustments yourself; I don't run any Debian servers.

Jup I adjusted all the scripts and they do work...

Only problem is the cron jobs....


What's the 9 for?

In Debian Etch the command to reload the bind configuration is /etc/init.d/bind9 reload ..

I guess the 9 is just the version of bind...
 
Not if it's preceeded by a space. It no doubt means something; perhaps you can tell if you want to look at the init file: /etc/init.d/bind. If it works correctly, and if it was created by the system then there's nothing to worry about.

Jeff
 
The space betweend /bind and 9 was a typing error...
And I can see it works when I manualy reload bind... but when I try to schedule it with cron I can see in the system log that the bind configuration is not reloaded..
 
Show us your cronjob line; that may need some adjustment as well.

Jeff
 
I want to run it every 5 minutes.
The line is

*/5 * * * * /etc/init.d/bind9 reload
 
At first I tried to run it as the user named (as described in the readme) but that did not work so than I tried to run it as root but that also dit not work
 
Instead of calling it the way you do why not call it in a script that also runs the command, and sends you an email that says something like "I restarted bind" so you'll know if the cronjob is being run.

Or at the very least check the logfiles; bind should write to /var/log/messages when it's restarted.

Jeff
 
Jeff,

I found this thread, which I noticed started way back in 2005. Is that release still the current one? or is there an updated one?

Thanks.
 
The current release is found on my website, here.

I've never taken the project out of beta because I didn't write it; rather I paid someone else to write it for me. He disappeared, and unless/until i understood it I didn't want to take it out of beta.

I now feel I understand it and I'm writing some code to remove dead zone files and servers you're no longer slaving. Once that's done and I also fix the typos in the instructions, I'll take it out of beta.

Jeff
 
Hi Jeff,
The current release is found on my website, here.

Is the current version installed with new DA installs and updates or do we need to update it manually?

BTW I have been using this feature and it's great.
Thanks for making it available to us.

Regards -Jason
 
Master2Slave DNS Replicator is mine; and it's not DirectAdmin specific (though the one on my site is known to work with DirectAdmin). It's not included with DirectAdmin (that's why they wrote their Multi Server Setup which requires a DirectAdmin license on both servers). And so it's not automatically updated.

When the final version is ready I'll be sending an email to everyone who left their real email address when they made the download. Most likely it'll install through a script which will remove the old one, but no promises yet.

:)

Jeff
 
Master2Slave DNS Replicator is mine; and it's not DirectAdmin specific (though the one on my site is known to work with DirectAdmin). It's not included with DirectAdmin (that's why they wrote their Multi Server Setup which requires a DirectAdmin license on both servers). And so it's not automatically updated.

When the final version is ready I'll be sending an email to everyone who left their real email address when they made the download. Most likely it'll install through a script which will remove the old one, but no promises yet.

:)

Jeff
Would be great if you can make it compatible with debian, since running this on debian requires real admin skills at the moment ;)
 
Running what on Debian? My script? If you'd post the issues you have, I'll look into them.

Jeff
 
FYI there is a small bug in getzone_dns.sh:

cp -f /home/namedftp/named.master.conf $weboroot/namedftp/$masterip.named.conf

should be

cp -f /home/namedftp/named.master.conf ${webroot}/namedftp/${masterip}.named.conf

I would also add {} around all the variables
 
I know; that's one reason it's still in beta. I've got to finish it but I've got to have the time :(.

Jeff
 
oh..my..i can't believe i spent 3 hours trying to get this script to work. i gave up in the end and wrote my own solution. based on the same concept, but it works, and, i dunno how other people's servers are setup, provide the rights paths and i imagine my solutions will work too.

question. is your solution based on rndc working or does it transfer all the zone data?
 
The solution (I spend anywhere from ten minutes to a half hour per install; that's why we charge $25 per server; it's a good average :).

None of the scripts restarts or reloads BIND: this root cronjob does a reload:
Code:
10,25,40,55 * * * * /sbin/service named reload

All we do is rewrite /etc/named.conf on the slave server with slave records that correspond to the master records on the master server.

There are some typos in the instructions, but nothing that's kept many admins from using the script.

If you can tell us what didn't work, that would help us bring the system out of beta.

Jeff
 
well, the whole requiring a username to run this got me confused for a little. and using custom paths to store the data files (the tmp/ dir i understand though).
i wrote my own solution, based around your idea. i think you may have it doing too much work. maybe over-complicating it.
then it started to confuse me where some cp commands are present, but commented out, leaving me a little puzzled as to where the resulting file actually ended up. i think you need to have more definitive configuration at the top of the script. try and use as few extra directories where possible, or try and get the script to setup directories it needs if they're not present and required.
it's 1.20am here right now, so i'm not in the best of thinking moods. i just wanted this task done! i have to come back to it because it doesn't reload BIND when new zones are added, and i want it to delete zones that are no longer in the master's list. i'll re-post tomorrow with a post which may be more helpful ;)

dan
 
ok, here's my version. and i got this working in about an hour.

master server:
Code:
#!/usr/bin/perl

use strict;

my $master_ip = "209.195.4.186";
my $named_conf = "/etc/bind/named.conf";
my $web_root = "/var/www/html/namedftp";

my $output = `grep "^zone" /etc/bind/named.conf|grep -v '^#'|grep "type master"`;

my @zones = split(/\n/,$output);

open(WWW,">".$web_root."/".$master_ip.".named.conf") or die "Can't open ".$web_root."/".$master_ip.".named.conf: ".$!."\n";

foreach (@zones) {
	$_ =~ /zone \"(.*)\" \{/;
	my $domain = $1;
	print WWW $domain."\n";
}
close(WWW);

slave server:
Code:
#!/usr/bin/perl

use strict;

my $master_file = "/var/named/etc/namedb/masterlist";
my $master_path = "namedftp";

my $slave_conf = "/var/named/etc/namedb/slave.conf";
my $named_path = "/var/named/etc/namedb/zones";

my $path_to_named_binary = "/usr/sbin/named";

system("rm -rf ./tmp/*");

open(MASTERS,$master_file) or die "Can't open ".$master_file.": ".$!."\n";
my @masters = <MASTERS>;
close(MASTERS);

open(SLAVE,">".$slave_conf) or die "Can't open slave config: ".$!."\n";

my @domains;

foreach my $ip (@masters) {
	chomp($ip);
	system("wget -q http://".$ip."/".$master_path."/".$ip.".named.conf -P ./tmp");
	
	open(DOMAINS,"./tmp/".$ip.".named.conf") or die "Can't open ./tmp/".$ip.".named.conf: ".$!."\n";
	@domains = <DOMAINS>;
	close(DOMAINS);

	foreach my $domain (@domains) {
		chomp($domain);
		print SLAVE "zone \"$domain\" { type slave; file \"$named_path/$domain.db\"; masters { $ip; }; };\n";
	}
}
close(SLAVE);

# find out the running BIND's PID number..
my $p = `ps ax | grep $path_to_named_binary | grep -v grep`;
my @ps = split(/\n/,$p);

my $pid;
foreach (@ps) {
	$_ =~ /^(\d*)\s/;
	$pid = $1;
}
# then rehash/reload it to force it to update the new slave.conf we generated (and thus ask for a notify on new zones)
system("kill -HUP ".$pid);

exit; # comment this out if you want the slave script to cleanup zones that were deleted on the master

opendir(DIR, $named_path) || die "can't opendir $named_path: $!";
my @files = readdir(DIR);
closedir DIR;

foreach my $file (@files) {
	if ($file eq "." || $file eq "..") { next; }
	my $domain = substr($file,0,length($file) - 3);
	my $found = 0;
	foreach my $d (@domains) {
		chomp($d);
		if ($d eq $domain) { $found = 1; last; }
	}
	if (!$found) { system("rm -f ".$named_path."/".$file); }
}

the scripts work by sitting in the named.conf's directory (/etc/bind or /etc/namedb, depending on o/s). make sure on the slave there is a tmp/ and zones/ directory in the same one as the script. also, make sure you have a "masterlist" file (as jeff's does) with one master server ip per line. configure the paths at the top and run them as root. i have it setup so that the master scripts runs every 15 mins on 0,15,30,45 and the slave every 15 mins on 5,20,35,50 (just incase).

note: this doesn't have jeff's domain exclusion stuff. so the slave will replicate all domains on the master. the only reason i didn't write that is because i didn't need it.

you don't have to use these, i was just posting my solution to try to be of help. i'm sure there are also much better ways of doing it. this is my 2 cents.

(also, i don't mean to try and take the thunder away from jeff's scripts. i'm sure they work marvellously, and probably do for many people. seems that when it gets towards 1am i tend to lose my patience threshold lol)

dan
 
Last edited:
Back
Top