当前位置:Linux教程 - Linux - Qmail实例配置详解

Qmail实例配置详解

Qmail 1.03+Courier+vpopmail+mysql+qmailadmin+webmail安装指南

对这个演示的补充说明-- Qmail 1.03+Courier+vpopmail+mysql安装指南
请到http://gujian.sege.com.cn/mail2000 去看这个文档的演示,用户名:hup
密码: 12345

作者:古剑


摘要: 本文对Qmail用户实现MYSQL的数据库管理,同时实现多虚拟主域的邮件发送,支持POP3、IMAP,使系统能够实现千万级的用户负载,同时提供邮件用户的后台管理。在此基础上可以进一步实现WEBMAIL的收发,邮件列表的管理等等。以实现真正意义上的千万级用户支持和友好的用户接口的电子邮件系统。

硬件环境:x86兼容系统,内存128M,单网卡。建议Qmail、MYSQL、WEBMAIL分别安装在单独(或者多台)的机器上,以便实现海量邮件用户支持。本系统也在SUN SOLARIS 8上通过。

软件准备:
red hat linux 7.0 内核2.2.16以上
MySQL-3.23.38-1.src.rpm
qmail-1.03+patches-18.src.rpm
dot-forward-0.71.tar.gz
courier-imap-1.3.8.1.tar.gz
ucspi-tcp-0.88.tar.gz
vpopmail-4.10.21.tar.gz
apache_1.3.19.tar.gz
php-4.05.tar.gz
vqregister-2.5.tar.gz(在线帐号申请)
Webmail1.0.tar.gz
autorespond-1.0.0.tar.gz
ezmlm-idx
qmailadmin-0.45.tar.gz
注意:本文没有讲Vmailmgr的安装和配置,这里简单介绍它的安装中注意事项:
Vmailmgr 0.96.9.tar.gz
对它./configure 后必须修改config.h文件加入#include和#include才可以编译成功!

MYSQL的安装:
解压和安装
#rpm –ivh ./ MySQL-3.23.38-1.src.rpm
#mv /usr/src/redhat/SOURCES/mysql-3.23.38.tar.gz /tmp
#cd /tmp
#tar –zxvf mysql-3.23.38.tar.gz
#cd mysql-3.23.38
#./configure
#make
#make install
#scripts/mysql_install_db
#/usr/local/bin/safe_mysqld& 有时候要重新启动系统才能正常启动MYSQL。

#mysqladmin –uroot password yourpassword
#/usr/local/bin/mysqladmin -u root -p password ''new-password''
#/usr/local/bin/mysqladmin -u root -h gujian.sege.com.cn -p password ''new-passwor
d''
#echo /usr/local/mysql/bin/safe_mysqld& >> /etc/rc.d/rc.local
在/etc/ld.so.conf文件末尾添加一行:
/usr/local/lib/mysql
#ldconfig

Qmail的安装:

$TTL 86400
@ IN SOA gujian.sege.com.cn. gujian.gujian.sege.com.cn. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS gujian.sege.com.cn.
IN MX 10 gujian.sege.com.cn.

gujian IN A 192.168.0.1
@ IN A 192.168.0.1

$TTL 86400
@ IN SOA gujian.sege.com.cn. gujian.gujian.sege.com.cn. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS gujian.sege.com.cn.
IN MX 10 gujian.sege.com.cn.

mail IN A 192.168.0.1

# rpm -e --nodeps sendmail
#mkdir /var/qmail
# groupadd -g 1000 nofiles
# useradd -u 5000 -g nofiles -d /var/qmail/alias alias
# useradd -u 5001 -g nofiles -d /var/qmail qmaild
# useradd -u 5002 -g nofiles -d /var/qmail qmaill
# useradd -u 5003 -g nofiles -d /var/qmail qmailp
# groupadd -g 1001 qmail
# useradd -u 5004 -g qmail -d /var/qmail qmailq
# useradd -u 5005 -g qmail -d /var/qmail qmailr
# useradd -u 5006 -g qmail -d /var/qmail qmails

#rpm –ivh qmail-1.03+patches-18.src.rpm
# mv /usr/src/redhat/SOURCES/qmail-1.03.tar.gz /tmp
# mv /usr/src/redhat/SOURCES/qmail-1.03-big-dns.patch /tmp
# mv /usr/src/redhat/SOURCES/qmail-1.03-bind-interface.patch /tmp
#cd /tmp
#tar –zxvf qmail-1.03.tar.gz
#cd qmail-1.03
#patch –p1<../ qmail-1.03-big-dns.patch
#patch –p1 <../ qmail-1.03-bind-interface.patch
#make && make setup check
#./config
或者运行
# cd /var/qmail/control
# echo mail.sege.com.cn> me
# echo mail.sege.com.cn> defaultdomain
# echo mail.sege.com.cn> rcpthosts
# echo mail.sege.com.cn> locals
# echo mail.sege.com.cn> plusdomain
# echo localhost >> locals
# echo localhost >> rcpthosts

# ln -s /var/qmail/bin/sendmail /usr/lib/sendmail
# ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail

# cd /var/qmail/boot
# mv home ../rc
# /var/qmail/rc &
#echo /var/qmail/rc&>>/etc/rc.d/rc.local
# ps auxww | grep qmail and find the ````qmail-lspawn'''' process together with a few others. Test the
# uname -a | mail [email protected]

安装.forward兼容的转发服务:
#tar –zxvf dot-forward-0.71.tar.gz
#make setup check
#cp /var/qmail/boot/home+df /var/qmail/rc
注意必须手工将rc文件的格式修改为如下:
#!/bin/sh
exec env - PATH=""/var/qmail/bin:$PATH""
qmail-start ''|dot-forward .forward ./Maildir'' splogger qmail

这样在/home/vpopmail/domains/domainname/username/Maildir/.forward 文件就可以生效了。


安装UCSPI-TCP
# tar xzvf ucspi-tcp-0.88.tar.gz
# cd ucspi-tcp-0.88
# make && make setup check

This will compile and install ucspi-tcp files in your /usr/local directory.
建立/etc/tcp.smtp 文件,内容为
127.0.0.:allow,RELAYCLIENT=''''
192.168.1.:allow,RELAYCLIENT=''''
:allow
relay 规则建立。

# tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
让规则生效
建立SMTP服务启动脚本/usr/sbin/runsmtp,内容如下
#!/bin/sh
/usr/local/bin/tcpserver -x/etc/tcp.smtp.cdb -u5002 -g1000
0 smtp /var/qmail/bin/qmail-smtpd 2>&1
| /var/qmail/bin/splogger &
#chmod +x /usr/sbin/runsmtp
#echo /usr/sbin/runsmtp >>/etc/rc.d/rc.local
启动SMTP服务:
#/usr/sbin/runsmtp
Checking to see if it worked
Check to see if you have done everything correctly by doing this:

# telnet mail.dexterslab.net smtp You should see:
Trying 192.168.1.1...
Connected to mail.dexterslab.net.
Escape character is '']''.
220 mail.dexterslab.net ESMTP Try saying hello. Type in
HELO johnnybravo.com It should say:
250 mail.dexterslab.net Type ````quit'''' to close connection. We will do serious testing later.

设置系统别名
# cd /var/qmail/alias
# echo ''&gujian'' > .qmail-root
# echo ''&gujian'' > .qmail-toor
# echo ''&gujian'' > .qmail-postmaster
# echo ''&gujian'' > .qmail-admin
# echo ''[email protected]'' > .qmail-gujian

设置POP3:
保证系统没有开pop3服务
root@mail:# killall -HUP inetd
运行下条命令启动POP3服务:
:# /usr/local/bin/tcpserver -u0 -g0 0 110 /var/qmail/bin/qmail-popup mail.sege.com.cn /usr/local/bin/checkvpw /var/qmail/bin/qmail-pop3d Maildir 2>&1 | /var/qmail/bin/splogger &

将这条命令写入/usr/sbin/runpop文件中。
#chmod +xꗬÁ‹Љ 勸¿ က Ѐ 䱘

l Ø Ø Ø Ø Ø Ø Ø ì ⨄ ⨄ ⨄ ⨄ ⨠ Œ ì 侭 IJ ⪸ ⫎ ⫎ ⫎ ⫎ ⫎ ⫎ ⫎ ䷨ ䷪ ䷪ ䷪ ䷪ ䷪ ䷪ $ 僟 Ƞ 勿 r 与 ř Ø ⫎ ⫎ ⫎ ⫎ ⫎ 与 .smtp /home/vpopmail/etc
# tar -zxvf vpopmail-4.10.21.tar.gz
#cd vpopmail-4.10.21
#vi vmysql.h
将文件中的mysql设置为你的MYSQL配置
#crontab –e
添加以下内容:
40 * * * * /home/vpopmail/bin/clearopensmtp 2>&1 >/dev/null

#./configure --enable-roaming-users=y --enable-hardquota=100000000 --enable-default-domain=sege.com.cn --enable-mysql=y --enable-sqlincdir=/usr/local/include/mysql --enable-sqllibdir=/usr/local/lib/mysql --enable-ucspi-dir=../ucspi-tcp-0.88 --enable-passwd=n --enable-clear-passwd=y


#make
#make install
添加虚拟域:
#/home/vpopmail/bin/vadddomain sege.com.cn
#/home/vpopmail/bin/vadddomain china.com
添加虚拟用户:
/home/vpopmail/bin/vadduser [email protected]

设置支持POP3:
将/usr/sbin/runpop脚本内容改为如下内容:
/usr/local/bin/tcpserver -u vpopmail -g vchkpw 0 110 /var/qmail/bin/qmail-popu
p sege.com.cn /home/vpopmail/bin/vchkpw /var/qmail/bin/qmail-pop3d Maildir 2>&1
| /var/qmail/bin/splogger &

#killall –9 tcpserver
#/usr/sbin/runsmtp
#/usr/sbin/runpop
可以通过以下命令测试POP用户了:
#telnet mail.china.com 110
#telnet mail.sege.com.cn 110



安装IMAP 服务器:
#tar –zxvf courier-imap-1.3.8.1.tar.gz
#cd courier-imap-1.3.8.1
# ./configure --disable-root-check
#make
#make install
#cd /usr/lib/courier-imap/etc
# cp imapd.dist imapd
# cp imapd-ssl.dist imapd-ssl
编辑imapd 文件:
MAXPERIP: 40 (改4为40,让同一个IP地址最多可以有40个连接,为webmail的用户做准备的。)
AUTHMODULES:删除所有的模块,只留下authvchkpw
启动courier imap服务
# /usr/lib/courier-imap/libexec/imapd.rc start
将/usr/lib/courier-imap/libexec/imapd.rc start添加到/etc/rc.d/rc.local文件尾


配置apache+php+mysqladmin:

# gunzip -c apache_1.3.9.tar.gz | tar xf -
# cd apache_1.3.9
# ./configure
# cd ..

# gunzip -c php-4.0.x.tar.gz | tar xf -
# cd php-4.0.5
# ./configure --with-mysql --with-apache=../apache_1.3.9 --enable-track-vars --enable-gettext –disable-debug
# make
# make install
#cp php.ini-dist /usr/local/lib/php.ini

#cd ../apache_1.3.19
#./configure --prefix=/www --activate-module=src/modules/php4/libphp4.a
#make
#make install
修改/www/conf/httpd.conf文件,启动apache
#/www/bin/apachectl start

vqregister-2.5.tar.gz (Web方式的在线用户申请)
#tar –zxvf vqregister-2.5.tar.gz
#cd vqregister-2.5
# vi vqregister.conf 改为合适的配置。
以下是我的文件内容:

# vQregister configuration file
#
#

# ADMINEMAIL
#
# Syntax: AdminEmail
#
# Sets the administrative contact
# for the vQregister program. Any errors
# that are generated should contain this
# email address. See the TEMPLATE file,
# and the template files.
#

AdminEmail [email protected]

# REGISTERUSER
#
# Syntax: RegisterUser
#
# Sets the username on the domain the user
# is signing up for, that vQregister sends
# out when VERIFY is on. The domain is
# the user is signing up for is appended.
#

#RegisterUser vQregister

# SUBJECT
#
# Syntax: Subject
#
# Sets the subject of the message
# that vQregister will put on the
# outgoing message when VERIFY is on
#

#Subject Your new email account created by vQregister

# VERIFY
#
# Syntax: Verify
# Default: off
#
# Sets whether or not you want
# vqregister to verify email addresses
# by sending a randomly set password
# to the user''s current email address.
# Checking is done to see if the email
# address exists on the remote server.
#

#Verify on

# ALLOWPASSWORD
#
# Syntax: AllowPassword
# Default: off
#
# Sets whether or not users can provide
# a password at registration time, rather
# than having one generated for them. When
# this option is enabled, users do not need
# to provide a current email address, but
# if they do, an email will be sent if
# VERIFY is on. A new feature with ALLOWPASSWORD
# is that a user must also fill in a vpass
# field to verify the password they have typed.
#

AllowPassword on

# ALLOWDOMAIN
#
# Syntax: AllowDomain
#
# Sets domain.tld as registerable by
# users. Any domains not listed here,
# cannot be signed up for.
#

AllowDomain sege.com.cn
AllowDomain china.com

# REDIRECT
#
# Syntax: Redirect
#
# If you wish to redirect your users
# to a signup success page, you may
# do this with the REDIRECT identifier.
# Otherwise, the html/success.html template
# file will be outputted.
#
# Note: The redirected URL cannot support
# templates.
#

Redirect http://gujian.sege.com.cn

# PASSWORD
#
# Syntax: Password
#
# Makes all passwords given to users be
# set to . Elimates generation
# of random passwords. For use with REDIRECT.
#

# PASSWORDLEN
#
# Syntax: PasswordLen
# Default: 8
#
# Sets the length of randomly generated
# passwords.
#

PasswordLen 8

# BADHOSTS
#
# Syntax: BadHosts
#
# Defines a filename which, contains a list of email
# addresses one cannot signup from.
#
# Example file:
# hotmail.com
# .cjb.net
# yahoo.com
# lycos.com
#
# If not defined, this feature is not turned on.
#

#BadHosts badhosts

# DB_Host
#
# Syntax: DB_Host
#
# Set where to connect for the
# database.
#

#DB_Host localhost

# DB_Name
#
# Syntax: DB_Name
#
# Defines the database name to use
# when storing demographic, or other
# information.
#

#DB_Name user_store

# DB_USER
#
# Syntax: DB_User
#
# Sets the username to use when
# connecting to the database
#

#DB_User root

# DB_PASSWORD
#
# Syntax: DB_Password
#
# Defines the password for the
# database.
#
# Note: Databases are created if they do not exist (if able)
#

#DB_Password inter7

# DB_FIELDS
#
# Syntax: DB_Fields [,[,]]
#

#DB_Fields user_info user,dom,pass,cemail,fname

# ADVERTISE
#
# Syntax: Advertise
# Default: on
#
# We''re silly. Turn this off to turn off the advertisement
# at the end of the outgoing email when VERIFY is on.
#

#Advertise on
修改html目录下的文件,使他们合适你的站点。
修改Makefile文件,
将LIBS = -L$(VDIR)/lib -lvpopmail -lcrypt -L/usr/local/mysql/lib/mysql -lmysqlclie
nt
改为:LIBS = -L$(VDIR)/lib -lvpopmail -lcrypt -L/usr/local/lib/mysql -lmysqlclie
nt
#make
#make install
#cp –r /usr/local/apache/cgi-bin/vqregister /www/cgi-bin/
http://gujian.sege.com.cn/cgi-bin/vqregister/vqregister.cgi


安装WEBMAIL:
#cd /www/html
#tar –zxvf webmail.tar.gz
修改/www/webmail/config.php文件以适合你的站点就可以了。


总结:
由于本人才疏学浅错误之处难免,请大家指教。