DNS clustering is part of setting up a server environment. cPanel has built-in support for DNS clustering to make it easy to deploy centralized nameservers, or have multiple nameservers receive DNS zone updates from one server. This article will help you understand setting up and managing a DNS cluster from command line.
Setting up a Cluster
From the remote nameserver:
You generally don't need to do anything other than enable clustering in WHM. You want the client servers to sync TO this server, not from it. Most of the time, the remote server will be your primary nameserver running cPanel DNSONLY.
From the client:
There are a few files involved in setting up a DNS cluster. Keep in mind that novice users may prefer to use WHM > Configure Cluster, but this article is focused on the command line.
- /var/cpanel/cluster/root/config/xxx.xxx.xxx.xxx : The file (named after the IP of the remote nameserver) containing the user, hostname, and remote hash
- /var/cpanel/cluster/root/config/xxx.xxx.xxx.xxx-dnsrole : The file containing the sync action to the remote nameserver (standalone or sync)
- /etc/wwwacct.conf : File containing the delegated nameservers for new zones created
- /var/cpanel/resellers-nameservers : list of nameservers for resellers (overrides /etc/wwwacct.conf for zones created by accounts for that reseller)
- /var/cpanel/useclusteringdns : Blank file indicating that DNS clustering is enabled (presence of file indicates yes, absence indicates no)
If the server is also going to be a nameserver itself, you will need to enable named in WHM > Service Manager (/etc/chkserv.d/chkservd.conf, set named to '1').
1) Create a file in /var/cpanel/cluster/root/config as the IP of the remote server. Get the remote access hash for the remote nameserver (/root/.accesshash, located on the remote server) and add it to the file under the cluster user (assuming 'root') and its hostname. In this case, the remote server's IP is 188.8.131.52, so I'm going to create a file called /var/cpanel/cluster/root/config/184.108.40.206 and have it contain:
*Keep in mind that if you're a user other than root, you'd substitute 'root' in the path name for the actual user setting up the cluster.
All of this can also be done via WHM > Configure Cluster as well.
Managing DNS Zones
Synchronize a zone:
You generally want to synchronize a zone if changes were made and you want to push it out to your nameserver cluster. This is essentially the same as going into WHM > Synchronize DNS Records:
Running this command by itself will give you a list of options for synchronizing, just as you get in WHM:
- syncall : sync all zones with all cluster servers. This will find the zone with the largest serial and copy it to all nameservers in the cluster
- syncalllocal : Finds the zone in the cluster with the highest serial number and copies it to the local server only (instead of to all servers in the cluster) – /scripts/dnscluster syncalllocal –full
- synczone : Syncs one zone to all servers in the cluster, using the zone with the highest serial number throughout the cluster
- synczonelocal – Syncs one zone locally, using the zone with the highest serial number throughout the cluster
So for instance, if you have a zone for mydomain.com on your hosting server and you want to synchronize it to all the nameservers in your cluster, you'd run:
/scripts/dnscluster synczone domain.com
Edit a DNS Zone:
To edit a zone, open /var/named/domainname.com.db in a text editor and make your changes. Remember to increment the serial number up by one, so that the correct zone it sync'ed to the nameserver cluster. The serial looks like this:
; cPanel 11.24.4-STABLE_36281 ; Zone file for domainnmame.com $TTL 14400 @ 86400 IN SOA ns.mynameserver.com. me.mynameserver.com. ( 2009082500 ; serial, todays date+todays 86400 ; refresh, seconds 7200 ; retry, seconds 3600000 ; expire, seconds 86400 ) ; minimum, seconds
Then use /scripts/dnscluster to copy the zone up to your nameserver cluster. (see above examples)
Removing a DNS zone:
Adding a DNS zone:
/scripts/adddns –domain domainname.com
You can also use the –ip and –reseller flags to indicate what IP and nameservers to use. For usage, just run /scripts/adddns and the help will display.