Nov 21 2006

Installing Qmail on RedHat

Welcommen! Because there are so many scripts we have to write that are necessary for the operation of qmail, the instructions are online so you can copy and paste the text into your scripts. Please be sure to read the instructions and not only the commands, you will miss important informaiton if you do!

Ok, the first step is to download the source for qmail. Also, you’ll need to download ucspi-tcp and daemontools. ucspi-tcp replaces inetd as the tcp server on your computer. This is not necessary, but is highly recommended by the creator of qmail to avoid issues. Daemontools, like ucspi-tcp is not mandatory, however it includes a tool called supervise which monitors services on your computer and restarts them if they die. You can see the importance of this if you were running a actual mail server.

* qmail, http://www.qmail.org/netqmail-1.05.tar.gz
* ucspi-tcp, http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
* daemontools, http://cr.yp.to/daemontools/daemontools-0.76.tar.gz

Now we need to unpack the tarballs. Change to the directory where you saved the tarballs.

umask 022
mkdir -p /usr/local/src
mv netqmail-1.05.tar.gz ucspi-tcp-0.88.tar.gz /usr/local/src
mkdir -p /package
mv daemontools-0.76.tar.gz /package
chmod 1755 /package

Now you can unpack the packages.

cd /usr/local/src
gunzip netqmail-1.05.tar.gz
tar xpf netqmail-1.05.tar
cd netqmail-1.05
cd ..
gunzip ucspi-tcp-0.88.tar.gz
tar xpf ucspi-tcp-0.88.tar
rm *.tar
cd /package
gunzip daemontools-0.76.tar.gz
tar xpf daemontools-0.76.tar
rm *.tar

There should now be directories called /usr/local/src/netqmail-1.05, /usr/local/src/ucspi-tcp-0.88, and /package/admin/daemontools-0.76.

Since qmail’s installation program creates the subdirectories as they’re needed, you only need to create the qmail “home” directory:

mkdir /var/qmail

Now to add users. In the source directory you’ll find a file called INSTALL.ids.

cd /usr/local/src/netqmail-1.05/netqmail-1.05

In this directory is a file called INSTALL.IDS. This is a script file with commands for many different types of systems. Typically you would copy the file and remove the commands that you don’t want from the new file. However, for this lab just create a new file called IDS and paste the following into it:

/usr/sbin/groupadd nofiles
/usr/sbin/useradd -g nofiles -d /var/qmail/alias alias
/usr/sbin/useradd -g nofiles -d /var/qmail qmaild
/usr/sbin/useradd -g nofiles -d /var/qmail qmaill
/usr/sbin/useradd -g nofiles -d /var/qmail qmailp
/usr/sbin/groupadd qmail
/usr/sbin/useradd -g qmail -d /var/qmail qmailq
/usr/sbin/useradd -g qmail -d /var/qmail qmailr
/usr/sbin/useradd -g qmail -d /var/qmail qmails

Now we need to run the script.

chmod 700 IDS

When the script finishes, all of your users and groups will be created.

Now you can start building qmail. Change to the /usr/local/src/netqmail-1.05/netqmail-1.05 directory and let’s get started:

cd /usr/local/src/netqmail-1.05/netqmail-1.05

Edit the files conf-cc and conf-ld and change “cc” to “gcc”. Then type the following:

make setup check

After the build is complete, you’ll need to do your post installation configuration. A couple of scripts are provided to make this job a lot easier.


YAY! qmail is installed! Now we’re about 1/4 done!

Earlier, you unpacked the qmail, ucspi-tcp, and daemontools tarballs. Now change to the ucspi-tcp directory:
cd /usr/local/src/ucspi-tcp-0.88

Edit the files conf-cc and conf-ld and change “cc” to “gcc”. Then do:

patch < /usr/local/src/netqmail-1.05/other-patches/ucspi-tcp-0.88.errno.patch
make setup check

Change to the daemontools build directory:

cd ../package/admin/daemontools-0.76

Once again, edit the files conf-cc and conf-ld and change "cc" to "gcc". Then do:

cd src
patch /var/qmail/control/defaultdelivery

Alright, now we need to make the qmail startup script. Without this script, qmail would not fully start at system boot. Create the following file: /var/qmail/bin/qmailctl. Copy and paste the following into the script.


# For Red Hat chkconfig
# chkconfig: – 80 30
# description: the qmail MTA

export PATH

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`

case “$1” in
echo “Starting qmail”
if svok /service/qmail-send ; then
svc -u /service/qmail-send /service/qmail-send/log
echo “qmail-send supervise not running”
if svok /service/qmail-smtpd ; then
svc -u /service/qmail-smtpd /service/qmail-smtpd/log
echo “qmail-smtpd supervise not running”
if [ -d /var/lock/subsys ]; then
touch /var/lock/subsys/qmail
echo “Stopping qmail…”
echo ” qmail-smtpd”
svc -d /service/qmail-smtpd /service/qmail-smtpd/log
echo ” qmail-send”
svc -d /service/qmail-send /service/qmail-send/log
if [ -f /var/lock/subsys/qmail ]; then
rm /var/lock/subsys/qmail
svstat /service/qmail-send
svstat /service/qmail-send/log
svstat /service/qmail-smtpd
svstat /service/qmail-smtpd/log
echo “Flushing timeout table and sending ALRM signal to qmail-send.”
svc -a /service/qmail-send
echo “Sending HUP signal to qmail-send.”
svc -h /service/qmail-send
echo “Pausing qmail-send”
svc -p /service/qmail-send
echo “Pausing qmail-smtpd”
svc -p /service/qmail-smtpd
echo “Continuing qmail-send”
svc -c /service/qmail-send
echo “Continuing qmail-smtpd”
svc -c /service/qmail-smtpd
echo “Restarting qmail:”
echo “* Stopping qmail-smtpd.”
svc -d /service/qmail-smtpd /service/qmail-smtpd/log
echo “* Sending qmail-send SIGTERM and restarting.”
svc -t /service/qmail-send /service/qmail-send/log
echo “* Restarting qmail-smtpd.”
svc -u /service/qmail-smtpd /service/qmail-smtpd/log
tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
chmod 644 /etc/tcp.smtp.cdb
echo "Reloaded /etc/tcp.smtp."
cat <&1

Create the concurrencyincoming control file:

echo 20 > /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming

Create the /var/qmail/supervise/qmail-smtpd/log/run file:

exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd

Make the run files executable:

chmod 755 /var/qmail/supervise/qmail-send/run
chmod 755 /var/qmail/supervise/qmail-send/log/run
chmod 755 /var/qmail/supervise/qmail-smtpd/run
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run

Then set up the log directories:

mkdir -p /var/log/qmail/smtpd
chown qmaill /var/log/qmail /var/log/qmail/smtpd

Finally, link the supervise directories into /service (The /service directory is created when daemontools is installed):

ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /service

Qmail will now start, however, we don’t want it running quite yet.

qmailctl stop

Now we have to allow localhost to inject mail via SMTP.

echo ‘127.:allow,RELAYCLIENT=””‘ >>/etc/tcp.smtp
qmailctl cdb

Next we have to stop and disable the installed MTA. This is how to do it in RedHat:

/etc/rc.d/init.d/sendmail stop

If the above doesn’t work, then find sendmail’s PID and kill it.

Ok, to prevent conflicts, we need to prevent sendmail from starting up in the future. The following method is a bit unorthodox, however it’s pretty easy to undo if you decide not to keep qmail. Edit the file /etc/rc.d/init.d/sendmail. Scroll down to the bottom of the file. Right under the comment “See how we are called.” simply comment out the line that says “start”. DO NOT comment any other line including the line “start)”.

Before we start qmail, we need to make sure nothing is listening to port 25:

netstat -a | grep smtp

You should have received no output. If you do receive output, make sure you find the culprit before continuing. Now replace any /usr/lib/sendmail with the qmail version.

mv /usr/lib/sendmail /usr/lib/sendmail.old # ignore errors
mv /usr/sbin/sendmail /usr/sbin/sendmail.old # ignore errors
chmod 0 /usr/lib/sendmail.old /usr/sbin/sendmail.old # ignore errors
ln -s /var/qmail/bin/sendmail /usr/lib
ln -s /var/qmail/bin/sendmail /usr/sbin

Now we must create the standard mail aliases. Note that all of these aliases point to root either directly or indirectly. If you want to change who gets mail sent to the following aliases you may change it here. See INSTALL.alias for more information:

echo root > /var/qmail/alias/.qmail-root
echo root > /var/qmail/alias/.qmail-postmaster
ln -s .qmail-postmaster /var/qmail/alias/.qmail-mailer-daemon
ln -s .qmail-postmaster /var/qmail/alias/.qmail-abuse
chmod 644 /var/qmail/alias/.qmail-root /var/qmail/alias/.qmail-postmaster

So that we can whitelist servers from spamassassin, run the following command to each user account:

spamassassin –lint

Edit the following file where {user} is the user name of each account

vi /home/{user}/.spamassassin/user_prefs

Where it says the whitelist section, add:
whitelist_from *@*.plymouth.edu
whitelist_from *@plymouth.edu

We now need to set the path where our Mailbox file is for mail clients to look at. You need to edit the profile mail setting.

vi /etc/profile

Edit the line that looks like this: MAIL=/var/spool/mail/{user}

Change it to look like this: MAIL=$HOME/Mailbox

For that to complete and to be able to read your mail, please restart the computer.

Now we can start qmail.

qmailctl start
Now run qmailctl stat to verify that the services are up and running. The output should look like this:

# qmailctl stat
/service/qmail-send: up (pid 30303) 187 seconds
/service/qmail-send/log: up (pid 30304) 187 seconds
/service/qmail-smtpd: up (pid 30305) 187 seconds
/service/qmail-smtpd/log: up (pid 30308) 187 seconds
messages in queue: 0
messages in queue but not yet preprocessed: 0

All four services should be “up” for more than a second. If they’re not, you’ve probably got a typo in the associated run script or you skipped one or more steps in creating the necessary files, directories, or links.

If everything seems to be working correctly, show that sendmail isn’t running and send and receive email and show the results to us.

If you have any other questions, check out the Lifewithqmail

Instructions and Installation provided to you by Timothy Haroutunian and Charles Newton
email, linux, mail, mail server, qmail, red hat, server, unix

About the author

Timothy Haroutunian

Timothy Haroutunian is a ServiceNow Cloud Implementation Specialist at Acorio. ServiceNow is an IT Management solution that allows for a complete view of your IT and physical environment.

Permanent link to this article: http://www.armenianeagle.com/2006/11/21/installing-qmail-on-redhat/


1 comment

1 ping

  1. trulz

    I feel like i have seen this exact wording somewhere before.

  1. Apple Cider

    click here…

    […]here are some links to sites that we link to because we think they are worth visiting[…]…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.