qmail的smtp与pop服务及相关日志完全解决方案
注:
1. supervise相关文件目录为/raid/var/supervise
2. log相关文件目录为/raid/var/log,该目录及子目录的所有权限为qmaill:nofiles
3. qmail软件安装目录为/raid/var/qmail
4. vpopmail软件安装目录为/raid/var/vpopmail
一、 相关程序:
1. daemontool工具包提供的svscan、supervise、mutilog、svc、setuidgid、softlimit、svstat程序。
2. ucspi-tcp工具包提供的tcpserver、tcprules程序。
二、 supervise的目录结构:(假定为/raid/var/supervise目录)
drwxr-sr-t root other qmail-pop3d
-rwxr-xr-x root other run
drwxr-sr-x root other log
-rwxr-xr-x root other run
drwxr-xr-t 4 root other qmail-send
-rwxr-xr-x root other run
drwxr-xr-x root other log
-rwxr-xr-x root other run
drwxr-xr-t root other qmail-smtpd
-rwxr-xr-x root other run
drwxr-xr-x root other log
-rwxr-xr-x root other run
三、各目录相关run文件:
1. /raid/var/supervise/qmail-pop3d/run文件:
#!/bin/sh
exec /usr/local/bin/tcpserver -H -R -v 0 pop3
/raid/var/qmail/bin/qmail-popup gzmail.ezhong.com
/raid/var/vpopmail/bin/vchkpw
/raid/var/qmail/bin/qmail-pop3d Maildir 2>&1
2. /raid/var/supervise/qmail-pop3d/log/run文件:
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill
/usr/local/bin/multilog t /raid/var/log/pop3d
3. /raid/var/supervise/qmail-send/run文件:
#!/bin/sh
exec env - PATH=""/raid/var/qmail/bin:$PATH""
qmail-start ``cat /raid/var/qmail/control/defaultdelivery``
Note:
使用以下命令建立defaultdelivery文件,举例如下:
echo ./Maildir/ >/raid/var/qmail/control/defaultdelivery
MailboxFormat---Name-----Location---defaultdelivery
mbox Mailbox $HOME ./Mailbox
maildir Maildir $HOME ./Maildir/
4. /raid/var/supervise/qmail-send/log/run文件:
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill
/usr/local/bin/multilog t /raid/var/log/qmail
5. /raid/var/supervise/qmail-smtpd/run文件:
#!/bin/sh
QMAILDUID=``/usr/xpg4/bin/id -u qmaild``
NOFILESGID=``/usr/xpg4/bin/id -g qmaild``
MAXSMTPD=``cat /raid/var/qmail/control/concurrencyincoming``
exec /usr/local/bin/softlimit -m 4000000
/usr/local/bin/tcpserver -v -p -x /etc/tcp.smtp.cdb -c ""$MAXSMTPD""
-u ""$QMAILDUID"" -g ""$NOFILESGID"" 0 smtp /raid/var/qmail/bin/qmail-smtpd 2>&1
Note:
A.建立concurrencyincoming控制文件:
echo 20 > /raid/var/qmail/control/concurrencyincoming
chmod 644 /raid/var/qmail/control/concurrencyincoming
B.建立SMTP访问控制文件:
echo 127.:allow,RELAYCLIENT="""" >>/etc/tcp.smtp
/etc/init.d/qmail cdb
6. /raid/var/supervise/qmail-smtpd/log/run文件:
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /raid/var/log/smtpd
四、qmail的启动脚本:(假定为/etc/init.d/qmail文件)
#!/usr/bin/sh
PATH=/raid/var/qmail/bin:/usr/local/bin:/usr/bin:/bin
export PATH
case ""$1"" in
start)
echo ""Starting qmail (smtpd+pop3d) & logging: svscan""
cd /raid/var/supervise
nohup env - PATH=""$PATH"" svscan &
echo $! > /raid/var/pid/svscan.pid
;;
stop)
echo ""Stopping qmail (smtpd+pop3d) & logging: svscan""
kill ``cat /raid/var/pid/svscan.pid``
/usr/local/bin/svc -dx /raid/var/supervise/qmail-smtpd
/usr/local/bin/svc -dx /raid/var/supervise/qmail-send
/usr/local/bin/svc -dx /raid/var/supervise/qmail-pop3d
/usr/local/bin/svc -dx /raid/var/supervise/qmail-smtpd/log
/usr/local/bin/svc -dx /raid/var/supervise/qmail-send/log
/usr/local/bin/svc -dx /raid/var/supervise/qmail-pop3d/log
;;
stat)
/usr/local/bin/svstat /raid/var/supervise/qmail-smtpd
/usr/local/bin/svstat /raid/var/supervise/qmail-send
/usr/local/bin/svstat /raid/var/supervise/qmail-pop3d
/usr/local/bin/svstat /raid/var/supervise/qmail-smtpd/log
/usr/local/bin/svstat /raid/var/supervise/qmail-send/log
/usr/local/bin/svstat /raid/var/supervise/qmail-pop3d/log
;;
doqueue|alrm)
echo ""Sending ALRM signal to qmail-send. Scheme send mail queue.""
/usr/local/bin/svc -a /raid/var/supervise/qmail-send
;;
queue)
/raid/var/qmail/bin/qmail-qstat
/raid/var/qmail/bin/qmail-qread
;;
reload|hup)
echo ""Sending HUP signal to qmail-send. Reload: locals & virtualdomains""
/usr/local/bin/svc -h /raid/var/supervise/qmail-send
;;
pause)
echo ""Pausing qmail-send""
/usr/local/bin/svc -p /raid/var/supervise/qmail-send
echo ""Pausing qmail-smtpd""
/usr/local/bin/svc -p /raid/var/supervise/qmail-smtpd
echo ""Pausing qmail-pop3d""
/usr/local/bin/svc -p /raid/var/supervise/qmail-pop3d
;;
cont)
echo ""Continuing qmail-send""
/usr/local/bin/svc -c /raid/var/supervise/qmail-send
echo ""Continuing qmail-smtpd""
/usr/local/bin/svc -c /raid/var/supervise/qmail-smtpd
echo ""Continuing qmail-pop3d""
/usr/local/bin/svc -c /raid/var/supervise/qmail-pop3d
;;
restart)
echo ""Restarting qmail ......""
echo ""+++ Stopping qmail-smtpd.""
/usr/local/bin/svc -d /raid/var/supervise/qmail-smtpd
echo ""+++ Stopping qmail-pop3d.""
/usr/local/bin/svc -d /raid/var/supervise/qmail-pop3d
echo ""+++ Sending qmail-send SIGTERM and restarting.""
/usr/local/bin/svc -t /raid/var/supervise/qmail-send
echo ""+++ Restarting qmail-smtpd.""
/usr/local/bin/svc -u /raid/var/supervise/qmail-smtpd
echo ""+++ Restarting qmail-pop3d.""
/usr/local/bin/svc -u /raid/var/supervise/qmail-pop3d
;;
cdb)
/usr/local/bin/tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
chmod 644 /etc/tcp.smtp
echo ""Reloaded /etc/tcp.smtp.""
;;
help)
cat < stop -- Stopping qmail(smtpd+pop3d)
start -- Starting qmail (smtpd+pop3d)
pause -- temporarily stops mail service(connections accepted, 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,pop3, 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 qmail queue
alrm -- same as doqueue
HELP
;;
*)
echo ""Usage: $0 {start|stop|restart|doqueue|reload|stat|pause|cont|cdb|queue|help}""
exit 1
;;
esac
exit 0
建立日志目录:
mkdir /raid/var/log: 所有者为qmail:nofiles 权限为755
注:其下的子目录pop3d、qmail、stmpd为mutilog自动构造。
建立进程ID号存放目录:
mkdir /raid/var/pid