DHCP is a wonderful piece of software. It keeps our networks running smoothly. For small networks, probably 100 machines or so, one server is enough, but to larger networks, is not a bad idea to have another one, just in case the firts one fails or the load is just to much..
DHCP has some configurations for load balancing and failover, the – failover declaration – that allows us to configure it.
To keep things simple, you can create a new file, and then just insert it in the global dhcpd.conf file
Primary DHCP server
Open a new file and put the following lines in it:
vi /etc/dhcp/dhcpd.failover# Failover specific configurations
failover peer “dhcp” { primary;address 10.1.2.1;
port 647;
peer address 10.1.2.2;
peer port 647;
max-response-delay 60;
max-unacked-updates 10;
mclt 600;
split 128;
load balance max seconds 3; }
Secondary Server
address 10.1.2.2;
port 647;
peer address 10.1.2.1;
peer port 647;
max-response-delay 60;
max-unacked-updates 10;
load balance max seconds 3; }
option subnet-mask 255.255.0.0;
option broadcast-address 10.1.255.255; pool { failover peer “dhcp”;
range 10.1.2.1 10.1.254.254; } }
Then the time is not the same.
Synchronization
- Creation of files
- changes in files
- deleting of files
- add an exception for dhcpd.failover (those are different in the servers – depending of primary or secondary server)
output:
Watch /etc/dhcp
Watch /etc/dhcp/Configs
Watch /etc/dhcp/dhclient.d
[14/Mar/2012 16:18:34] * Command: touch /tmp/someaction
[14/Mar/2012 16:18:34] IN_CREATE /etc/dhcp/Configs/.dhcp.vlan.swx
[14/Mar/2012 16:18:34] * Command: touch /tmp/someaction
[14/Mar/2012 16:18:34] IN_CLOSE_WRITE /etc/dhcp/Configs/.dhcp.vlan.swx
[14/Mar/2012 16:18:34] * Command: touch /tmp/someaction
Now that we saw it working, let’s configure the daemon part.
<!DOCTYPE config SYSTEM “/etc/iwatch.dtd” ><config charset=”utf-8″>
<guard email=”informatica@ulscb.min-saude.pt” name=”IWatch”/>
<watchlist>
<title>DHCP Sync</title>
<contactpoint email=”sysadmin@domain.com” name=”Administrator”/>
<path type=”recursive” syslog=”on” alert=”off” events=”create,delete,close_write” exec=”/root/scripts/syncFiles”>/etc/dhcp</path>
<path type=”regexception”>b4913b</path>
<path type=”exception”>/etc/dhcp/dhcpd.failover</path>
<path type=”exception”>/etc/dhcp/dhclient.d</path>
<path type=”regexception”>.*.swp*</path>
<path type=”regexception”>.*~</path>
</watchlist>
</config>
Now, edit that file and make the changes you want
I’ve added a few exceptions, because there are files i don’t need to sync.
Also, vi creates a few temporary files (directory 4913 and backups with ~ | swp extensions) when you’re editing, and those don’t mind.
We are not also using modify, because if a file is closed with write, it was modified, right ?
The exec parameter tells iwatch what to do when any of the events occurs. I have a script (syncFiles) that synchronizes with the secondary server and sends and email
#!/bin/bash # Script to synchronized dhcp changes# This script will be called by iwatch
# DO NOT EXECUTE THIS SCRIPT – IT WILL BE EXECUTED AUTOMATICALLY
# 15/12/2011 log=”/tmp/synclog.log” echo “Syncing dhcp from primary server to secondary server” >> $log
# Using rsync so it can only copy different files – Low on bandwith/usr/bin/rsync -avz –delete -e ssh /etc/dhcp/ –exclude dhcpd.failover root@secondary:/etc/dhcp >> $log # Restart the service with the new configurations
ssh root@secondary -C “service dhcpd restart” >> $log service dhcpd restart >> $log # Email if [ -a $log ]; then mail sysadmin@domain.com -s “Sync dhcp ” < $log rm -f $log fi
I use rsync to perform the copy. I exclude dhcpd.failover because the files are not the same and they depend on the server (primary or secondary)
Notes: A few security issues. iwatch is executed with root privileges – it’s started by /etc/rc.local
If you do nothing, every time the script is executed, you’ll have to give the root password of the secondary server. You can prevent this (if you want) by adding the ssh key to the authorized keys and have a password-less ssh configuration between those two servers (using only keys)
Now, just put iwatch executing when the machine start:
vi /etc/rc.local # Exec iwatch/usr/local/bin/iwatch -d
Execute iwatch as daemon
/usr/local/bin/iwatch -d
Now you have a dhcp failover instalation and synchronization
Hope it helps anyone
References
http://www.lithodyne.net/docs/dhcp/dhcp-4.html
http://www.madboa.com/geek/dhcp-failover/
http://www.ipamworldwide.com/dhcp-failover-a-load-balancing/declarations.html