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 184.108.40.206, so I'm going to create a file called /var/cpanel/cluster/root/config/220.127.116.11 and have it contain:
root ns1.mynameserver.com 1429r23c1fdec38012a574be14382fd5 14f24bc86f86af9273575677c53aff83 4dc0d2d24cc8b1a7fe275acdb18e8ae8 71298146e796566a0a9fa0ea92644f11 aeceeb5f6eb489f2bb477b783a5a97c0 b24644193bb58b682c28113aa1e0e79f 59b190962fca3fcb2efb13d58d103374 3b68072ffe65a2a58cfa285fa69edeae aff9e1922e0664acb86698c2c2884191 6cd9bd139252ec83833d07337117b898 ac071d28446cae6531e4dbeebdbe1aa2 511a689a4e2b24c7880a113694618920 a690f5b6bca11863fbc0d5b0d9a0a110 2b75426ca67984898afb71fc86c3ad75 c4a435525fc0f393ec317adbcbf4b99a ce4b64d04c2f23766ecfb1ca4c9d09ac 36f66070c2ed55362338a1d26315c37a 91af3d1723149727d2e1756233340a57 4d1432bbfa61356b8a4b656abe817cb5 80d40d86c23cc3f4f86e74766c6d1cd6 66d2a4f89773beb02e6f856c9ae13e29 ca3e12219298e51d92f7ee9e7c645b27 dc70e2c151be6d4949d38379f6897d84 1fa9afec98cd6965300a058d77fd792b 5f47b6b791c8739ac4a18064a4420455 cc4bdf1ccf0e91d30fa7fa23b0efd168 2546f63b55f385bab0910711476d
*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.