一、下载软件包
qmail, ftp://cr.yp.to/software/qmail-1.03.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 ·
vpopmail http://www.inter7.com/vpopmail/vpopmail-5.2.1.tar.gz
mysql
二、安装
1、准备安装文件和目录
su
umask 022
mkdir -p /usr/local/src
mv qmail-1.03.tar.gz ucspi-tcp-0.88.tar.gz /usr/local/src
mkdir -p /package
mv daemontools-0.76.tar.gz /package
chmod 1755 /package
2、解压文件
cd /usr/local/src
tar -xzf qmail-1.03.tar.gz
tar -xzf ucspi-tcp-0.88.tar.gz
cd /package
tar -xzf daemontools-0.76.tar.gz
3、安装qmail
mkdir /var/qmail 创建qmail安装目录
#mkdir /etc/qmail
#ln -s /etc/qmail /var/qmail/control
阅读INSTALL.ids文件。根据要求创建安装qmail所需要的用户组
groupadd nofiles
useradd qmaild -g nofiles -d /var/qmail -s /nonexistent
useradd alias -g nofiles -d /var/qmail/alias -s /nonexistent
useradd qmaill -g nofiles -d /var/qmail -s /nonexistent
useradd qmailp -g nofiles -d /var/qmail -s /nonexistent
groupadd qmail
useradd qmailq -g qmail -d /var/qmail -s /nonexistent
useradd qmailr -g qmail -d /var/qmail -s /nonexistent
useradd qmails -g qmail -d /var/qmail -s /nonexistent
#build qmail source
cd /usr/local/src/qmail-1.03
make setup check
./config or ./config-fast mail2.fugui.cn
4、安装vpopmail(需要mysql数据库)
1、添加用户和组 vpopmail/vchkpw
groupadd -g 89 vchkpw
useradd -g vchkpw -u 89 vpopmail
2、准备软件包
tar xzf vpopmail-5.3.23.tar.gz
chown -R root.root vpopmail-5.3.23
cd vpopmail-5.3.23
3、在vpopmail的源文件中设置对mysql的支持
修改vmysql.h中的下面几行。
#define MYSQL_UPDATE_USER "vpopmailuser"
#define MYSQL_UPDATE_PASSWD "vpoppasswd"
#define MYSQL_READ_USER "vpopmailuser"
#define MYSQL_READ_PASSWD "vpoppasswd“
4、在mysql中创建数据库并进行用户授权
mysql --password="mysql-root-pwd"
CREATE DATABASE vpopmail;
GRANT select,insert,update,delete,create,drop ON vpopmail.*
TO vpopmailuser@localhost IDENTIFIED BY 'vpoppasswd';
quit
5、编译vpopmail
./configure --enable-roaming-users=y \ #这里用y也许可以支持有选择的relay
--enable-logging=p --enable-defaultquota=20971520S --enable-ip-alias-domains=n --enable-passwd=n --enable-clear-passwd=y --enable-domain-quotas=n --enable-mysql=y --enable-incdir=/usr/local/mysql/include --enable-libdir=/usr/local/mysql/lib --enable-many-domains=n --enable-auth-logging=y --enable-mysql-logging=y --enable-valias=y --enable-mysql-limits=n
make
make install-strip
5、安装ucspi-tcp
cd /usr/local/src/ucspi-tcp-0.88
make
make setup check
6、安装daemontools
cd /package/admin/daemontools-0.76
package/install
#安装完后可以验证
1、 ps -ef | grep svscan
2、 在/etc/inittab 中增加以下行SV:123456:respawn:/command/svscanboot
7、准备启动管理qmail的脚本
/var/qmail/supervise/qmail-send/run
\log/run
\qmail-smtpd/run
\log/run
\qmail-pop3d/run
\log/run
/var/qmail/rc
1、/var/qmail/rc的创建,采用qmail-local来分发信件
#!/bin/sh
# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver
exec env - PATH="/var/qmail/bin:$PATH" qmail-start "`cat /var/qmail/control/defaultdelivery`"
chmod 755 /var/qmail/rc
#决定默认的邮箱类型。而非由.qmail分发类型
mailbox format name location defaultdelivery
mbox Mailbox $HOME ./Mailbox
maildir Maildir $HOME ./Maildir/
mbox username /var/spool/mail 可以参看INSTALL.vsm
#要使用/var/spool/mail邮箱类型可以使用/var/qmail/boot/proc 作为rc脚本
echo ./Maildir/ >/var/qmail/control/defaultdelivery
2、/var/qmail/bin/qmailctl控制脚本
Create the qmailctl file by vi /var/qmail/bin/qmailctl
#!/bin/sh
# For Red Hat chkconfig
# chkconfig: - 30 80
# description: the qmail MTA
PATH=/var/qmail/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH
QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
case "$1" in
start)
echo "Starting qmail"
if svok /service/qmail-send ; then
svc -u /service/qmail-send /service/qmail-send/log
#调用/var/qmail/supervice/qmail-send/run
else
echo qmail-send service not running
fi
if svok /service/qmail-smtpd ; then #调用/var/qmail/supervice/qmail-smtpd/run
svc -u /service/qmail-smtpd /service/qmail-smtpd/log
else
echo qmail-smtpd service not running
fi
if [ -d /var/lock/subsys ]; then
touch /var/lock/subsys/qmail
fi
if svok /service/qmail-pop3d ; then #调用/var/qmail/supervice/qmail-pop3d/run
svc -u /service/qmail-pop3d /service/qmail-pop3d/log
else
echo qmail-pop3d service not running
fi
;;
stop)
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
fi
echo " qmail-pop3d"
svc -d /service/qmail-pop3d /service/qmail-pop3d/log
;;
stat)
svstat /service/qmail-send
svstat /service/qmail-send/log
svstat /service/qmail-smtpd
svstat /service/qmail-smtpd/log
qmail-qstat
svstat /service/qmail-pop3d
svstat /service/qmail-pop3d/log
;;
doqueue|alrm|flush)
echo "Sending ALRM signal to qmail-send."
svc -a /service/qmail-send
;;
queue)
qmail-qstat
qmail-qread
;;
reload|hup)
echo "Sending HUP signal to qmail-send."
svc -h /service/qmail-send
;;
pause)
echo "Pausing qmail-send"
svc -p /service/qmail-send
echo "Pausing qmail-smtpd"
svc -p /service/qmail-smtpd
echo "Pausing qmail-pop3d"
svc -p /service/qmail-pop3d
;;
cont)
echo "Continuing qmail-send"
svc -c /service/qmail-send
echo "Continuing qmail-smtpd"
svc -c /service/qmail-smtpd
echo "Continuing qmail-pop3d"
svc -c /service/qmail-pop3d
;;
restart)
echo "Restarting qmail:"
echo "* Stopping qmail-smtpd."
svc -d /service/qmail-smtpd
echo "* Sending qmail-send SIGTERM and restarting."
svc -t /service/qmail-send
echo "* Restarting qmail-smtpd."
svc -u /service/qmail-smtpd
echo "* Restarting qmail-pop3d."
svc -t /service/qmail-pop3d
;;
cdb)
tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
chmod 644 /etc/tcp.smtp.cdb
echo "Reloaded /etc/tcp.smtp."
;;
help)
cat <<HELP
stop -- stops mail service (smtp connections refused, nothing goes out)
start -- starts mail service (smtp connection accepted, mail can go out)
pause -- temporarily stops mail service (smtp connections accepted, but nothing leaves)
cont -- continues paused mail service
stat -- displays status of mail service
cdb -- rebuild the tcpserver cdb file for smtp
restart -- stops and restarts smtp, sends qmail-send a TERM & restarts it
doqueue -- sends qmail-send ALRM, scheduling queued messages for delivery
reload -- sends qmail-send HUP, rereading locals and virtualdomains
queue -- shows status of queue
alrm -- same as doqueue
flush -- same as doqueue
hup -- same as reload
HELP
;;
*)
echo "Usage: $0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help}"
exit 1
;;
esac
exit 0
> chmod 755 /var/qmail/bin/qmailctl
> ln -s /var/qmail/bin/qmailctl /etc/init.d/qmail
> ln -s /var/qmail/bin/qmailctl /usr/bin/qmailctl
##其余的一些脚本
#建立脚本的目录
mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log
mkdir -p /var/qmail/supervise/qmail-pop3d/log
1>/var/qmail/supervise/qmail-send/run脚本
#!/bin/sh
exec /var/qmail/rc
2>/var/qmail/supervise/qmail-send/log/run
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail
**multilog 是daemontools中的一个工具。t告诉在每条日志记录前加上@timestamp
**multilog script
**multilog /var/log/qmail 表示可以在此目录添加日志内容。当前日志为current
**以及一些老的日志文件。当日志足够大的时候(默认为99999=96k)的时候把current
**更名为老文件。日志文件大小可以用设置。也可以设置最多保留多少份日志默认为
**10
**multilog t /dir sszie nnum
**setuidgid username child 就是以username的身份执行child
3>/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 "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
###softlimit 工具 softlimit opts child 限制child运行时的soft resource
###tcpserver opts host port prog
###tcpserver等待客户连接,然后运行prog 服务的地址由host 和 port 给出,host可
##以是0,这样就允许连接到任何本地ip.
##options 分为3类[常规选项,连接选项,数据收集选项]
-v : 输出详细的错误信息 [常规选项]
-R : 不去查询远端主机的信息 [数据收集选项]
-l $LOCAL 设置本地主机名 [数据收集选项]
-x cdb 定义如何设置环境变量或者拒绝某类连接
-c n 定义允许的最大连接数
-u uid
-g gid 以用户和组的身份运行prog
-H 不查询客户端域名
echo 20 > /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming
4》3>/var/qmail/supervise/qmail-smtpd/log/run脚本
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd
5>/var/qmail/supervise/qmail-pop3d/run
#!/bin/sh
exec /usr/local/bin/softlimit -m 3000000 /usr/local/bin/tcpserver -v -R -H -c 30 -l hostname.yourdomain.com 0 110 /var/qmail/bin/qmail-popup hostname.yourdomain.com /home/vpopmail/bin/vchkpw /var/qmail/bin/qmail-pop3d Maildir 2>&1
6>/var/qmail/supervise/qmail-pop3d/log/run
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/pop3d
ln -s /var/qmail/supervise/qmail-send /service
ln -s /var/qmail/supervise/qmail-smtpd /service
ln -s /var/qmail/supervise/qmail-pop3d /service
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
chmod 755 /var/qmail/supervise/qmail-pop3d/run
chmod 755 /var/qmail/supervise/qmail-pop3d/log/run
###准备日志目录
mkdir -p /var/log/qmail/qmail-smtpd
mkdir -p /var/log/qmail/qmail-pop3d
chown qmaill /var/log/qmail /var/log/qmail/smtpd /var/log/qmail/qmail-pop3d
SMTP Access Control
Allow the local host to inject mail via SMTP:
echo '127.:allow,RELAYCLIENT=""' >>/etc/tcp.smtp
qmailctl cdb
###starting qmail
#替换sendmail程序
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
#创建必须的别名
echo dave > /var/qmail/alias/.qmail-root
echo dave > /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
smtp auth docuemnt
可以使用qmail-smtpd-auth 实现smtp auth
1、打补丁及编绎安装qmail
#wget http://members.elysium.pl/brush/qmail-smtpd-auth/dist/qmail-smtpd-auth-0.31.tar.gz
#tar zxvf qmail-1.03.tar.gz
#tar zxvf qmail-smtpd-auth-0.31.tar.gz //smtp auth补丁。
#cp qmail-smtpd-auth-0.31/base64.* qmail-1.03 //安装smtp-auth补丁,支持smtp认证
#patch -d qmail-1.03 < qmail-smtpd-auth-0.31/auth.patch
2、修改/var/qmail/supervise/qmail-smtpd/run
exec /usr/local/bin/softlimit -m 4000000 tcpserver -H -l0 -R -c 512 -x
/home/vpopmail/etc/tcp.smtp.cdb -u VPOPMAILUID -g VPOPMAILGUID 0 smtp
/var/qmail/bin/qmail-smtpd your.qmail.server.name /home/vpopmail/bin/vchkpw
/bin/true &
收集的一些常见问题
################################
如何限制附件大小:
在/var/qmail/control/databytes中写入想要限制的大小值:
#################################
###############################33
如何将进出internet的信件转发一封给某个人
你以前问过吧。
置顶的有个问题相关。
简单的办法,就是你所有的信件都转给某个用户。
再到这个用户进行过滤。
#############################################
###########################################
最好不要用raoming user方式编译,没什么好处。
auth的时候,把后面的域名去掉试试看
############################################
#########################################
最近有几封邮件无法发送出去,日志中提示说对方服务器block 掉了发送地址。可是我的qmail 还是不断的尝试,直到大概7 天后回复给发送者说无法发送,现在我要更改这个时间为2 个小时,请问有什么参数来着???
坏邮件在队列中存在时间过长?????
queuelifetime 缺省
604800 也就是7天
秒为单位
1小时 3600
#########################################