Qmail+vpopmail+daemontools+ucspi邮件系统安装及其SMTP认证配置

    最近线上的一台qmail邮件系统因硬件出现故障,又重新部署了新的Qmail邮件系统,在网上查阅了好多关于qmail安装资料,下面是我整理的qmail安装和SMTP认证配置文档。

准备条件:
系统:centos 5.5 64位
安装qmail邮件系统依赖的相关软件包
yum install g++ gcc-g++ gdbm gdbm-devel openssl openssl-devel stunnel krb5-devel bzip2 bzip2-devel
然后删除系统自带的邮件系统,以免安装受影响
rpm -e --nodeps sendmail postfix

mkdir -p /var/src/qmail
软件包:
qmail           http://www.qmail.org/netqmail-1.05.tar.gz
ucspi-tcp       http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tat.gz
daemontools     http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
vpopmail        http://shupp.org/software/vpopmail-5.4.10.tar.gz

安装netqmail
cd ../
tar -zxvf qmail/netqmail-1.05.tar.gz
cd netqmail-1.05
./collate.sh

安装daemontools
mkdir -p /package
chmod 1755 /package
cd /package
tar -zxvf /var/src/qmail/daemontools-0.76.tar.gz
cd admin/daemontools-0.76
patch -p1 < /var/src/netqmail-1.05/other-patches/daemontools-0.76.errno.patch
package/install

安装ucspi-tcp
cd /var/src/
tar -zxvf qmail/ucspi-tcp-0.88.tar.gz
cd ucspi-tcp-0.88
patch -p1 < /var/src/netqmail-1.05/other-patches/ucspi-tcp-0.88.errno.patch
make
make setupcheck

设置qmail文件目录用户及其用户组
mkdir /var/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 /var/src
tar -zxvf qmail/toaster-scripts-0.8.tar.gz
cd netqmail-1.05/netqmail-1.05/
ln -s 
/usr/include/ /usr/kerberos/include/
rm /usr/sbin/sendmail
make
make setup check

注意qmail的补丁将在vpopmail安装以后打
打开SPF checking
echo 3 > /var/qmail/control/spfbehavior
cd ~alias; echo "admin@test.com" > .qmail-postmaster
echo "admin@test.com" > .qmail-mailer-daemon
echo "admin@test.com" > .qmail-root
chmod 644 ~alias/.qmail*
./config-fast mail.test.com   你可以填写你实际邮件服务器的域名

修改qmail的man路径
Edit  /etc/man.config
Add "MANPATH /var/qmail/man"
相应脚本
cd /var/src
cp toaster-scripts-0.8/rc /var/qmail/rc
chmod 755 /var/qmail/rc
mkdir /var/log/qmail
echo ./Maildir/ >/var/qmail/control/defaultdelivery
cp toaster-scripts-0.8/qmailctl /var/qmail/bin/
chmod 755 /var/qmail/bin/qmailctl
ln -s /var/qmail/bin/qmailctl /usr/bin
ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
ln -s /var/qmail/bin/sendmail /usr/lib/sendmail
#Now create the supervise directories/scripts for the qmail services:
mkdir -p /var/qmail/supervise/qmail-send/log
mkdir -p /var/qmail/supervise/qmail-smtpd/log
mkdir -p /var/qmail/supervise/qmail-pop3d/log
mkdir -p /var/qmail/supervise/qmail-pop3ds/log
cp /var/src/toaster-scripts-0.8/send.run /var/qmail/supervise/qmail-send/run
cp /var/src/toaster-scripts-0.8/send.log.run /var/qmail/supervise/qmail-send/log/run
cp /var/src/toaster-scripts-0.8/smtpd.run /var/qmail/supervise/qmail-smtpd/run
cp /var/src/toaster-scripts-0.8/smtpd.log.run /var/qmail/supervise/qmail-smtpd/log/run
cp /var/src/toaster-scripts-0.8/pop3d.run /var/qmail/supervise/qmail-pop3d/run
cp /var/src/toaster-scripts-0.8/pop3d.log.run /var/qmail/supervise/qmail-pop3d/log/run
cp /var/src/toaster-scripts-0.8/pop3ds.run /var/qmail/supervise/qmail-pop3ds/run
cp /var/src/toaster-scripts-0.8/pop3ds.log.run /var/qmail/supervise/qmail-pop3ds/log/run
echo 20 > /var/qmail/control/concurrencyincoming
chmod 644 /var/qmail/control/concurrencyincoming
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
chmod 755 /var/qmail/supervise/qmail-pop3ds/run
chmod 755 /var/qmail/supervise/qmail-pop3ds/log/run
mkdir -p /var/log/qmail/smtpd
mkdir -p /var/log/qmail/pop3d
mkdir -p /var/log/qmail/pop3ds
chown -R qmaill /var/log/qmail
允许daemontools来启动qmail
ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /service

启动qmail服务
qmailctl start
安装vpopmail
groupadd -g 89 vchkpw
useradd -u 89 -g vchkpw vpopmail
cd /var/src
tar -zxvf qmail/vpopmail-5.4.10.tar.gz
cd vpopmail-5.4.10

./configure --enable-logging=v
make
make install-strip
echo '127.:allow,RELAYCLIENT=""' > ~vpopmail/etc/tcp.smtp
cd ~vpopmail/etc
tcprules tcp.smtp.cdb tcp.smtp.tmp < tcp.smtp

安装vpopmail启动脚本
cp ../toaster-scripts-0.8/vpopmailctl /var/qmail/bin/vpopmailctl
chmod 755 /var/qmail/bin/vpopmailctl
ln -s /var/qmail/bin/vpopmailctl /usr/bin

安装qmail的补丁
cd /var/src/netqmail-1.05/netqmail-1.05
bunzip2 -c ../../tar/qmail/qmail-toaster-0.9.2.patch.bz2 | patch -p0
make clean
make
qmailctl stop
make setup check
chown -R vpopmail:vchkpw /var/qmail/spam

重启启动qmail
qmailctl start
允许daemontools来启动vpopmail
ln -s /var/qmail/supervise/qmail-pop3d /var/qmail/supervise
/qmail-pop3ds /service
启动vpopmail
vpopmailctl start

添加域:
/home/vpopmail/bin/vadddomain test.com [系统会让用户定义域管理员密码的]
添加用户:
/home/vpopmail/bin/vadduser -q 10MB jerry@test.com

qmail SMTP 认证配置
在/var/src/netqmail-1.05/netqmail-1.05目录里面备份qmail-smtpd.c文件,然后拷贝
http://down.51cto.com/data/452396里面的qmail-smtpd.c文件到该目录下面,然后执行下面命令:
./compile qmail-smtpd.c
./load qmail-smtpd rcpthosts.c commands.c timeoutread.c timeoutwrite.c ip.c ipme.c ipalloc.c control.c constmap.c received.c date822fmt.c now.c qmail.c cdb.a fd.a wait.a datetime.a getln.a open.a sig.a case.a env.a stralloc.a alloc.a substdio.a error.a str.a fs.a auto_qmail.o `cat socket.lib`
cp qmail-smtpd /var/qmail/bin/qmail-smtpd.auth
chmod 6755 /home/vpopmail/
chmod 6755 /home/vpopmail/bin/vchkpw

测试:
root@mail netqmail-1.05]# su - qmaild -c "/var/qmail/bin/qmail-popup localhost /home/vpopmail/bin/vchkpw pwd"
+OK <24041.1323042311@localhost>
user jerry@test.com
+OK
pass jerry
/home/vpopmail/domains/test.com/jerry 如果出现用户邮件的家目录说明认证配置成功
kill 掉tcpserver进程,安装下面的方法重启tcpserver服务,其中504,503为qmaild用户的属主和属组。
/usr/local/bin/tcpserver  -H -R -l 0 -t 1  -c 100 -x /home/vpopmail/etc/tcp.smtp.cdb -u504 -g503 \
0 smtp /var/qmail/bin/qmail-smtpd.auth /home/vpopmail/bin/vchkpw /bin/true 2>&1 \
| /var/qmail/bin/splogger smtpd 3 &

必须出现下面进程SMTP认证才会成功,否则在客户端SMTP认证通不过的
[root@mail ~]# ps -auxw |grep “ tcpserver”
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
qmaild    8473  0.0  0.0   5916   564 ?        S    Dec06   0:00 /usr/local/bin/tcpserver -H -R -l 0 -t 1 -c 100 -x /home/vpopmail/etc/tcp.smtp.cdb -u504 -g503 0 smtp /var/qmail/bin/qmail-smtpd.auth /home/vpopmail/bin/vchkpw /bin/true

    标注:源码包和SMTP认证文件下载地址:http://down.51cto.com/data/452396










本文转自 sfzhang 51CTO博客,原文链接:http://blog.51cto.com/sfzhang88/852059,如需转载请自行联系原作者

上一篇:史上最全!阿里智能人机交互的核心技术解析


下一篇:为了在全球“买买买”,阿里工程师自研了一套海外HR系统