Hi Guys,
Ok, I have been hangin around picking up tips and getting help and now it is time to give something back
I needed to set up a secondary mx server for several hosting servers, some of which run DA. I will try and make this as foolproof as possible, but it may vary from distro to distro.
# First off, lets create a user on the backupmx server
$ useradd backupmx -d /home/backupmx -m -s /bin/bash
# Now create an ssh key for the new user
$ su backupmx
$ ssh-keygen -t rsa
# Grab the ssh key and stick it in notepad for future reference
$ cat ~/.ssh/id_rsa.pub
# Now, on each of the hosting servers:
# create user for the backupmx scripts to run
$ useradd backupmx -d /home/backupmx -m -s /bin/bash
$ su backupmx
$ nano ~/.ssh/authorized_keys
# put the key that you copied from the backup server in here
## NOTE ##
If there is no .ssh dir in the home directory of the user you are working with (there probably wont be if it is a new user), just ssh somewhere and it will be automatically created.
On my system, exim configs reside in /etc/exim4, feel free to adjust if yours is different.
# Back to the backupmx server
# Create dir structure
$mkdir /etc/exim4/backupmx
$mkdir /etc/exim4/backupmx/domain_files
$ chown -R backupmx:backupmx /etc/exim4/backupmx
And then copy this script to /etc/exim4/backupmx/retrieve_domains.sh
Now, edit your exim.conf and set the following line:
# Reload exim..
$ /etc/init.d/exim4 restart
Finally, set up a cron job for the script
(runs on the 5th minute of every hour - adjust to suit)
And now for the magic...
Oh wait, there is nothing left to do!
Except set the dns records of course...
You can test if the system works by running this command on the backupmx server:
Obviously, if you have non-DA servers that you want to run a backupmx for, you can do that simply by changing the ssh line for that server to point to /etc/localdomains or where ever the list of domains is kept.
I hope this helps someone
Ok, I have been hangin around picking up tips and getting help and now it is time to give something back

I needed to set up a secondary mx server for several hosting servers, some of which run DA. I will try and make this as foolproof as possible, but it may vary from distro to distro.
# First off, lets create a user on the backupmx server
$ useradd backupmx -d /home/backupmx -m -s /bin/bash
# Now create an ssh key for the new user
$ su backupmx
$ ssh-keygen -t rsa
# Grab the ssh key and stick it in notepad for future reference
$ cat ~/.ssh/id_rsa.pub
# Now, on each of the hosting servers:
# create user for the backupmx scripts to run
$ useradd backupmx -d /home/backupmx -m -s /bin/bash
$ su backupmx
$ nano ~/.ssh/authorized_keys
# put the key that you copied from the backup server in here
## NOTE ##
If there is no .ssh dir in the home directory of the user you are working with (there probably wont be if it is a new user), just ssh somewhere and it will be automatically created.
On my system, exim configs reside in /etc/exim4, feel free to adjust if yours is different.
# Back to the backupmx server
# Create dir structure
$mkdir /etc/exim4/backupmx
$mkdir /etc/exim4/backupmx/domain_files
$ chown -R backupmx:backupmx /etc/exim4/backupmx
And then copy this script to /etc/exim4/backupmx/retrieve_domains.sh
Code:
# Set Variables
cd /etc/exim4/backupmx/
# Import from servers
# SERVER1
ssh [email protected] cat /etc/virtual/domains > ./domain_files/server1
# SERVER2
ssh [email protected] cat /etc/virtual/domains > ./domain_files/server2
# Insert into exim4
# initialise
if [ -e domains ] ; then
rm domains
fi
if [ -e domains.temp ] ; then
rm domains.temp
fi
touch domains
for file in $( ls ./domain_files/ )
do
cat ./domain_files/$file >> domains.temp
done
# remove non-domain lines
sed -i '/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/d' domains.temp
# remove duplicates to keep it tidy
sort domains.temp | uniq > domains
# clean up and exit normally
rm domains.temp
exit 0
Now, edit your exim.conf and set the following line:
Code:
domainlist relay_to_domains = <stuff that you already have> : lsearch;/etc/exim4/backupmx/domains
# Reload exim..
$ /etc/init.d/exim4 restart
Finally, set up a cron job for the script
Code:
5 * * * * /etc/exim4/backupmx/retrieve_domains.sh > /dev/null
And now for the magic...
Oh wait, there is nothing left to do!
Except set the dns records of course...
You can test if the system works by running this command on the backupmx server:
Code:
$ exim -v [email protected]
test message
LOG: MAIN
<= [email protected] U=root P=local S=361
root@backupmx:~# delivering 1JyKtS-0001hj-3l
R: dnslookup_relay_to_domains for [email protected]
T: remote_smtp for [email protected]
Connecting to mail.relaydomain.com [2.2.2.2]:25 ... connected
SMTP<< 220 server2.relaydomain.com ESMTP Exim 4.63 Tue, 20 May 2008 15:43:50 +1000
SMTP>> EHLO backupmx.mydomain.com
SMTP<< 250-server2.relaydomain.com Hello backupmx.mydomain.com [3.3.3.3]
250-SIZE 20971520
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
SMTP>> STARTTLS
SMTP<< 454 TLS currently unavailable
SMTP>> MAIL FROM:<[email protected]>
SMTP<< 250 OK
SMTP>> RCPT TO:<[email protected]>
SMTP<< 250 Accepted
SMTP>> DATA
SMTP<< 354 Enter message, ending with "." on a line by itself
SMTP>> writing message and terminating "."
SMTP<< 250 OK id=1JyKda-0005zQ-MK
SMTP>> QUIT
LOG: MAIN
=> [email protected] R=dnslookup_relay_to_domains T=remote_smtp H=mail.relaydomain.com [2.2.2.2]
LOG: MAIN
Completed
Obviously, if you have non-DA servers that you want to run a backupmx for, you can do that simply by changing the ssh line for that server to point to /etc/localdomains or where ever the list of domains is kept.
I hope this helps someone
