Archive for April, 2006

Running multiple postfix instances on Debian

Sunday, April 2nd, 2006

Recently I needed to reconfigure the company’s mail server in order to comply with the different requirements of Yahoo, Hotmail, AOL, etc.
The only solution for us was to set up multiple postfix instances with different configuration files.

I was surprised how easy that is:
cp –rp /etc/postfix /etc/postfix2
cp –rp /var/spool/postfix /var/spool/postfix2

Add the following line to /etc/postfix/main.cf:
alternate_config_directories = /etc/postfix2

Make sure you change the following in /etc/postfix2/main.cf:
syslog_name = postfix2
queue_directory = /var/spool/postfix2
alternate_config_directories = /etc/postfix

The only thing to do now is to bind the instances to separate IP addresses (or even different ports but I didn’t try that).
In my case I’ve changed the inet_interfaces value into mail1 for the first instance and mail2 for the second one. mail1 and mail2 are entries in my /etc/hosts for 192.168.0.4 and 192.168.0.5. They are both in use by my mail server.

The only difficult part was to hack the /etc/init.d/postfix script to start and stop both instances. I’ve posted my init script and it takes care of the multiple instances.

When you run tools like ‘qshape‘ or ‘mailq‘ they all use the spool directory of the first instance. With some tools you can specify the -c parameter to change to an alternative config directory. For example ‘qshape -c /etc/postfix2‘ will analyze the queue of the second instance. But the tool ‘mailq‘ doesn’t take the parameter -c. There you can set the environment variable ‘MAIL_CONFIG’. Just ‘export MAIL_CONFIG=/etc/postfix2 && mailq‘ et voila. When you use the php mail() function just ‘putenv (”MAIL_CONFIG=/etc/postfix2″);‘ before using the mail() function and your mails will be sent thru the second instance.

Happy mailing,
Nicolas

The hacked postfix init script