1 Postfix邮件系统介绍
1.1 Postfix邮件系统介绍
Postfix是Wietse Venema在IBM的GPL协议之下开发的MTA(邮件传输代理)软件。Postfix是Wietse Venema想要为使用最广泛的Sendmail提供替代品的一个尝试。在Internet世界中,大部分的电子邮件都是通过Sendmail来投递的,大约有100万用户使用Sendmail,每天投递上亿封邮件。这真实一个让人吃惊的数字。Postfix试图更快、更容易管理、更安全,同时还与Sendmail保持足够的兼容性。
1.2 Postfix特点
1、    Postfix是免费的:
   Postfix想要作用的范围是广大的Internet用户,试图影响大多数的Internet上的电子邮件系统,因此它是免费的。
2、    更快:
   Postfix在性能上大约比Sendmail×××倍。一部运行Postfix的台式PC每天可以收发上百万封邮件。
3、    兼容性好:
   Postfix是Sendmail兼容的,从而使Sendmail用户可以很方便地迁移到Postfix。Postfix支持/var[/spool]/mail、/etc/aliases、 NIS、和 ~/.forward 文件。
4、    更健壮:
   Postfix被设计成在重负荷之下仍然可以正常工作。当系统运行超出了可用的内存或磁盘空间时,Postfix会自动减少运行进程的数目。当处理的邮件数目增长时,Postfix运行的进程不会跟着增加。
5、    更灵活:
   Postfix是由超过一打的小程序组成的,每个程序完成特定的功能。你可以通过配置文件设置每个程序的运行参数。
6、    安全性:
   Postfix具有多层防御结构,可以有效地抵御恶意***者。如大多数的Postfix程序可以运行在较低的权限之下,不可以通过网络访问安全性相关的本地投递程序等等。
1.3 Postfix邮件系统组成及工作原理
Postfixs邮件系统是由十多个具有不同功能的模块组成,这些模块以进程的方式工作,我们可以把它们称为Postfix的功能进程,这些功能性进程都是相互协作、相互平等,它们可以为彼此提供特定的服务。大部分Postfix功能性进程由一个守护进程进行管理,该进程负责负责协调各个功能性进程间的工作,这个进程叫做master。
Postfix各个功能性进程之间的关系如下图所示:
 

【说明】
    Postfix邮件系统主要由上图中所列的功能模块组成,下面将分别描述每个功能模块在整个邮件系统中的作用:
1、 MTA:
整个邮件系统的核心,主要负责来自网络的或者本地的邮件,并根据邮件的目标地址将邮件通过MDA发送其他MTA或者保存到本地。由Postfix本身应用程序提供。
2、 MDA:
邮件传送代理,主要负责将邮件传送到目的地
3、 MAA:
一般情况下,邮件系统将用户的邮件保存在服务器上用户指定的家目录中,用户如何获取服务器上的邮件呢?这个就是MAA的主要功能,他主要为用户提供pop3/imap功能,让用户通过它来获取邮件服务器上的邮件。中间会提供一些用户身份认证的机制。
4、 MUA:
邮件用户代理,接受用户输入的各种指令,将用户的邮件发送至MTA或者通过POP3、IMAP协议将邮件从MTA取到本机。常见的MUA有Foxmail、Outlook、tundbird等邮件客户端程序。
5、 Webmail:
提供Webmail功能和后台管理功能
6、 Mailbox
MTA获取邮件之后,调用MDA将邮件保存在MAILBOX中。MAILBOX主要用来保存用户的邮件。
7、 认证系统
提供用户身份验证的功能,Postfix支持多种数据库,比较常用的有MySQL、Ldap。我们可以通过postconf –m,查看Postfix支持的数据库的类型。
8、 防病毒反垃圾邮件系统
垃圾邮件和病毒邮件已经成为整个邮件系统中公害,几乎每个邮件系统都面临着这样的问题,在Postfix我们采用业界比较出名的amavisd-new进程来调用clamad和dspam来扫描病毒和垃圾邮件。
 
2 Linux服务器系统初始化安装与配置
Ø 硬件:
CPU: Intel(R) Xeon(TM) CPU 3.00GHz
内存: 4G
磁盘:磁盘 1->73G   磁盘2->146G
Ø 操作系统
Redhat AS 5.4 x86_64

分区
大小
磁盘
说明
/boot
128M
/dev/sda
保存启动文件
/swap
8000M
/dev/sda
交换分区
/
/dev/sda剩余的所有空间
/dev/sda
 
/home
/dev/sdb 整个磁盘
/dev/sdb
用于保存用户邮件和网盘数据,应尽量大。

服务器组件
软件包
 
说明
desktops
Default
 
 
Applications
Default
 
 
server
Web Server
全选
 
Mail Server
加选 spamassassin,其它清除
 
Database
 
 
Development
全选
 
 
System-tools
全选
 
便于维护
language
Chinaese
 
 
Ø 网络设置
[root@mail ~]# hostname mail.servyou-it.com
[root@mail Server]# vi /etc/resolv.conf
search servyou-it.com
nameserver 202.101.172.46
nameserver 202.101.172.35
[root@mail Server]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
设置 IPADDR=192.168.2.37
Ø 启动项设置
[root@mail ~]#chkconfig --level 35 sendmail off
[root@mail ~]#chkconfig --level 35 iptables off
[root@mail ~]#chkconfig --level 35 ip6tables off
[root@mail ~]#service    sendmail   stop
[root@mail ~]#vi /etc/inittab 修改 --> 启动级别设置为3
[root@mail ~]#cd /
[root@mail ~]#mkdir    data
Ø 配置 yum源
[root@mail ~]#vi  /etc/yum.repos.d/ #添加 -->
[Server]
name=Red Hat Enterprise Linux Server
baseurl=ftp://192.168.2.179/pub/Server
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[VT]
name=Red Hat Enterprise Linux VT
baseurl=ftp://192.168.2.179/pub/VT
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[Cluster]
name=Red Hat Enterprise Linux Cluster
baseurl=ftp://192.168.2.179/pub/Cluster
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[ClusterStorage]
name=Red Hat Enterprise Linux ClusterStorage
baseurl=ftp://192.168.2.179/pub/ClusterStorage
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[redhatds]
name=Red Hat Enterprise Linux Directory Manager
baseurl=ftp://192.168.2.179/pub/redhatds
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
说明: 192.168.2.179的ftp上存放了REDHAT AS 5.4 x86_64操作系统的yum仓库,只需要按照上面的配置,既可以通过yum的方式安装各个软件包。
Ø 新增系统帐号,后面安装邮件系统各个组件的时候需要用到
[root@mail ~]#groupadd postfix
[root@mail ~]#useradd -g postfix -s /bin/false postfix
[root@mail ~]#groupadd postdrop
[root@mail ~]#groupadd vmail -g 1000
[root@mail ~]#useradd -u 1000 -g 1000 -M -s /sbin/nologin -d /dev/null vmail
Ø 安装 php、http及相关依赖包
[root@mail ~]#yum -y install httpd php php-mysql php-gd php-imap php-mbstring php-ldap
[root@mail ~]#yum -y install perl-Unix-Syslog \
perl-GD \
perl-Digest-SHA1 \
perl-Digest-HMAC \
perl-Net-IP \
perl-Net-DNS \
perl-Time-HiRes \
perl-HTML-Tagset \
perl-HTML-Parser \
perl-libwww-perl \
perl-IO-stringy \
perl-IO-Multiplex \
perl-Net-SSLeay-1.30 \
perl-IO-Socket-SSL \
perl-Net-Server \
perl-TimeDate \
perl-MailTools \
perl-MIME-Base64 \
perl-Convert-BinHex \
perl-MIME-tools \
perl-Convert-TNEF \
perl-Convert-UUlib \
perl-Compress-Zlib \
perl-Archive-Zip \
perl-IO-Zlib \
perl-Archive-Tar \
arc-5.21o \
oo-2.10 \
unarj
3 Postfix邮件系统各个组件的安装与配置
3.1 OpenLDAP的安装、配置及数据的初始化
3.1.1 OpenLDAP的安装
可以通过两种方式来安装,第一种是在安装系统是自已就安装了,你如果认为它的版本太低了,可以通过YUM的方式升级一下,也可以通过源代码的方式安装,我这里是通过YUM的方式简单的安装了一下,如果通过源代码安装的话,那后面的一些组件的安装时就需要注意一下路径了。
[root@mail ~]#yum –y install openldap*
3.1.2 OpenLDAP的配置
Openldap的配置文件位于 /etc/openldap/下,主要的配置文件有slapd.conf和ldap.conf。ldap配置文件主要本机ldap测试工具连接ldap服务器时的一些参数的设定,slapd.conf配置文件才是ldap服务器的配置文件,一定不要弄错。对于这两个配置文件我们需要做如下的修改:
1、 ldap.conf
[root@mail ~]#vi /etc/openldap/ldap.conf  修改 -->
BASE dc=servyou-it.com
2、 slapd.conf
[root@mail ~]#vi /etc/openldap/slapd.conf 修改 -->
include      /etc/openldap/schema/extmail.schema #该配置文件位于 extman的解压包里
suffix           "dc=servyou-it.com"
rootdn           "cn=Manager,dc=servyou-it.com"
rootpw 123456
service    ldap start
3.1.3 OpenLDAP数据的配初始化
在配置 ldap的时候,我们需要把后面我们的Webmail用的ldap的schema配置在LDAP服务器的配置文件里面去。具体的配置方法如下:
[root@mail ~]#cd /data/
[root@mail data]#tar zxvf extman-1.1.tar.gz
[root@mail data]#cp extman-1.1/docs/extmail.schema /etc/openldap/schema/
[root@mail data]#cp extman-1.1/docs/init.ldif /etc/openldap/
[root@mail ~]#vi /etc/openldap/init.ldif 修改 -->
将 init.ldif文件里面的extmail.org修改为servyou-it.com
cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
service    ldap start
chkconfig --level 35 ldap on 设置开机启动。
 
ldapadd -x -D "cn=Manager,dc=servyou-it.com" -W -f /etc/openldap/init.ldif
注意:
错误提示:
Enter LDAP Password:
ldap_bind: Invalid credentials (49)
解决方法:有可能是配置初始化数据或者配置文件有错,请仔细检查配置或者密码
3.2BerkeleyDB 的安装与配置:
3.2.1BerkeleyDB 的安装
BerkeleyDB 可以通过两种方式来安装,第一种是在安装系统是自已就安装了,你如果认为它的版本太低了,可以通过YUM的方式升级一下,也可以通过源代码的方式安装,我这里是通过编译源码的方式安装的。
[root@mail data]#tar    zxvf db-5.1.25.tar.gz
[root@mail data]#cd    db-5.1.25
[root@mail db-5.2.28]#./dist/configure --prefix=/usr/local/BerkeleyDB
[root@mail db-5.2.28]#make
[root@mail db-5.2.28]#make install
3.2.2 BerkeleyDB的配置
BerKeleyDB初始化安装完成之后,所有头文件都保存在 /usr/local/BerkeleyDB/include,为了方便其他组件调用BerKeleyDB的头文件。操作如下
[root@mail db-5.2.25]# cd /
[root@mail1]# ln -sv /usr/local/BerkeleyDB/include /usr/include/db4
create symbolic link `/usr/include/db4/include' to `/usr/local/BerkeleyDB/include'
[root@mail1]# mv /usr/include/db.h /usr/include/db.h.bak
[root@mail1]# ln -sv /usr/local/BerkeleyDB/include/db.h /usr/include/db.h
create symbolic link `/usr/include/db.h' to `/usr/local/BerkeleyDB/include/db.h'
[root@mail1]# mv /usr/include/db_cxx.h /usr/include/db_cxx.h.bak
[root@mail1]# ln -sv /usr/local/BerkeleyDB/include/db_cxx.h /usr/include/db_cxx.h
create symbolic link `/usr/include/db_cxx.h' to `/usr/local/BerkeleyDB/include/db_cxx.h' [root@mail ~]#ldconfig -v
3.3.1 Courier-authlib的安装
authlib提供 pop3、smtp、imap等其他组件访问LDAP、MySQL、PAM等数据库组件的认证接口,类似于ODBC,所以我们需要在其他组件前面安装,具体的安装过程如下:
[root@mail data]#tar jxvf courier-authlib-0.63.0.tar.bz2
[root@mail data]#cd courier-authlib-0.63.0
[root@mail courier-authlib-0.63.0]#./configure --prefix=/usr/local/authlib --sysconfdir=/etc --with-authldaprc=/etc/authlib/authldaprc --with-mailuser=vmail --with-mailgroup=vmail --without-stdheaderdir --without-authuserdb --without-pam --without-authmysql --without-authpwd --without-authshadow --without-authpgsql --without-authcustom --with-redhat
[root@mail courier-authlib-0.63.0]#make 
[root@mail courier-authlib-0.63.0]#make    install
[root@mail courier-authlib-0.63.0]#make    install-configure
3.3.2 Courier-authlib的配置
在安装完成之后,我们需要对 courier-authlib做一下初始化的配置:
1、 authdaemonrc 的配置
[root@mail courier-authlib-0.63.0]#cd /
[root@mail ~]#vi    /etc/authlib/authdaemonrc 修改内容 -->
authmodulelist="authldap"
authmodulelistorig="authldap"
daemons=5 #改参数可以根据服务器的性能做适当的调整。
authdaemonvar=/usr/local/authlib/var/spool/authdaemon
DEBUG_LOGIN=0 #改参数的值可以为 0、1、2,一般情况下设置为0,需要调试的时候修改为2
DEFAULTOPTIONS="wbnodsn=1"
LOGGEROPTS=""
2、 authldaprc 的配置
[root@mail ~]#cp /etc/authlib/authldaprc /etc/authlib/authldaprc.bak
[root@mail ~]#vi /etc/authlib/authldaprc 添加内容 -->
LDAP_URI                 ldap://127.0.0.1:389
LDAP_PROTOCOL_VERSION    3
LDAP_BASEDN              o=extmailAccount,dc=servyou-it.com
LDAP_BINDDN              cn=Manager,dc=servyou-it.com
LDAP_BINDPW           123456
LDAP_TIMEOUT             5
LDAP_MAIL                mail
LDAP_FILTER              (&(objectClass=extmailUser)(active=1))
LDAP_HOMEDIR             homeDirectory
LDAP_MAILROOT            /home/domains
LDAP_MAILDIR             mailMessageStore
LDAP_MAILDIRQUOTA        quota
LDAP_CRYPTPW             userPassword
LDAP_UID                 uidNumber
LDAP_GID                 gidNumber
LDAP_AUXOPTIONS          disablesmtpd=disablesmtpd,disablesmtp=disablesmtp,disablewebmail=disablewebmail,disablenetdisk=disablenetdisk,disableimap=disableimap,disablepop3=disablepop3
LDAP_DEREF               never
LDAP_TLS                 0
LDAP_DOMAIN              servyou-it.com
3、 系统初始化配置
在每次系统启动的时候,我们希望 courier-authlib能够自动启动,需要做如下设置:
[root@mail data]#cd /data/courier-authlib-0.63.0
[root@mail courier-authlib-0.63.0]#cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@mail courier-authlib-0.63.0]#chmod 755 /etc/init.d/courier-authlib
[root@mail courier-authlib-0.63.0]#chkconfig --add courier-authlib
[root@mail courier-authlib-0.63.0]#chkconfig --level 35 courier-authlib on
[root@mail courier-authlib-0.63.0]#service courier-authlib start
[root@mail courier-authlib-0.63.0]#chmod +x /usr/local/authlib/var/spool/authdaemon/
[root@mail courier-authlib-0.63.0]#echo "/usr/local/authlib/lib/courier-authlib/" >>  /etc/ld.so.conf
[root@mail courier-authlib-0.63.0]#ldconfig
 
 
3.4 smtpd认证工具Cyrus-sasl组件的安装与配置
SASL全称Simple Authentication and Security Layer,是一种用来扩充C/S模式验证能力的机制。在Postfix可以利用SASL来判断用户是否有权使用转发服务,或是辨认谁在使用我们的服务器。
3.4.1 cyrus-sasl的安装
(在安装 cyrus-sasl之前我们需要将系统自带的软件包卸载,然后再进行cysasl的安装。确认系统中是否已经安装cyrus-sasl,确认方法:
[root@mail ~]# rpm –qa |grep sasl
用 rpm -e –nodeps 软件包名 进行卸载,如果是64为操作系统,系统默认会安装64和x86的两个相关包,需要加上 --allmatches的参数进行卸载,卸载完成之后,可以用前面的命令进行确认,直到系统没有sasl相关的软件包为止。再进行 cyrus-sasl的安装。)--可以不删除。
[root@mail data]# tar zxvf cyrus-sasl-2.1.23.tar.gz
[root@mail data]# cd cyrus-sasl-2.1.23
[root@mail cyrus-sasl-2.1.23]#./configure --prefix=/usr/local/sasl2/ --sysconfdir=/etc --disable-anon --enable-plain --enable-login --enable-ldapdb --with-ldap --with-authdaemond=/usr/local/authlib/var/spool/authdaemon/socket
说明:
1、 make 报错
db_berkeley.c:106: error: too few arguments to function '(*mbdb)->open'
make[2]: *** [db_berkeley.lo] Error 1
make[2]: Leaving directory `/data/cyrus-sasl-2.1.23/sasldb'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/data/cyrus-sasl-2.1.23'
make: *** [all] Error 2
解决方法
[root@mail cyrus-sasl-2.1.23]#cd sasldb/
[root@mail sasldb]#vi db_berkeley.c 修改为 -->
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1
        ret = (*mbdb)->open(*mbdb, NULL, path, NULL, DB_HASH, flags, 0660);
#else
        ret = (*mbdb)->open(*mbdb, "NULL", path, NULL, DB_HASH, flags, 0660);
#endif
cd ..
vi    utils/dbconverter-2.c 修改为 -->
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1
        ret = (*mbdb)->open(*mbdb, NULL, path, NULL, DB_HASH, DB_CREATE, 0664);
#else
        ret = (*mbdb)->open(*mbdb, "NULL", path, NULL, DB_HASH, DB_CREATE, 0664);
#endif
[root@mail sasldb]#cd ..
[root@mail cyrus-sasl-2.1.23]#make
[root@mail cyrus-sasl-2.1.23]#make install
3.4.2 Cyrus-sasl 的初始化配置
[root@mail cyrus-sasl-2.1.23]#echo "/usr/local/sasl2/lib/sasl2" >>/etc/ld.so.conf
[root@mail cyrus-sasl-2.1.23]#vi /usr/lib64/sasl2/smtpd.conf 内容为 -->
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/usr/local/authlib/var/spool/authdaemon/socket
[root@mail cyrus-sasl-2.1.23]#cp /usr/lib64/sasl2/smtpd.conf /usr/lib/sasl2/
[root@mail cyrus-sasl-2.1.23]#cp /usr/lib64/sasl2/smtpd.conf /etc/
 
3.5 Postfix软件的安装与配置
Postfix邮件系统的核心组件,主要提供 MTA服务,及整个邮件系统的框架。
3.5.1 Postfix的安装
[root@mail data]# tar zxvf    postfix-2.8.2.tar.gz
[root@mail data]# cd    postfix-2.8.2
[root@mail postfix-2.8.2]# make tidy
[root@mail postfix-2.8.2]#make makefiles "CCARGS=-DHAS_LDAP -I/usr/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/sasl2/include/sasl/ -I/usr/local/BerkeleyDB/include -DUSE_TLS -I-DUSE_TLS -I/usr/include/openssl" "AUXLIBS=-L/usr/lib -lldap -llber -L/usr/lib -lsasl2 -L/usr/local/BerkeleyDB/lib -L/usr/lib -lssl -lcrypto"
make
make install 提示输入 -->
install_root: [/]
tempdir: [/data/postfix-2.8.2] /tmp
config_directory: [/etc/Postfix]
command_directory: [/usr/sbin]
daemon_directory: [/usr/libexec/postfix]
data_directory: [/var/lib/postfix]
html_directory: [no]
mail_owner: [postfix]
mailq_path: [/usr/bin/mailq]
manpage_directory: [/usr/local/man]
newaliases_path: [/usr/bin/newaliases]
queue_directory: [/var/spool/Postfix]
readme_directory: [no]
Sendmail_path: [/usr/sbin/Sendmail]
setgid_group: [postdrop]
[root@mail Postfix-2.8.2]# newaliases #生成别名数据库
3.5.2 Postfix的配置
Postfix的配置存放 /etc/postfix/目录下,主要配置文件有main.cf、master配置文件。这里不做详细描述,详细配置请参考附录。
3.6 Maildrop的安装与配置
maildrop 是一个使用 C++编写的用来代替本地MDA 的带有过滤功能邮件投递代理,是courier 邮件系统组件之一。它从标准输入接受信息并投递到用户邮箱;maildrop 既可以将邮件投递到mailboxes 格式邮箱,亦可以将其投递到maildirs 格式邮箱。同时,maildrop 可以从文件中读取入站邮件过滤指示,并由此决定是将邮件送入用户邮箱或者转发到其它地址等。和procmail 不同的是,maildrop 使用结构化的过滤语言,因此,邮件系统管理员可以开发自己的过滤规则并应用其中。
在此将使用 maildrop 来代替Postfix 自带的MDA,并以此为基础扩展后文的邮件杀毒和反垃圾邮件功能的调用;在此可能会修改前文中的许多设置,请确保您的设置也做了相应的修改。
3.6.1 Maildrop的安装
1、 pcre的安装
在安装 maildrop之前请先确认系统中是否已经安装了pcre组件,maildrop需要此组件的支持。确认方法:
[root@mail data]#rpm -qa |grep pcre 确认 prce是否安装。在这里我们系统默认已经安装了此组件,这里就不另外安装了。pcre的×××地址为:
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.bz2
configure&&make&&make install
然后按照解压、配置、编译、安装的步骤进行安装即可。这里不再详述。
2、 maildrop的安装
[root@mail data]#tar jxvf maildrop-2.5.4.tar.bz2
[root@mail data]#cd    maildrop-2.5.4
[root@mail data]#ln -s /usr/local/authlib/bin/courierauthconfig /usr/bin/courierauthconfig
[root@mail data]#ln -s /usr/local/authlib/include/* /usr/include
[root@mail maildrop-2.5.4]#./configure --enable-sendmail=/usr/sbin/sendmail --enable-trusted-users='root vmail' --enable-syslog=1 --enable-maildirquota --enable-maildrop-uid=1000 --enable-maildrop-gid=1000  --with-trashquota --with-dirsync
[root@mail maildrop-2.5.4]# make
[root@mail maildrop-2.5.4]# make install
3.6.2 Maildrop的配置
配置 Postfix调用maildrop来处理邮件。
1、 Postfix中 matser.cf配置文件的修改
[root@mail maildrop-2.5.4]# vi    /etc/postfix/master.cf 修改 -->
maildrop unix -        n       n       -       -       pipe
 flags=DRhu user=vmail:vmail argv=/usr/local/bin/maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}
2、 Postfix中 main.cf配置文件的修改
[root@mail maildrop-2.5.4]# vi    /etc/postfix/main.cf 修改 -->
virtual_transport = maildrop
3、 maildrop配置文件 maildroprc的修改
[root@mail maildrop-2.5.4]# vi    /etc/maildroprc   加入 -->
logfile "/var/log/maildrop.log"
TEST="/bin/test -f"
#
# Check for custom user .mailfilter file
#
CUSTOM_FILTER="$HOME/.mailfilter"
`$TEST $CUSTOM_FILTER && exit 1 || exit 0`
if ( $RETURNCODE == 0 )
{
        to "$HOME/Maildir"
}
4、 创建 maildrop日志文件,并赋予相应的权限
[root@mail maildrop-2.5.4]#touch /var/log/maildrop.log
[root@mail maildrop-2.5.4]#chown vmail.vmail /var/log/maildrop.log
3.6.3 Maildrop的验证
maildrop -v 如下输入正常 -->
maildrop 2.5.4 Copyright 1998-2005 Double Precision, Inc.
GDBM/DB extensions enabled.
Courier Authentication Library extension enabled.  代表安装正常
Maildir quota extension are now always enabled.
This program is distributed under the terms of the GNU General Public
License. See COPYING for additional information.
3.7 Courier-imap的安装与配置
courier-iamp在整个邮件系统中充当 MAA的角色,主要为用户提供pop3和imap服务。
3.7.1 Courier-imap的安装
[root@mail data]#tar jxvf courier-imap-4.9.3.tar.bz2
[root@mail data]#cd    courier-imap-4.9.3
[root@mail courier-imap-4.9.3]#./configure --prefix=/usr/local/imap --sysconfdir=/etc --with-redhat --enable-unicode --disable-root-check --with-trashquota --without-ipv6 CPPFLAGS='-I/usr/local/authlib/include' LDFLAGS='-L/usr/local/authlib/lib/courier-authlib' COURIERAUTHCONFIG='/usr/local/authlib/bin/courierauthconfig'
[root@mail courier-imap-4.9.3]#make
[root@mail courier-imap-4.9.3]#make    install
[root@mail courier-imap-4.9.3]#make    install-configure
3.7.2courier-imap 的配置
courier-iamp的配置文件主要包括: pop3d、pop3-ssl、imapd、imapd-ssl。
1、 pop3d配置文件的修改
[root@mail courier-imap-4.9.3]#vi    /etc/pop3d 修改 -->
POP3DSTART=YES
2、 pop3d-ssl配置文件
[root@mail courier-imap-4.9.3]#vi    /etc/pop3d-ssl 修改 -->
POP3DSSLSTART=YES
3、 pop3d.cnf配置文件
[root@mail courier-imap-4.9.3]#vi    /etc/pop3d.cnf 修改 -->
#default_md = sha1     (注释点这项)
4、 imapd配置文件
[root@mail courier-imap-4.9.3]#vi /etc/imapd 修改 -->
IMAPDSTART=yes
5、 imapd-ssl配置文件
[root@mail courier-imap-4.9.3]#vi /etc/imapd-ssl 修改 -->
IMAPDSSLSTART=YES
6、 imapd.cnf配置文件
[root@mail courier-imap-4.9.3]#vi /etc/imapd.cnf 修改 -->
#default_md = sha1     (注释点这项)
7、 maildrop 初始化配置
[root@mail courier-imap-4.9.3]#cp    courier-imap.sysvinit /etc/rc.d/init.d/courier-imapd
[root@mail courier-imap-4.9.3]#chmod 755 /etc/rc.d/init.d/courier-imapd
[root@mail courier-imap-4.9.3]#chkconfig --add courier-imapd
[root@mail courier-imap-4.9.3]#chkconfig --level 35 courier-imapd on
[root@mail courier-imap-4.9.3]#service    courier-imapd start
4 Webmail的安装与配置
Webmail主要为管理员提供管理和维护的平台、为用户提供查看和管理邮件平台。主要包括 Extman和Extmail两个组件。下面将详细介绍其安装与配置的方法。
4.1 Extman的安装与配置
extman主要提供 web的后台管理与维护。
4.1.1 Extman的安装
extman的安装非常简单,只需要将 extman的
[root@mail data]#tar zxvf extman-1.1.tar.gz
[root@mail data]#cp -ra extman-1.1 /var/www/extsuite/extman
[root@mail data]#cd /var/www/extsuite/extman/
4.1.2 Extman的配置
[root@mail extman]#cp webman.cf.default webman.cf
[root@mail extman]#vi webman.cf 修改内容 -->
SYS_SESS_DIR = /var/www/extsuite/extman/tmp
SYS_BACKEND_TYPE = ldap
SYS_LDAP_BASE = dc=servyou-it.com
SYS_LDAP_RDN = cn=Manager,dc=servyou-it.com
SYS_LDAP_PASS = 123456
SYS_GROUPMAIL_SENDER = postmaster@servyou-it.com
4.2 Extmail的安装与配置
4.2.1 Extmail的安装
[root@mail data]#tar    zxvf extmail-1.2.tar.gz
[root@mail data]#cp -ra extmail-1.2 /var/www/extsuite/extmail
4.2.2 Extmail的配置
[root@mail data]#cd /var/www/extsuite/extmail/
[root@mail extmail]#cp webmail.cf.default webmail.cf
[root@mail extmail]#vi webmail.cf 修改内容 -->
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_AUTH_TYPE = ldap
SYS_SPAM_REPORT_ON = 1
SYS_DEBUG_ON = 0
SYS_LDAP_PASS = 123456
SYS_LDAP_BASE = o=extmailAccount,dc=servyou-it.com
SYS_LDAP_RDN = cn=Manager,dc=servyou-it.com
SYS_G_ABOOK_LDAP_BASE = ou=AddressBook,dc=servyou-it.com
SYS_G_ABOOK_LDAP_ROOTDN = cn=Manager,dc=servyou-it.com
SYS_SESS_DIR = /var/www/extsuite/extmail/tmp
SYS_UPLOAD_TMPDIR = /var/www/extsuite/extmail/tmp
SYS_AUTHLIB_SOCKET = /usr/local/authlib/var/spool/authdaemon/socket
4.3 Apache的配置
[root@mail ~]#vi /etc/httpd/conf/httpd.conf 末尾添加 -->
include conf/vhost_*.conf
[root@mail ~]#vi /etc/httpd/conf/vhost_extmail.conf
# VirtualHost for ExtMail Solution
<VirtualHost *:80>
ServerName mail2.servyou-it.com
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/
Alias /extmail /var/www/extsuite/extmail/html/
ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/
Alias /extman /var/www/extsuite/extman/html/
#Alias /phpldapadmin /var/www/extsuite/phpldapadmin/htdocs/
#Suexec config
#SuexecUserGroup vmail vmail
</VirtualHost>
配置完成之后就可以启动 httpd服务了。
[root@mail ~]#service httpd start
4.4 Postfix虚拟用户的配置
一般情况下,邮件服务器都不会直接用系统帐号户用户提供邮件服务,所以我们需要用到虚拟用户这个功能,将用户的信息保存在后台数据库中,这里我们采用 ldap的方式保存用户数据,接下来将详细介绍为Postfix添加虚拟用户支持,具体配置如下:
1、 Postfix主配置文件 main.cf的配置
[root@mail ~]#vi /etc/Postfix/main.cf  添加如下内容 -->
#extmail config here
virtual_mailbox_base = /home/domains
virtual_alias_maps = ldap:/etc/Postfix/ldap_virtual_alias_maps.cf
virtual_mailbox_domains = ldap:/etc/Postfix/ldap_virtual_domains_maps.cf
virtual_mailbox_maps = ldap:/etc/Postfix/ldap_virtual_mailbox_maps.cf
virtual_transport = maildrop
smtpd_sender_login_maps =
ldap:/etc/Postfix/ldap_virtual_sender_maps.cf,
ldap:/etc/Postfix/ldap_virtual_alias_maps.cf
2、 配置 Postfix的ldap列表
[root@mail ~]#cp /var/www/extsuite/extman/docs/ldap* /etc/postfix/
[root@mail ~]#postfix reload
Postfix本身采用了 body_checks和header_checks的方法对邮件内容进行,但是这种机制将检查经过Postfix的每一份邮件,而且一次只能对比对一行文字。如果设置了复杂的过滤规则,将严重降低Postfix的效率,消耗大量的服务器运算资源。另外该模式只提供拒收和接收两种动作,所以,我们一般只用它来实现简单的过滤操作。
Postfix一般采用外界程序来实现对邮件进行病毒和垃圾扫描。这里我采用 Amavisd-new来调用ClamAV和SpamAssassin的组合套件来实现对病毒邮件扫描和垃圾邮件过滤。
5.1 clamav的安装与配置
ClamAV 是一个 Unix 系统平台上的开源反病毒工具,它是特地为在邮件网关上进行邮件扫描而设计的。整套软件提供了许多的实用工具,包括一个可伸缩和可升级的多线程守护进程、一个命令行扫描工具和病毒库自动升级工具。
5.1.1 ClamAV的安装
[root@mail data]#tar    zxvf clamav-0.97.1.tar.gz
[root@mail data] #cd    clamav-0.97.1
[root@mail clamav-0.97.1]#./configure --prefix=/usr/local/clamav --with-dbdir=/usr/local/share/clamav --disable-zlib-vcheck --sysconfdir=/etc/clamav
make
make install
5.1.2 ClamAV的配置
[root@mail data]#mkdir /var/log/clamav
[root@mail data]#chmod -R 744 /var/log/clamav
[root@mail data]#chmod -R amavis:amavis /var/log/clamav
[root@mail data]#chown -R amavis:amavis /var/log/clamav
[root@mail data]#chown -R amavis:amavis /usr/local/share/clamav
[root@mail data]#mkdir /var/run/clamav
[root@mail data]#chmod 700 /var/run/clamav
[root@mail data]#chown -R clamav:clamav /var/run/clamav
[root@mail data]#mv /etc/clamav/clamd.conf /etc/clamav/clamd.conf.old
[root@mail data]#vi    /etc/clamav/clamd.conf
[root@mail data]#mv    /etc/clamav/freshclam.conf /etc/clamav/freshclam.conf.old
[root@mail data]#vi /etc/clamav/freshclam.conf
[root@mail data]#find / -name "clamav-milter"
[root@mail data]#cp clamd/clamd /etc/rc.d/init.d/clamd
5.2 SpamAssassin的安装与配置
是目前最好的、最流行的开源反垃圾邮件软件之一。它是一个邮件过滤器,使用了多种反垃圾邮件技术,如:文本分析、贝叶斯过滤、DNS 黑名单和分布式协同过滤数据库等。
1、    基础配置
在安装系统的时候,sapmassassin组件就默认安装了,这里只要做简单的配置即可,sapmassassin的配置文件位于/etc/mail/spamassassin/目录下。
[root@mail data]#vi    /etc/mail/spamassassin/local.cf
# These values can be overridden by editing ~/.spamassassin/user_prefs.cf
# (see spamassassin(1) for details)
 
# These should be safe assumptions and allow for simple visual sifting
# without risking lost emails.
 
#required_hits 5
#report_safe 0
#rewrite_header Subject [SPAM]
 
required_hits 10.0
#rewrite_subject 1
required_score 5.0
rewrite_header Subject *****SPAM*****
report_safe 1
use_bayes 1
bayes_auto_learn 1
skip_rbl_checks 1
use_razor2 0
use_pyzor 0
ok_locales all
2、    增加Chinese_rules.cf 支持
Chinese_rules.cf 是教育科研网的反垃圾邮件小组对大量垃圾邮件和正常邮件进行分析后得出的一个关键字 /分数规则集,用于处理中文(简体)垃圾邮件。这里我们通过如下命令增加到系统:
#wget -N -P /usr/share/spamassassin http://www.ccert.edu.cn/spam/sa/Chinese_rules.cf
 
5.3 Amavisd-new的安装与配置
Amavisd-new 是一个连接 MTA 和内容检测工具(诸如病毒扫描工具和SpamAssassin)的高性能接口程序,使用perl 语言写成。它一般通过SMTP、ESMTP 或者LMTP 和MTA 进行通讯,当然也可以借助于其它外部程序进行。同Postfix(MTA)协同工作时表现尤佳。当它呼叫SpamAssassin 进行内容过滤时,对于一封邮件只需要呼叫一次,而不管这封邮件将发往多少个收件人;同时,它亦会尽力保证实现每一位收件人的偏好设置,如接收/拒绝,检测/不检测,垃圾邮件级别等;它还会在邮件头部分插入spam 相关信息。
5.3.1 amavisd-new的安装
[root@mail data]#tar    zxvf   amavisd-new-2.6.1.tar.gz
[root@mail data]#cd amavisd-new-2.6.1
[root@mail data]#mkdir -p /var/amavis /var/amavis/tmp /var/amavis/var /var/amavis/db
[root@mail data]#chown -R amavis:amavis /var/amavis
[root@mail data]#chmod -R 750 /var/amavis
[root@mail data]#cp amavisd /usr/local/sbin/
[root@mail data]#chown root /usr/local/sbin/amavisd
[root@mail data]#chown 755 /usr/local/sbin/amavisd
[root@mail data]#cp amavisd.conf /etc/
[root@mail data]#chown root /etc/amavisd.conf
[root@mail data]#chmod 644 /etc/amavisd.conf
[root@mail data]#mkdir /var/virusmails
[root@mail data]#vi    /etc/amavisd.conf
[root@mail data]#/usr/local/sbin/amavisd debug
根据调试命令的结果来安装所需要的 perl模块,默认情况下,需要安装的perl组件有:
MIME::Base64
DB_File
Net::SMTP
Mail::SPF
IP::Country::Fast
Net::Ident
IO::Socket::INET6
IO::Socket::SSL
Compress::Zlib
Time::HiRes
Mail::DKIM
Mail::DomainKeys
DBI *and* DBD driver/modules
Encode::Detect
Apache::Test
Razor2
安装方法如下:
[root@mail data]#perl -MCPAN -e shell
cpan> install Digest::SHA1
………………
5.4 Spam Locker的安装与配置
SpamAssassin 是基于 "邮件内容"来进行判别的垃圾邮件过滤系统,而Spam Locker 是基于邮件"发送行为"来进行判别的垃圾邮件过滤系统。两种模式的垃圾邮件过滤系统孰优孰劣在此不做评判,请安装者自行选择。两个过滤系统可分别安装,也可以并存运行。Spam Locker 简称slockd,下载地址:http://www.extmail.org/download/
1、 环境要求 Spam Locker 要用到的perl 模块:
Net::NS
Digest::MD5
Digest::SHA1
Digest::HMAC
Net::IP
2、 locker的安装
[root@mail data]# tar -zxvf slockd-0.10.tar.gz
[root@mail data]# mv slockd-0.10 slockd
[root@mail data]# mv slockd /usr/local/
5.4.2 配置slockd
进入 /usr/local/slockd 目录,编辑config/main.cf 配置文件,每个配置参数都有简短的注释,如果要修改的话,请仔细阅读注释后方可修改。默认情况下,slockd 将只监听127.0.0.1(localhost)的10030 端口,公网是无法访问这一服务的,这样做是为了安全起见,防止被其他有心人利用来做坏事。默认的日志将在标准的输出和标准错误输出(STDERR)显示。将如下行去掉注释:
setsid 1
使之以后台的方式运行。接下来,可以配置 slockd 的日志路径和pid 文件路径,默认配置为:
log_file /var/log/slockd.log
pid_file /var/run/slockd.pid
启动 slockd:
[root@mail data]# /usr/local/slockd/slockd-init start
添加开机时自动执行
[root@mail data]#echo "/usr/local/slockd/slockd-init start" >> /etc/rc.local
进入 /usr/local/slockd/tools 目录,输入:
[root@mail data]#perl policy_sig -h localhost -p 10030 --helo FOOBAR \
--ip 192.168.2.180 --from zhufg@servyou-it.com --to test@servyou-it.com
此时,程序应该返回如下错误信息:
action=504 <FOOBAR>: rejected, see http://bl.extmail.org/cgi/why?fqdn
这表示 slockd 初步的正常工作了。
配置 MTA:
[root@mail data]# vi /etc/Postfix/main.cf
将“check_policy_service inet:127.0.0.1:10030”记录增加到 smtpd_recipient_restrictions 里,
一个建议的配置如下:
########## slockd ##########
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname,
check_policy_service inet:127.0.0.1:10030
########## slockd end ##########
配置完毕后,重新启动 Postfix。
注意的是,上面的配置是将 slockd 的查询放到最后,这也是进一步提高资源利用率的办法,
因为有部分功能 Postfix 已实现了,所以就先由Postfix 检测,如果检测不到再由slockd 完成。
6.1 Postal邮件测试工具介绍
Postal是邮件服务器压力测试工具。
6.2 postal邮件测试工具的安装
postal需要 gnutls的支持,而gnutls需要nettle和p11-kit的支持,所以在安装该软件之前,要先安装这三个组件。
[root@mail ~]#cd    /data
[root@mail data]#tar    zxvf nettle-2.4.tar.gz
[root@mail data]#cd    nettle-2.4
[root@mail nettle-2.4]#./configure
[root@mail nettle-2.4]#make
[root@mail nettle-2.4]#make install
6.2.23 、安装p11-kit
[root@mail data]#tar    zxvf p11-kit-0.7.tar.gz
[root@mail data]#cd    p11-kit-0.7
[root@mail p11-kit-0.7]#./configure
[root@mail p11-kit-0.7]#make
[root@mail p11-kit-0.7]#make install
6.2.3 gnutls的安装
开始安装 gnutls之前请将系统自带的gnutls删除,因为系统自带的版本为1.4.1比较低。而postal至少要求1.4.3
[root@mail data]#rpm -e --nodeps gnutls
[root@mail data]#rpm -e --nodeps gnutls-utils
[root@mail data]#rpm -e --nodeps gnutls-devel
[root@mail data]#rpm -e --nodeps --allmatches gnutls (x64)
[root@mail data]#rpm -e --nodeps --allmatches gnutls-devel (x64)
[root@mail data]#rpm -e --nodeps --allmatches gnutls-utils (x64)
[root@mail data]#tar    jxvf gnutls-2.2.4.tar.bz2
[root@mail data]#cd gnutls-2.2.4
[root@mail gnutls-2.2.4]#./configure
[root@mail gnutls-2.2.4]# make
[root@mail gnutls-2.2.4]# make install
[root@mail gnutls-2.2.4]#cd /usr/local/lib/
[root@mail lib]#cp libgnutls.so.26 /usr/lib64 (x64) #将 postal运行时需要的动态连接库复制到/usr/lib目录下,方便调用。
[root@mail lib]#cp libgnutls.so.26 /usr/lib
[root@mail lib]#strings libgnutls.so.26.1.5 |grep GNUTLS_1
GNUTLS_1_4
注意 :在选择postal的时候一定选择比较新的软件包,我选择安装的是0.70版本,低版本的postal要求必须为GNUTLS_1_3,这样就会导致postal不能正常运行。
6.2.4 安装postal
[root@mail data]#tar zxvf    postal-0.70.gz
[root@mail data]#cd postal-0.70
[root@mail postal-0.70]#cp /bin/uname /usr/bin/uname
[root@mail postal-0.70]#./configure
[root@mail postal-0.70]#make
[root@mail postal-0.70]#make install
[root@mail postal-0.70]#postal
Usage: postal [-m maximum-message-size] [-M minimum-message-size] [-t threads]
              [-c messages-per-connection] [-r messages-per-minute] [-a]
              [-b [no]netscape] [-p port] [-[z|Z] debug-file]
              [-s ssl-percentage]
              [-l local-address] [-f sender-file]
              smtp-server user-list-filename
 
Postal Version: 0.70
看见上述输出就代表 postal已经可以正常运行了。
6.3 postal邮件测试工具的使用
postal工具的参数说明
[-m maximum-message-size] 邮件的最大 size
[-M minimum-message-size] 邮件的最小 size
[-t threads] 发送邮件的线程数
[-c messages-per-connection] 每个链接发送多少个邮件
[-r messages-per-minute] [-a] 一分钟发送多少封邮件
[-b [no]netscape]
[-p port] 邮件服务器的端口
[-[z|Z] debug-file] 将调试结果写入文件
[-s ssl-percentage] SSL链接
[-l local-address] 本地地址
[-f sender-file] 发送附件
smtp-server  邮件服务器的地址
user-list-filename 用户列表,用户必须在系统中存在, postal会随机从一个地址发送到另一个地址。
7 Postfix邮件服务器的集群部署
任何稳定的系统都有系统 down机的时候,如何保证邮件系统系统高可用性呢。下面将描述Postfix的集群部署方案,如下图所示:
 

说明:
1、Postfix集群方案中,采用双机主备部署模式,主要分为业务 (包括MTA、MAA、MDA、WEB)、邮件存储、用户认证三个某块;
2、其中业务模块采用 HA的方式虚拟出一个VIP(服务器IP地址),对外提供服务。正常情况下VIP守护在主服务器上为用户提供服务,当主服务器出现故障的时候,VIP将守护在从服务器上提供服务。有关heartBeat的资料请参考《基于heartbeat技术实施CTI服务高可用性的技术实现方案》
3、对于邮件服务器来,还有一个比较重要的就是用户数据,在这里不论是 mysql还是LDAP都可以采用主备同步的技术来实现用户数据的同步。有关ldap的集群部署请参考《OpenLDAP安装与部署手册》
4、邮件服务器会暂时把用户的邮件保存在服务器上,直到用户利用客户端工具将该邮件收下或者删除,所以邮件的存储也在集群方案中必须要考虑的。在 Postfix的集群方案中,我们采用MFS分布式存储技术,将用户的邮件分为两个副本保存在两台不同的服务器上。有关MFS的资料请参考《Linux MFS安装手册》
 
8.1 FastCGI的安装与配置
为 Extmail 增加FCGI 的支持,主要是为了获得优异的WEB效能,克服CGI 不能应付大量访问及低效率的缺陷。据说,FCGI 的页面效率是CGI 模式的十倍以上。mod_fastcgi 是针对Apache Web 服务器的FCGI 支持模块,下载地址http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
[root@mail data]# tar -zxvf mod_fastcgi-2.4.6.tar.gz
[root@mail data]#cd mod_fastcgi-2.4.6
[root@mail mod_fastcgi-2.4.6]# cp Makefile.AP2 Makefile
[root@mail mod_fastcgi-2.4.6]# make top_dir=/usr/local/apache install
除了 Apache 需要FCGI 的支持外,extmail 也需要相应的perl-FCGI 模块。下载地址http://dries.ulyssis.org/rpm/packages/perl-FCGI/info.html
用以下命令安装:
[root@mail data]# rpm -ivh perl-FCGI-0.67-1.2.el5.rf.i386.rpm
(请安装跟你的操作系统版本对应的安装包)
8.1.2 Apache FastCGI的配置
在 Apache 的配置文件的Extmail 虚拟主机部分,添加如下内容:
vi
LoadModule fastcgi_module modules/mod_fastcgi.so
<Ifmodule mod_fastcgi.c>
FastCgiExternalServer /var/www/extsuite/extmail/dispatch.fcgi -host 127.0.0.1:8888
</Ifmodule>
同时,去掉如下行:
ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/
Alias /extmail /var/www/extsuite/extmail/html
ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/
Alias /extman /var/www/extsuite/extman/html
改为:
Alias /extmail/cgi/ /var/www/extsuite/extmail/dispatch.fcgi/
Alias /extmail /var/www/extsuite/extmail/html
Alias /extman/cgi/ /var/www/extsuite/extmail/dispatch.fcgi/
Alias /extman /var/www/extsuite/extman/html
<Location "/extmail/cgi">
SetHandler fastcgi-script
</Location>
<Location "/extman/cgi">
SetHandler fastcgi-script
</Location>
然后编辑 /var/www/extsuite/extmail/dispatch-init 文件,修改如下:
SU_UID=vmail
SU_GID=vmail
BASE=/var/www/extsuite/extmail
启动 fastcgi server:
# /var/www/extsuite/extmail/dispatch-init start
如果没有意外将启动 5 个dispatch.fcgi 守护进程.
添加自启动:
# echo "/var/www/extsuite/extmail/dispatch-init start" >> /etc/rc.d/rc.local
重启 apache
# /usr/local/apache/bin/apachectl restart
8.2 DNS缓存工具的安装与配置
发送邮件时,系统必须到 DNS 服务器上进行查询,如果自己有DNS 服务器或者DNS 缓存,会大大加快域名查询速度。这里安装的是djbdns,如果你装有bind 的话,就不要装这个了。进入本安装包install-djbdns-rpm 目录(见附件),运行install.sh 安装,注:install.sh 最后两行的ip 地址是广西电信的DNS 服务器地址,运行前请修改为你所在区域的dns 服务器地址。
(你也可以自己去下载 djbdns 的源码来编译安装,下载地址及安装教程 http://cr.yp.to/djbdns.html,这个貌似很麻烦~~)
1、 启动
# /etc/init.d/djbdns start
启动正常的话会在 53 端口监听
2、 验证 djbdns 是否起作用:
# dig http://www.163.com/ (别的网站域名也可以)
再执行一次上述命令,应该能感觉到第二次运行时的响应速度明显比第一次快。
3、 刷新 DNS 缓存
有时候互联网上的 DNS 记录已经发生改变了,而你的DNS 缓存还是旧的,可用如下命令来刷新
# /usr/bin/svc -t /service/dnscache
你也可以将上述命令写个脚本添加到 crontab 进行定期刷新:
# vi /root/flush_dns.sh -->添加下行
/usr/bin/svc -t /service/dnscache
# chmod 755 /root/flush_dns.sh
# crontab -e
添加下行
1 1 * * * /root/flush_dns.sh
(这个本不应属于 Postfix 邮件服务器的一部分的,加进来只是为了方便一点。如果你的邮件数量不是很多的话,作DNS 缓存的意义不大;如果你经常往外大量群发邮件,就比较有用了。)
 
在整个邮件系统安装完成之后,在调试的过程中,经常会出现这样或者那样的问题,下面列举一些比较常见的问题及解决的方法,希望对大家有所帮助。
问题1
temporary failure. Command output: /usr/bin/maildrop: Invalid home directory permissions - world writable. )
[root@Mail ~]# echo "test" | maildrop -V 10 -d lian@extmail.org
maildrop: authlib: groupid=1000
maildrop: authlib: userid=1000
maildrop: authlib: logname=lian@extmail.org,home=/home/domains/extmail.org/lian, mail=/home/domains/extmail.org/lian/Maildir/
maildrop: Changing to /home/domains/extmail.org/lian
maildrop: Invalid home directory permissions - world writable.
出现这样的问题是 /home /domails文件的权限不能设高777   755恢复
问题2:
Mar 18 15:38:08 Mail Postfix/smtpd[31796]: warning: SASL authentication failure: cannot connect to Courier authdaemond: Permission denied
Mar 18 15:38:08 Mail Postfix/smtpd[31796]: warning: Mail[127.0.0.1]: SASL login authentication failed: generic failure
此类问题最多的是几个问题
/usr/lib/sasl2/smtpd.conf    配置问题    文件的权限问题
/var/spool/authdaemon   文件的权限问题
/etc/authlib/authdaemon  配置问题
1、关于很多日志报拒绝情况下,检查权限的问题,多数情况 是 SELinux搞的鬼,将SELinux关闭,重新启动机器再看一切运行正常
2、连不上数据的问题 最好将默认的 localhost改为127.0.0.1
=============================================================================
3、 extmail 与extman  web界面打开提示DBI连接数据库的问题,是因为缺少perl-DBD-MySQL包
提示连接不上数据库是因为 webman里面的数据库设置问题
没有那个邮件地址目录的,拒绝是因为权限的设置无法写入比如:
drwxr-xr-x 5 vuser vgroup 4096 03-18 15:43 extmail.org
问题3:
Feb 23 23:32:45 mail-bk Postfix/smtpd[2799]: NOQUEUE: reject: RCPT from xmerp.test.com[192.168.0.37]: 554 5.7.1 <xmerp.test.com[192.168.0.37]>: Client host rejected: Access denied; from=<hufy@test.com> to=<joe@test.com> proto=ESMTP helo=<xmerp>
确认以上日志为客户机访问拒绝,无中继的权限。
1、检查 mynetworks是否有列出192.168.0.37这台服务器。
经确认存在。(这里有异常,等下在说,但现在我们就认是正常的)
2、检查 POSTFIX中的几个restriction确认是否有存在permit_mynetworks列出。
smtpd_restriction_classes=allow_send_alluser,only_send_localdomain
allow_send_alluser = check_sender_access hash:/etc/Postfix/s2all_sender.txt,reject
only_send_localdomain=check_recipient_access hash:/etc/Postfix/onlysend_localdomain_maps.txt,reject
smtpd_recipient_restrictions=check_recipient_access hash:/etc/Postfix/send2allclass,check_sender_access, mysql:/etc/Postfix/mysql_virtual_localdomain_class_maps.cf,
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject
smtpd_sender_restrictions=
permit_mynetworks,
reject_sender_login_mismatch,
reject_authenticated_sender_login_mismatch,
reject_unauthenticated_sender_login_mismatch,
smtpd_sender_login_maps=
mysql:/etc/Postfix/mysql_virtual_sender_maps.cf,
mysql:/etc/Postfix/mysql_virtual_alias_maps.cf
smtpd_client_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_sender,
reject_unauth_pipelining,
reject_unauth_destination,
reject
mynetworks = 127.0.0.1 192.168.0.8 192.168.0.11 193.168.0.37  192.168.0.17 192.168.0.6 
192.168.0.3 192.168.0.16 192.168.0.15 192.168.9.49 192.168.0.39 192.168.0.19 192.168.0.202  192.168.0.144
###MASTER文件
submission inet n       -       n       -       -       smtpd
  -o smtpd_tls_security_level=may
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth
  -o smtpd_sasl_security_options=noanonymous
  -o smtpd_sasl_local_domain=$mydomain
  -o smtpd_client_restrictions=permit_sasl_authenticated,permit_mynetworks,reject
确认以下设置都没有问题,没办法开启 POSTFIX的DEBUG
在 main.cf文件中增加以下内容:
debug_peer_list = 192.168.0.37
#运行 Postfix reload
问题4: extman后台管理系统控制没有信息输出的解决方法
[root@KangTa daemon]# pwd
/var/www/extsuite/extman/daemon
[root@KangTa daemon]# ./cmdserver --daemon
loaded ok
Found an server instance pid=15259 is running, abort..
[root@KangTa daemon]# ps -eaf | grep 15259
root     15259     1  0 21:31 ?        00:00:00 /usr/bin/perl -w ./cmdserver –daemon
root     15485 10403  0 21:36 pts/1    00:00:00 grep 15259
[root@KangTa daemon]# kill 15259
问题5:编译courier-imap 出错
checking for courierauthconfig... no
configure: WARNING: === Courier authentication library not found.
configure: WARNING: === You need to download and install
configure: WARNING: === http://www.courier-mta.org/download.php#authlib first.
configure: WARNING: === If courier-authlib is installed in a non-default
configure: WARNING: === directory, set the COURIERAUTHCONFIG environment
configure: WARNING: === variable to the full path to the courierauthconfig
configure: WARNING: === binary and rerun this configure script.
configure: WARNING:
configure: error: courierauthconfig not found
解决方法:
[root@mail courier-imap-4.8.0.20100628]# export COURIERAUTHCONFIG=/usr/local/authlib/bin/courierauthconfig
问题6:maildrop编译出错
configure: error: pcre.h not found - install PCRE from www.pcre.org
解决方法:
[root@ivon maildrop-2.5.0]# yum install pcre-devel 
问题7:安装courier-imap时报错

安装 courier-imap时报错,信息如下
checking for courierauthconfig... /usr/local/authlib/bin/courierauthconfig
configure: error: This option is no longer supported
You have new mail in /var/spool/mail/root
解决方法:
我用的 4.8的  换成4.5时安装顺利完成。
courier-imap-4.5.1.tar.bz2
问题8:extman验证码不显示
解决方法
支持范围:后台登陆和帐户注册模块。需要 GD的支持,详细请到cpan上搜索GD并安装即可。注意的是默认webman.cf里打开了该功能的自持,如果需要关闭校验码,请将SYS_CAPTCHA_ON = 0即可关闭。
[root@ivon daemon]# perl -MCPAN -e shell
Terminal does not support AddHistory.
cpan shell -- CPAN exploration and modules installation (v1.7602)
ReadLine support available (try 'install Bundle::CPAN')
cpan> install GD
参数介绍:
SYS_CAPTCHA_ON = 1 | 0 如果为0则关闭此功能
SYS_CAPTCHA_KEY 该参数非常重要,设置的是您的校验key,强烈 建议安装extman后修改此参数,否则非法分子可以利用默认的key来伪造请求!!请设置一个复杂、不易猜测的key值。
SYS_CAPTCHA_LEN 校验码的长度,默认是6位。
校验码使用了ttf字库,如果您的操作系统没有freetype等ttf库,请删除 extman/addon/font.ttf这个软链接,这样校验码就会用gd默认的字体来显示。
 
问题9:启动Postfix时报错
Postfix: fatal: /etc/Postfix/main.cf, line 50: missing '=' after attribute name: "reject_non_fqdn_hostname,"
解决方法:
修改/etc/Postfix/main.cf  smtpd_recipient_restrictions = 后面的选项都不能有空格。
#====================SASL========================
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions=
permit_mynetworks,
permit_sasl_authenticated,
reject_invalid_hostname,
reject_non_fqdn_hostname,
reject_unknown_sender_domain,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain,
reject_unauth_pipelining,
reject_unauth_destination,permit
问题10:extman后台管理不能登录了,提示如下
Can't open /tmp/extman//sid_26da75f9aec35f2cbc6b4fa425ab525e, No such file or directory
解决方法:
修改,/var/www/extsuite/extman/webmail.cf文件里面的配置
# sys_sess_dir, the session dir
SYS_SESS_DIR = /tmp/extman/
改为:SYS_SESS_DIR = /var//tmp/extman/还有一种常见错误就是提示
Can't open /tmp/extman//sid_89b33ec5ce0b5903f24035aa4ad76d15, Permission denied
这个是因为extman 那个临时目录的权限不对。
可以设置为777就ok了
问题11:点extman后台图像日志报错:
Can't locate RRDs.pm in @INC (@INC contains: /var/www/extsuite/extman/libs /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /var/www/extsuite/extman/libs/Ext/GraphLog.pm line 23. BEGIN failed--compilation aborted at /var/www/extsuite/extman/libs/Ext/GraphLog.pm line 23. Compilation failed in require at /var/www/extsuite/extman/libs/Ext/MgrApp/ViewLog.pm line 22. BEGIN failed--compilation aborted at /var/www/extsuite/extman/libs/Ext/MgrApp/ViewLog.pm line 22. Compilation failed in require at /var/www/extsuite/extman/cgi/viewlog.cgi line 18.
解决方法:安装rrdtool包
[root@hmg2 src]#tar -zxvf rrdtool-1.3.1.tar.gz
[root@hmg2 src]#./configure --prefix=/usr/local/rrdtool && make && make install
cp -rp /usr/local/rrdtool/lib/perl/5.8.8/x86_64-linux-thread-multi/* /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/
运行 rrdtool –v测试安装成功没有:
[root@hmg2 src]#rrdtool -v //可以看到 RRDTool的用法以及版本信息
问题12:extman后台图形日志红叉
解决方法:
[root@mail lib]# tar zxvf File-Tail-0.99.3.tar.gz
[root@mail lib]# cd File-Tail-0.99.3
[root@mail lib]# perl Makefile.PL
[root@mail lib]# make
[root@mail lib]# make install
[root@ivon lib]# /usr/local/mailgraph_ext/mailgraph-init start
引用 :
 /usr/local/mailgraph_ext/mailgraph-init start
将这 2句复制到/etc/rc.d/rc.local(linux)或/etc/rc.conf(bsd)便于系统重启动后自动启动相关进程。过一段时间看/var/lib下是否产生了mailgraph_**.rr