• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Two Plesk servers & DNS

S

sunech

Guest
Hi,

I have a client with one Plesk webserver, who wishes to expand with an additional webserver with Plesk. Both servers are going to be used for web/mail hosting.

The client wishes the servers to act as nameservers for the domains being hosted at each server, with one server as primary DNS server and the other as secondary.

How can this be done?
Should they just both have an ACL record for the other server added, to allow zone transfers, and each domain an NS record for both servers?
Thanks.
 
Sort of. On one server you'd set the DNS to act as secondary DNS for the same domain on the other server (there's an icon to enable this in the DNS section). The domain would have to be hosted on the other server.

This is not hugely efficient because you'd have to have each domain set up on both servers.

I think there's a script on atomicrocketturtle.com that helps with automating secondary DNS. I'm not sure it will do exactly what you want but it might be a start. I'm afraid I don't remember where it might be on that site or what it is called - only that something like that exists or existed at one point.

You can also look into dnsmanager from 4psa.com but this is a commercial option and does more than is required here.

Faris.
 
I have written external scripts, that cause completely seperate servers to be my primary DNS servers via PowerDNS.

If you want my scripts, drop by IRC.

-Will
 
Since I went to all the work to put this together when he dropped by IRC, I'll go ahead and post it here.

=Event Manager Settings=
Domain alias created lowest (0) psaadm /opt/psa/scripts/domain -a add -n <new_domain_alias_name>
Domain alias deleted lowest (0) psaadm /opt/psa/scripts/domain -a del -o <old_domain_alias_name>
Domain alias updated lowest (0) psaadm /opt/psa/scripts/domain -a up -o <old_domain_alias_name> -n <new_domain_alias_name>
Domain created lowest (0) psaadm /opt/psa/scripts/domain -a add -n <new_domain_name>
Domain deleted lowest (0) psaadm /opt/psa/scripts/domain -a del -o <old_domain_name>
Domain updated lowest (0) psaadm /opt/psa/scripts/domain -a up -o <old_domain_name> -n <new_domain_name>

Client Script (/opt/psa/domain.php):
PHP:
#!/usr/bin/php
<?php
/*
 Command Options
  -a <action>
    up - Update Domain Name (requires arguments n and o)
    add - Add a new Domain Name (require arguments n)
    del - Delete an existing Domain Name (requires argument o)
  -o <domain>
    old domain name to work on
  -n <domain>
    new domain to work on
*/

$url = 'http://ns0.somedomain.net/domain.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
$options = getopt('a:o:n:');
curl_setopt($ch, CURLOPT_POST, true);
$fields = '';
$fields .= 'server='.rawurlencode('plesk1');
$fields .= '&key='.rawurlencode('uniquekey');
$fields .= '&action='.rawurlencode($options['a']);
$fields .= '&old_domain_name='.rawurlencode($options['o']);
$fields .= '&new_domain_name='.rawurlencode($options['n']);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec ($ch);
curl_close ($ch);
$result = explode('|',$result,2);
if ($result[0] == 'SUCCESS') exit(0);
if ($result[0] == 'ERROR') print $result[1]."\n";
else print "Unknown output\n".$result[0]."\n";
?>

Script to put on Backup PowerDNS Server (/srv/www/somedomain.net/ns0/htdocs/domain.php):
PHP:
<?
include('config.inc.php');

function gpc($name) {
        return get_magic_quotes_gpc()?stripslashes($_REQUEST[$name]):$_REQUEST[$name];
}

function est($string) {
        return mysql_escape_string($string);
}

function dr($error, $message = null) {
        global $server;
        $out = $error?'ERROR':'SUCCESS';
        if ($message) $out .= '|'.$message;
        if ($error) {
                define_syslog_variables();
                openlog("plesk-dnsbackup", LOG_CONS, LOG_USER);
                syslog(LOG_WARNING, $server."(".$_SERVER['REMOTE_ADDR'].") - $message");
        }
        die($out);
}

$key = gpc('key');
$server = gpc('server');

if (!isset($auth[$server])||$auth[$server]['key'] != $key) {
        dr(true,'authorization denied');
}



if (!mysql_connect($dbhost,$dbuser,$dbpass)) die('ERROR|Unable to Connect to Database');
if (!mysql_select_db($dbdatabase)) die('ERROR|Unable to select database');

if ($_REQUEST['action'] == 'add') {
        $domain = gpc('new_domain_name');
        $sql = 'SELECT `id`, `name`, `master`, `type` FROM `domains` WHERE `name` = "'.est($domain).'";';
        $query = mysql_query($sql);
        if (!$query) dr(true,'Query Error '.mysql_error().' Query - '.$sql);
        if (mysql_num_rows($query)) {
                $row = mysql_fetch_assoc($query);
                dr(true,'Domain ('.$domain.') Already Exists');
        } else {
                $sql = 'INSERT INTO `domains` (`name`, `master`, `type`) VALUES ("'.est($domain).'", "'.est($auth[$server]['ip']).'","SLAVE");';
                if (!mysql_query($sql)) dr(true,'Query Error '.mysql_error().' Query - '.$sql);
                dr(false);
        }
} elseif ($_REQUEST['action'] == 'del') {
        $domain = gpc('old_domain_name');
        $sql = 'SELECT `id` FROM `domains` WHERE `name` = "'.est($domain).'" AND `type` = "SLAVE" AND `master` = "'.est($auth[$server]['ip']).'";';
        $query = mysql_query($sql);
        if (!$query) dr(true,'Query Error '.mysql_error().' Query - '.$sql);
        if (mysql_num_rows($query)) {
                $sql = 'DELETE FROM `domains` WHERE `name` = "'.est($domain).'" AND `type` = "SLAVE" AND `master` = "'.est($auth[$server]['ip']).'";';
                if (!mysql_query($sql)) dr(true,'Query Error '.mysql_error().' Query - '.$sql);
                dr(false);
        } else {
                dr(true,"domain (".$domain.") does not exist");
        }
} elseif ($_REQUEST['action'] == 'up') {
        $new_domain = gpc('new_domain_name');
        $old_domain = gpc('old_domain_name');
        if ($new_domain == $old_domain) {
                $sql = 'SELECT `id` FROM `domains` WHERE `name` = "'.est($new_domain).'" AND `type` = "SLAVE" AND `master` = "'.est($auth[$server]['ip']).'";';
                $query = mysql_query($sql);
                if (!$query) dr(true,'Query Error '.mysql_error().' Query - '.$sql);
                if (mysql_num_rows($query)) {
                        dr(false);
                } else {
                        dr(true,'Domain ('.$new_domain.') does not exist to update');
                }
        }
        $sql = 'UPDATE `domains` SET `name` = "'.est($new_domain).'" WHERE `name` = "'.est($old_domain).'" AND `type` = "SLAVE" AND `master` = "'.est($auth[$server]['ip']).'";';
        if (!mysql_query($sql)) dr(true,'Query Error '.mysql_error().' Query - '.$sql);
        if (mysql_affected_rows()) {
                dr(false);
        } else {
                dr(true,"Domain (".$old_domain.") does not exist, could not update to (".$new_domain.")");
        }
} else {
        dr(true,"Unknown Action");
}

Config Script to Define Servers that can add backup domains (/srv/www/somedomain.net/ns0/htdocs/config.inc.php):
PHP:
<?php

/* Edit all fields below here to your information */

/* MySQL Configuration */

//
// Host we should connect to.
// This could be for example "localhost" or a sock file
$dbhost = 'localhost';

//
// Your user with SELECT/INSERT/UPDATE/DELETE/CREATE access to $dbdatabase
$dbuser = 'pdns';

//
// Youe password, the password for $dbuser
$dbpass = 'password';

// Your database, the database you want to use for PowerDNS (or are already using)
$dbdatabase   = 'pdns';

$auth = array();
$auth['plesk1'] = array();
$auth['plesk1']['key'] = 'uniquekeyhere';
$auth['plesk1']['ip'] = 'iphere';

$auth['cyberleo'] = array();
$auth['cyberleo']['key'] = 'uniquekeyhere2';
$auth['cyberleo']['ip'] = 'secondip';

That's it folks...

Thanks,
Will
 
Back
Top