前阵子做的一个项目,现在整理了,和大家一起分享。
qmail installation guide
author: lupeng lockbox@163.com
version: v1.1 2004-6-27
qmail is an excellent MTA(Mail Transport Agent) written by Dan Bernstein.
Why qmail:
* Security. qmail is secure.
* Speed. qmail is capable of handing millions of deliveries per day on a moderate system.
* Reliability. qmail writes mail to disk before it announces success.
* Extremely easy virtual domain administration.
* User-controlled mailing lists using ezmlm.
* Intuitive, straightforward, and simple administration.
Requirements:
* You must be running UNIX or a UNIX-like operating system.
* You must have a working DNS, and your system must have a DNS name.
* You must have a working C compiler.
Install file list:
* netqmail-1.05.tar.gz
* ucspi-tcp-0.88.tar.gz
* daemontools-0.76.tar.gz
* vpopmail-5.4.0.tar.gz
* mysql-standard-4.0.20-pc-linux-i686.tar.gz
* apache_1.3.31.tar.gz
* php-4.3.7.tar.gz
* autorespond-2.0.4.tar.gz
* ezmlm-0.53.tar.gz
* ezmlm-idx-0.40.tar.gz
* qmailadmin-1.2.0.tar.gz
* sqwebmail-3.5.3.tar.gz
Patches:
* ezmlm-idx-0.53.400.unified_41.patch
Scripts:
* qmailctl
* inst_check
* qmailadmin_zh
* zh-cn/*
* images/webmail/*
Preparation:
Login the system as root.
mkdir -p /usr/local/src
mkdir -p /package
Move the files of installation, patches and scripts except daemontools-0.76.tar.gz to /usr/local/src
Move daemontools-0.76.tar.gz to /package
chmod 1755 /package
Start installation:
cd /usr/local/src
tar -xvzf netqmail-1.05.tar.gz
cd netqmail-1.05
./collate.sh # important sentence!!!
cd ..
tar -xvzf ucspi-tcp-0.88.tar.gz
rm *.tar # optional, unless space is very tight
cd /package
tar -xvzf daemontools-0.76.tar.gz
rm *.tar # optional, again
################################
# Install qmail
################################
mkdir /var/qmail
mkdir /etc/qmail
ln -s /etc/qmail /var/qmail/control
# Create users and groups
userdel alias
userdel qmaild
userdel qmaill
userdel qmailp
userdel qmailq
userdel qmailr
userdel qmails
groupdel nofiles
groupdel qmail
groupadd nofiles
useradd -g nofiles -d /var/qmail/alias alias
useradd -g nofiles -d /var/qmail qmaild
useradd -g nofiles -d /var/qmail qmaill
useradd -g nofiles -d /var/qmail qmailp
groupadd qmail
useradd -g qmail -d /var/qmail qmailq
useradd -g qmail -d /var/qmail qmailr
useradd -g qmail -d /var/qmail qmails
cd /usr/local/src/netqmail-1.05/netqmail-1.05
make setup check
# If your DNS is configured properly, this script should be all you need at this point:
./config
# Or you can configure your domain.
./config-fast mail.myqmail.com
################################
# Install ucspi-tcp
################################
cd /usr/local/src/ucspi-tcp-0.88
patch < /usr/local/src/netqmail-1.05/other-patches/ucspi-tcp-0.88.errno.patch
make
make setup check
################################
# Install daemontools
################################
cd /package
tar -xvzf daemontools-0.76.tar.gz
cd /package/admin/daemontools-0.76/src
patch < /usr/local/src/netqmail-1.05/other-patches/daemontools-0.76.errno.patch
cd ..
package/install
# Start qmail script
vi /var/qmail/rc
######## Write the following section to file:/var/qmail/rc ########
#!/bin/sh
# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver messages by default
exec env - PATH="/var/qmail/bin:$PATH" \
qmail-start "`cat /var/qmail/control/defaultdelivery`"
######## End ########
chmod 755 /var/qmail/rc
mkdir /var/log/qmail
echo ./Maildir/ >/var/qmail/control/defaultdelivery
mv /usr/local/src/qmailctl /var/qmail/bin/
chmod 755 /var/qmail/bin/qmailctl
ln -s /var/qmail/bin/qmailctl /usr/bin
# Create the supervise
mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log
vi /var/qmail/supervise/qmail-send/run
######## Write the following section to file:/var/qmail/supervise/qmail-send/run ########
#!/bin/sh
exec /var/qmail/rc
######## End ########
vi /var/qmail/supervise/qmail-send/log/run
######## Write the following section to file:/var/qmail/supervise/qmail-send/log/run ########
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail
######## End ########
vi /var/qmail/supervise/qmail-smtpd/run
######## Write the following section to file:/var/qmail/supervise/qmail-smtpd/run ########
#!/bin/sh
QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
LOCAL=`head -1 /var/qmail/control/me`
if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; then
echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
echo /var/qmail/supervise/qmail-smtpd/run
exit 1
fi
if [ ! -f /var/qmail/control/rcpthosts ]; then
echo "No /var/qmail/control/rcpthosts!"
echo "Refusing to start SMTP listener because it'll create an open relay"
exit 1
fi
exec /usr/local/bin/softlimit -m 2000000 \
/usr/local/bin/tcpserver -v -R -l "$LOCAL" -x /etc/tcp.smtp.cdb -c "$MAXSMTPD" \
-u "$QMAILDUID" -g "$NOFILESGID" 0 smtp /var/qmail/bin/qmail-smtpd 2>&1
######## End ########
echo 20 > /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming
vi /var/qmail/supervise/qmail-smtpd/log/run
######## Write the following section to file:/var/qmail/supervise/qmail-smtpd/log/run ########
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd
######## End ########
chmod +t /var/qmail/supervise/qmail-send
chmod +t /var/qmail/supervise/qmail-smtpd
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
mkdir -p /var/log/qmail/smtpd
chown qmaill /var/log/qmail /var/log/qmail/smtpd
ln -s /var/qmail/supervise/* /service/
# Allow the local host to inject mail via SMTP:
echo '127.:allow,RELAYCLIENT=""' >>/etc/tcp.smtp
qmailctl cdb
# Stop and disable the installed MTA:
/etc/init.d/sendmail stop
/sbin/init.d/sendmail stop
/etc/rc.d/init.d/sendmail stop
# Uninstall the sendmail:
rpm -e --nodeps sendmail
# Verify that nothing is listening to the SMTP port (25):
netstat -a | grep smtp
# If something is running, make sure it's not qmail by doing:
qmailctl stop
# The repeat the netstat check:
netstat -a | grep smtp
# Replace any existing /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
# Create these aliases "stone":
echo stone > /var/qmail/alias/.qmail-root
echo stone > /var/qmail/alias/.qmail-postmaster
ln -s .qmail-postmaster /var/qmail/alias/.qmail-mailer-daemon
chmod 644 /var/qmail/alias/.qmail-root /var/qmail/alias/.qmail-postmaster
# Start qmail service:
qmailctl start
# Now qmail should now be running. You can run "qmailctl stat" to verify that the services are up and running:
# qmailctl stat
# And run "qmailctl cdb" to reload the /etc/tcp.smtp
# qmailctl cdb
mkdir /var/qmail/supervise/qmail-pop3d
vi /var/qmail/supervise/qmail-pop3d/run
######## Write the following section to file:/var/qmail/supervise/qmail-pop3d/run ########
#!/bin/sh
exec /usr/local/bin/softlimit -m 3000000 \
/usr/local/bin/tcpserver -v -R -H -l 0 0 110 /var/qmail/bin/qmail-popup \
mail.myqmail.com /home/vpopmail/bin/vchkpw /var/qmail/bin/qmail-pop3d Maildir 2>&1
######## End ########
mkdir /var/qmail/supervise/qmail-pop3d/log
vi /var/qmail/supervise/qmail-pop3d/log/run
######## Write the following section to file:/var/qmail/supervise/qmail-pop3d/log/run ########
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t \
/var/log/qmail/pop3d
######## End ########
mkdir /var/log/qmail/pop3d
chown qmaill /var/log/qmail/pop3d
chmod 755 /var/qmail/supervise/qmail-pop3d/run
chmod 755 /var/qmail/supervise/qmail-pop3d/log/run
ln -s /var/qmail/supervise/qmail-pop3d /service
vi /var/qmail/bin/qmailctl
######## Add the following section to "start" part of the file:/var/qmail/bin/qmailctl ########
if svok /service/qmail-pop3d ; then
svc -u /service/qmail-pop3d /service/qmail-pop3d/log
else
echo qmail-pop3d supervise not running
fi
######## End ########
######## Add the following section to "stop" part of the file:/var/qmail/bin/qmailctl ########
echo " qmail-pop3d"
svc -d /service/qmail-pop3d /service/qmail-pop3d/log
######## End ########
######## Add the following section to "stat" part of the file:/var/qmail/bin/qmailctl ########
svstat /service/qmail-pop3d
svstat /service/qmail-pop3d/log
######## End ########
######## Add the following section to "pause" part of the file:/var/qmail/bin/qmailctl ########
echo "Pausing qmail-pop3d"
svc -p /service/qmail-pop3d
######## End ########
######## Add the following section to "cont" part of the file:/var/qmail/bin/qmailctl ########
echo "Continuing qmail-pop3d"
svc -c /service/qmail-pop3d
######## End ########
######## Add the following section to "restart" part of the file:/var/qmail/bin/qmailctl ########
echo "* Restarting qmail-pop3d."
svc -t /service/qmail-pop3d /service/qmail-pop3d/log
######## End ########
# Test the Installation:
cd /usr/local/src
sh inst_check
# When everything looks right, inst_check will report:
# Congratulations, your LWQ installation looks good!
################################
# Install mysql
################################
groupadd mysql
useradd -g mysql mysql
cd /usr/local
tar -xvzf /usr/local/src/mysql-standard-4.0.20-pc-linux-i686.tar.gz
ln -s mysql-standard-4.0.20-pc-linux-i686 mysql
cd mysql
scripts/mysql_install_db
cd ..
chown -R root.mysql mysql-standard-4.0.20-pc-linux-i686
chmod -R 640 mysql
chmod -R u+X,g+X mysql
chmod -R ug+x mysql/bin
chmod -R g+w mysql/data
chmod -R u+x mysql/scripts
cp /usr/local/mysql/support-files/my-medium.cnf /usr/local/mysql/data/my.cnf
chgrp mysql /usr/local/mysql/data/my.cnf
cd /usr/local/mysql
bin/safe_mysqld --user=mysql &
# Set the root password
/usr/local/mysql/bin/mysqladmin -u root password 'secret'
# Configure MySQL so it is running all the time from bootup onwards
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
chmod 744 /etc/rc.d/init.d/mysql
chkconfig --add mysql
################################
# Install apache
################################
cd /usr/local/src
chown -R root.root apache_1.3.31.tar.gz
tar -xvzf apache_1.3.31.tar.gz
groupadd www
useradd -g www www
cd /usr/local/src/apache_1.3.31
./configure \
--prefix=/usr/local/apache \
--enable-module=so \
--enable-module=rewrite \
--enable-shared=rewrite \
--server-uid=www \
--server-gid=www
make
make install
################################
# Install php
################################
cd /usr/local/src
tar -xvzf php-4.3.7.tar.gz
chown -R root.root php-4.3.7.tar.gz
cd php-4.3.7
./configure \
--with-mysql=/usr/local/mysql \
--with-apxs=/usr/local/apache/bin/apxs
make
make install
cp php.ini-dist /usr/local/lib/php.ini
vi /usr/local/lib/php.ini
######## Modify the /usr/local/lib/php.ini file and make sure it contains the following commands. ########
max_execution_time=60
memory_limit=10M
post_max_size=8M
upload_max_filesize=8M
file_uploads=On
log_errors=On
error_log=/usr/local/apache/logs/php_error_log
######## End ########
chown -R root.www /usr/local/lib/php
chmod -R g-w,o-rwx /usr/local/lib/php
vi /usr/local/apache/conf/httpd.conf
######## Modify the /usr/local/apache/conf/httpd.conf file and make sure it contains the following commands. ########
User www
Group www
ServerAdmin postmaster@myqmail.com
ServerName mail.five-star.cn
# Following line should be present already as it would be inserted by the PHP make
# Make sure you move it outside of the IfDefineSSL section if the make (incorrectly) put it there
LoadModule php4_module libexec/libphp4.so
# uncomment (or add) the following line
AddType application/x-httpd-php .php
# Add the index.php into this line so apache will use this file as a default in addition to index.html
DirectoryIndex index.php index.html
######## End ########
rm -Rf /usr/local/apache/htdocs/*
rm -f /usr/local/apache/index.html.*
rm -Rf /usr/local/apache/cgi-bin/*
cd /usr/local
chown -R root.root apache
chmod 755 apache
chmod -R 600 apache/*
chmod -R u+X apache
cd apache
chmod -R u+x bin
chgrp -R www cgi-bin
chmod -R u+x,g+x cgi-bin
chgrp -R www icons
chmod -R g+rX icons
chgrp -R www logs
chmod g+wX logs
chgrp -R www htdocs
chmod -R g+rX htdocs
# Run apache every time at bootup.
rm -rf /etc/rc.d/init.d/httpd
vi /etc/rc.d/init.d/httpd
######## Create the /etc/rc.d/init.d/httpd file with the following commands. ########
#!/bin/sh
#
# Startup script for the Apache Web Server
#
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# Source function library.
./etc/rc.d/init.d/functions
# See how we were called.
case "$1" in
start)
echo -n "Starting httpd: "
daemon /usr/local/apache/bin/httpd
echo
touch /var/lock/subsys/httpd
;;
stop)
echo -n "Shutting down http: "
killproc httpd
echo
rm -f /var/lock/subsys/httpd
rm -f /var/run/httpd.pid
;;
status)
status httpd
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reloading httpd: "
killproc httpd -HUP
echo
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
######## End ########
chown root.root /etc/rc.d/init.d/httpd
chmod 744 /etc/rc.d/init.d/httpd
chkconfig --add httpd
################################
# Install vpopmial
################################
groupadd vchkpw
useradd -g vchkpw vpopmail
cd /usr/local/src
tar -xvzf vpopmail-5.4.0.tar.gz
chown -R root.root vpopmail-5.4.0
cd vpopmail-5.4.0
mkdir ~vpopmail/etc
chown vpopmail.vchkpw ~vpopmail/etc
echo "localhost|0|vpopmailuser|vpoppasswd|vpopmail" > ~vpopmail/etc/vpopmail.mysql
chown vpopmail.vchkpw ~vpopmail/etc/vpopmail.mysql
chmod 640 ~vpopmail/etc/vpopmail.mysql
/usr/local/mysql/bin/mysql --password="secret"
CREATE DATABASE vpopmail;
GRANT select,insert,update,delete,create,drop ON vpopmail.* TO vpopmailuser@localhost IDENTIFIED BY 'vpoppasswd';
quit
./configure \
--disable-roaming-users \
--enable-logging=p \
--disable-passwd \
--enable-clear-passwd \
--disable-domain-quotas \
--enable-auth-module=mysql \
--disable-many-domains \
--enable-auth-logging \
--enable-mysql-logging \
--enable-valias \
--disable-mysql-limits
make
make install-strip
vi ~vpopmail/etc/vlimits.default
default_quota 20971520 # Set the mail box default size 20M.
echo "myqmail.com" > /home/vpopmail/etc/defaultdomain
# Setup the quota warning message that is sent to users when they are at 90% quota.
vi quotawarn.msg
######## Create the quotawarn.msg file with the following commands. ########
From: SomeCompany Postmaster <postmaster@myqmail.com>
Reply-To: postmaster@myqmail.com
To: SomeCompany User:;
Subject: Mail quota warning
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit
Your mailbox on the server is now more than 90% full.
So that you can continue to receive mail,
you need to remove some messages from your mailbox.
If you require assistance with this,
please contact our support department :
email : support@myqmail.com
Tel : xx xxxx xxxx
######## End ########
cp quotawarn.msg /home/vpopmail/domains/.quotawarn.msg
echo "Message rejected. Not enough storage space in user's mailbox to accept message." > /home/vpopmail/domains/.over-quota.msg
# add a domain
/home/vpopmail/bin/vadddomain myqmail.com myqmail
# add a test account
/home/vpopmail/bin/vadduser stone@myqmail.com stone
# delete a user
# /home/vpopmail/bin/vdeluser stone@myqmail.com
# delete a domain
# /home/vpopmail/bin/vdeldomain myqmail.com
################################
# Install autoresponder
################################
cd /usr/local/src
tar -xvzf autorespond-2.0.4.tar.gz
chown -R root.root autorespond-2.0.4
cd autorespond-2.0.4
make
make install
################################
# Install ezmlm / ezmlm-idx
################################
cd /usr/local/src
tar -xvzf ezmlm-0.53.tar.gz
chown -R root.root ezmlm-0.53
cd /usr/local/src
tar -xvzf ezmlm-idx-0.40.tar.gz
chown -R root.root ezmlm-idx-0.40
cp -R ezmlm-idx-0.40/* ezmlm-0.53/
# (you need to press y quite a few times to allow the patch files to overwrite the original files)
cd ezmlm-0.53
patch < idx.patch
patch -p1 < ../ezmlm-idx-0.53.400.unified_41.patch
make
make man
make setup
################################
# Install qmailadmin
################################
cd /usr/local/src
tar -xvzf qmailadmin-1.2.0.tar.gz
chown -R root.root qmailadmin-1.2.0
cd qmailadmin-1.2.0
./configure \
--enable-htmldir=/usr/local/apache/htdocs \
--enable-cgibindir=/usr/local/apache/cgi-bin \
--enable-maxusersperpage=12 \
--enable-maxaliasesperpage=12 \
--enable-modify-quota \
--disable-ezmlm-mysql \
--disable-help
make
make install-strip
# Chinese qmailadmin
# Backup the orginal files.
mv /usr/local/share/qmailadmin/lang/en /usr/local/share/qmailadmin/lang/en_bak
mv /usr/local/src/qmailadmin_zh /usr/local/share/qmailadmin/lang/en
# Test the qmailadmin
http://mail.myqmail.com/cgi-bin/qmailadmin
################################
# Install sqwebmail
################################
cd /usr/local/src
tar -xvzf sqwebmail-3.5.3.tar.gz
chown -R root.root sqwebmail-3.5.3.tar.gz
cd sqwebmail-3.5.3
./configure \
--without-authpwd --without-authshadow --without-authpam \
--without-authuserdb --without-authldap --without-authdaemon \
--with-authvchkpw --with-fcgi --enable-unicode=gb2312 \
--enable-webpass=vpopmail \
--enable-cgibindir=/usr/local/apache/cgi-bin \
--enable-imagedir=/usr/local/apache/htdocs/images/webmail \
--enable-mimetypes=/usr/local/apache/htdocs \
--enable-mimecharset=gb2312 \
--with-defaultlang=zh
make
make install
make install-configure
cp -a /usr/local/apache/htdocs/images/webmail /usr/local/apache/htdocs/
mv -f /usr/local/src/zh-cn/* /usr/local/share/sqwebmail/html/zh-cn
mv /usr/local/src/images/webmail/* /usr/local/apache/htdocs/images/webmail/
# Test the webmail
http://mail.myqmail.com/cgi-bin/sqwebmail
Download the source
* qmail, http://www.qmail.org/netqmail-1.05.tar.gz
* ucspi-tcp, ftp://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
* daemontools, ftp://cr.yp.to/daemontools/daemontools-0.76.tar.gz
References:
http://www.lifewithqmail.org/lwq.html
http://www.pipeline.com.au/staff/mbowe/isp/webmail-server.htm
http://cr.yp.to
If any questions, welcome to email to me: lockbox@163.com
,