Monday, September 25, 2006

Installing qmail 1.03 on Red Hat ES

I mentioned in my previous post that I am installing a email server on Red Hat ES version 4. In this post I plan to talk about how I managed to install a qmail SMTP server to create a reference I can easily find if I ever need to do this again.

Red Hat Preparation

Install all rpm packages needed for building source code. This rpm packages should be on the installation CD's:

rpm -ivh gcc-3.4.3-9.EL4.i386.rpm
rpm -ivh glibc-devel-2.3.4-2.i386.rpm
rpm -ivh glibc-headers-2.3.4-2.i386.rpm
rpm -ivh glibc-kernheaders-2.4-9.1.87.i386.rpm
rpm -ivh autoconf-2.59-5.noarch.rpm
rpm -ivh automake-1.9.2-3.noarch.rpm

Installing qmail
First download the qmail-1.03 source code and the qmail-date-localtime.patch.This patch causes the various qmail programs to generate date stamps in the local timezone.

Next uncompress the qmail-1.03 source code and apply the patch

# tar xvfz qmail-1.03.tar.gz
# cd qmail-1.03/
# patch -p1 < ../qmail-date-localtime.patch

Before we compile we must do some manual work here. This version of qmail is not the most recent version of qmail and it has some incompatibility problems with glibc 2.3.1 and later. The problem is with the errno.h header file that qmail does not have included. To fix this we must modify the source code of qmail (don't be afraid, is not big deal) and change all the lines that say extern int errno; with the line #include <errno.h>. There are only three files that have this line:


Simply open this files and edit the problematic line. And then we make the famous configure/make/make install dance:

# make setup
# make check
# ./config

Please note that the command ./config will complain if the machine does not have a FQDN (Fully Qualified Domain Name) properly configured in the DNS server. If you are installing a test server that will not have a FQDN or that will have one later we should change the command to ./config-fast where is the test domain name.

At this point qmail must be installed in the /var/qmail directory and most cofiguration files must be already setup. We can check that everything went ok by looking at this files inside tha /var/qmail/control directory:






In all this files must be the domain name of your server. You can edit the files in case they are missing any parts. Actually you may trust better the qmail ./config script and leave everything just like that.

We shall not forget the important accounts for root, postmaster and mailer-daemon.

# cd /var/qmail/alias
# touch .qmail-postmaster .qmail-mailer-daemon .qmail-root
# chmod 644 .qmail*

If sendmail is installed on the server we must disable it to avoid conflicts with qmail. Unfortunatelly uninstalling sendmail in Red Hat ES 4 starts complaining about missing dependencies and stuff. The solution for this is cheat the server by removing the sendmail binary and replacing it with that of qmail:

First stop the service

service sendmail stop

Next remove it from the statup scripts so sendmail is not restarted when the server is rebooted:

/sbin/chkconfig --level 12345 sendmail off

Finally replace the sendmail binary with a link to the qmail binary:

# cd /usr/sbin
# mv sendmail sendmail.dist
# chmod 0 sendmail.dist
# ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail

With sendmail out of way we can now start the qmail services just for testing:

# cp /var/qmail/boot/home /var/qmail/rc
# /var/qmail/rc &

Testing qmail

To check if the qmail services are running we can use the ps command:

# ps -aef | grep qmail
qmails 14540 13180 0 00:54 pts/4 00:00:00 qmail-send
qmaill 14541 14540 0 00:54 pts/4 00:00:00 splogger qmail
root 14542 14540 0 00:54 pts/4 00:00:00 qmail-lspawn ./Mailbox
qmailr 14543 14540 0 00:54 pts/4 00:00:00 qmail-rspawn
qmailq 14544 14540 0 00:54 pts/4 00:00:00 qmail-clean

All the services must be running under the respective users. If the output is not like the shown here then something went wrong. Try to go back and check all steps again.

Now lets try to send a single mail locally to see if it arrives. To send and empty email to the root user we run the next command:

# echo to: | /var/qmail/bin/qmail-inject

To check if the mail was delivered or not we look at the root user Mailbox:

# more /var/qmail/alias/Mailbox

There should be an empty email in there directed to

But I want Maidir instead of Mailbox!!
Ok we all now that Maildir have advantages over mailbox and that in these days Maildir is the default. To change qmail to use Maildir instead of Mailbox we must edit the start script /var/qmail/rc file.

We must change the line:

qmail-start ./Mailbox splogger qmail

with the next line

qmail-start ./Maildir/ splogger qmail

Note the trailing slach after Maildir... it is important.

Now each user that is to use Maildir must have the Maildir directory created in it's home directory. For this we use the maildirmake utility that comes with qmail. We don't want to be creating Maildirs everytime a new user is added so we create a Maildir in the /etc/skel direcotry. This way the Maildir will be created automatically when a new user is added to the system.

# /var/qmail/bin/maildirmake /etc/skel/Maildir

Finally we kill all the qmail process using the kill command and the pid of the processes we see with the ps command and restart the qmail again but with Maildir support.

# /var/qmail/rc &

Starting qmail at boot

There exists several ways to start qmail at server boot. The old way was using inetd or the newer xinetd. Unfortunatelly it is known that inetd/xinetd have scalability limitations as the number of requests increase. The new solution is to use tcpserver that not only is more efficient and scalable but also has security features.

Since this post is already very long I will blog about setting qmail with tcpserver in a new post. Subsequent posts will contain information about POP3 access and Vpopmail/MySQL virtual domain support.

No comments:

Post a Comment