发新话题
打印

全功能邮箱反垃圾反病毒+webmail最新源码编译安装(postfix)

全功能邮箱反垃圾反病毒+webmail最新源码编译安装(postfix)

+++++++++++++++++++++++++++++++++++++++++++
秀脱实战笔记之postfix病毒过滤和反垃圾实战篇:
    QQ:      6541657
EMAIL:xiutuo@gmail.com
postfix-2.5.1_postfixadmin-2.2.0-rc3_
dovecot-1.0.12_SpamAssassin-3.2.4
_amavisd-new-2.5.4_clamav-0.92.1
pam_mysql_cyrus-sasl-auth
外加webmail:squirrelmail-1.4.13
apache2.2.6_php-5.2.5_mysql5_gd

秀脱bloghttp://hi.baidu.com/xiutuo/
++++++++++++++++++++++++++++++++++++++++++
功能:
postfix完全虚拟用户,采用mysql数据库,虚拟用户映射的真实用户和组是postfix
pop3:dovecot作为邮局服务,mysql认证
本地邮件代理mta(lda)使用dovecot,可以对每个用户进行邮件容量限制。
postfix用户和组的id都是12345
smtp认证:采用cyrus-sasl-auth认证功能-通过pam调用pam_mysql-md5加密
采用postfixadmin来管理虚拟域和用户以及邮箱别名
通过amavis-new做中间件,介于邮件服务和反垃圾、病毒过滤服务之间
反垃圾功能:spamassasin,在垃圾邮件标题提示**spam**,并通知管理员
病毒过滤:clamav,病毒邮件直接丢弃并存在放在病毒隔离目录,并通知管理员
webmail:squirrelmail-1.4.13通过web页面发送电子邮件,最大附件上传10m

-----------------
环境:
****服务器
操作系统:contos4.5
ip:192.168.1.230
域名:xiutuo.com
全域名称:xt.xiutuo.com
mx记录:mail.xiutuo.com
下载所有软件包放在/home/xiutuo/software目录下
dns:
ypbind-1.17.2-13.rpm
bind-utils-9.2.4-24.EL4.rpm
bind-9.2.4-24.EL4.rpm
bind-libs-9.2.4-24.EL4.rpm
bind-chroot-9.2.4-24.EL4.rpm
pam_mysql:
pam_mysql-0.7RC1.tar.gz
后缀名.so文件安装/lib/security/目录下
cyrus-sasl:
cyrus-sasl-md5-2.1.19-5.EL4.rpm
cyrus-sasl-plain-2.1.19-5.EL4.rpm
cyrus-sasl-devel-2.1.19-5.EL4.rpm
cyrus-sasl-2.1.19-5.EL4.rpm
cyrus库文件安装在/usr/lib/sasl2/
postfix:
postfix-2.5.1.tar.gz
安装路径 /usr(采用默认的安装路径)
postfixadmin:
postfixadmin-2.2.0-rc3.tar.gz
安装路径 /usr/local/apache2/htdocs/postfixadmin
squirrelmail:
安装路径 /usr/local/apache2/htdocs/webmail
apache2:
apache2.2.6.tar.gz
安装路径 /usr/local/apache2
mysql5数据库:
安装路径 /usr/local/mysql
建立postfix数据库和相关虚拟用户的使用的表,
参照postfixadmin提供的sql脚本DATABASE_MYSQL.TXT
访问数据库用户root,密码123456
php5:php-5.2.5.tar.gz
安装路径 /usr/local/php
dovecot--pop3,imap:源码安装路径/usr/local
dovecot-1.0.12.tar.gz
amavis-new:
amavisd-new-2.5.4.tar.gz
安装路径 /usr/local
clamav:
clamav-0.92.1.tar.gz
安装路径 /usr/local
SpamAssassin
Mail-SpamAssassin-3.2.4.tar.gz
采用perl命令安装,安装成perl模块
perl -MCPAN -e shell
需要总的perl 模块:见文章最后附录

****客户端
邮件客户端outlook express
或者foxmail
-----------------
一:软件安装
0. dns安装,请参照blog文章:
http://hi.baidu.com/xiutuo/blog/item/047f3c06b966e6780308810b.html
cyrus-sasl的rpm包安装:
# rpm -ivh cyrus-sasl*
1.apache2_php5_mysql5 安装见blog文章:
http://hi.baidu.com/xiutuo/blog/item/e7b42b31ca4d191aebc4aff0.html
切记安装该组合需要其他的软件包!!!
编译php的时候记得加上--enable-mbstring,
否则使用setup.php安装postadmin的时候,(当然可以忽略这个错误)
提示错误如下:
Error: Depends on: multibyte string - NOT FOUND
pam_mysql安装:
# ./configure --with-pam-mods-dir=/lib/security \
--with-mysql=/usr/local/mysql \
--with-pam=/usr \
--with-cyrus-sasl2=/usr/lib/security \
--with-openssl
必须这样安装,才不会出错。

2.安装postfixadmin
# cd /home/xiutuo/software
# tar -zxvf postfixadmin-2.2.0-rc3.tar.gz
# mv postfixadmin-2.2.0-rc3 /usr/local/apache2/htdocs/postfixadmin
# cd /usr/local/apache2/htdocs/postfixadmin
# 把postfixadmin目录下的sql脚本DATABASE_MYSQL.TXT
# 导入mysql,建立postfix数据库并赋予postfix用户,密码123456
# mysql -u root < DATABASE_MYSQL.TXT
# 配置postfixadmin 数据库连接参数
# vi config.inc.php
修改以下参数
//$CONF['configured'] = false; 注释此行,在运行postfixadmin时
$CONF['database_type'] = 'mysql'; //数据库类型
$CONF['database_host'] = 'localhost'; //数据库服务器名
$CONF['database_user'] = 'postfix'; //数据库用户名
$CONF['database_password'] = '123456'; //数据库用户密码
$CONF['database_name'] = 'postfix';    //数据库名
$CONF['database_prefix'] = ''; //库前缀,这里为空
$CONF['admin_email'] = [email=%20xiutuo@xiutuo.com%20]'xiutuo@xiutuo.com'[/email]; //管理帐号
$CONF['smtp_server'] = 'localhost'; //邮件服务器ip
$CONF['smtp_port'] = '25'; //邮件服务器端口
$CONF['encrypt'] = 'md5'; //密码加密方式,选择自己需要的
$CONF['quota'] = 'YES'; //如果需要对用户邮箱进行限制,请用yes
其他参数根据自己需要修改!
# 设置postfixadmin文件夹权限和属组。
# chown -R xiutuo:xiutuo postfixadmin
# chmod -R 755 postfixadmin
插入相关管理员和虚拟域名数据
管理员xiutuo@xiutuo.com 密码123456
虚拟域 xiutuo.com,xt.xiutuo.com virtual.com
用户邮箱:[email=xt@xiutuo.com,test@xiutuo.com]xt@xiutuo.com,test@xiutuo.com[/email] 密码都是123456
注:mailbox表中quota就是容量限制字段。dovecot 默认采用k作为容量限制单位。
INSERT INTO `domain` (`domain`, `description`, `aliases`, `mailboxes`,
`maxquota`, `quota`, `transport`, `backupmx`, `created`, `modified`,
`active`) VALUES ('virtual.com', 'virtual.com', 10, 10, 0, 0, 'virtual',
0, '2008-03-25 21:14:11', '2008-03-25 21:14:11', 1),('xiutuo.com',
'xiutuo.com', 0, 0, 0, 0, 'dovecot', 0, '0000-00-00 00:00:00',
'0000-00-00 00:00:00', 1),('xt.xiutuo.com', 'ddd', 10, 10, 0, 0,
'virtual', 0, '2008-03-25 21:16:10', '2008-03-25 21:16:10', 1);
INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`)
VALUES ([email=%20xiutuo@xiutuo.com%20]'xiutuo@xiutuo.com'[/email], 'ALL', '0000-00-00 00:00:00', 1);
INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`,
`domain`, `created`, `modified`, `active`) VALUES ([email=%20xt@xiutuo.com%20]'xt@xiutuo.com'[/email],
'e10adc3949ba59abbe56e057f20f883e', 'e10adc3949ba59abbe56e057f20f883e',
[email=%20xt@xiutuo.com%20]'xt@xiutuo.com'[/email], 0, 'xiutuo.com', '0000-00-00 00:00:00',
'2008-04-01 16:00:20', 1),([email=%20xiutuo@virtual.com%20]'xiutuo@virtual.com'[/email],
'e10adc3949ba59abbe56e057f20f883e', 'xiutuo', [email=%20xiutuo@virtual.com/%20]'xiutuo@virtual.com/'[/email],
0, 'virtual.com', '2008-03-25 21:14:42', '2008-03-25 21:14:42', 1),
([email=%20test@xiutuo.com%20]'test@xiutuo.com'[/email], 'e10adc3949ba59abbe56e057f20f883e', 'test',
[email=%20test@xiutuo.com/%20]'test@xiutuo.com/'[/email], 0, 'xiutuo.com', '2008-03-26 20:44:39', '2008-03-26 20:44:39', 1);
超级用户管理地址:
http://xt.xiutuo.com/postfixadmin/admin
普通用户管理地址
http://xt.xiutuo.com/postfixadmin/users
3.dovecot安装
先卸载系统自带的dovecot-0.99
增加dovecot用户用来启动dovecot
# useradd dovecot -d /dev/null -s /sbin/nologin
# rpm -e dovecot
# cd /home/xiutuo/software
# tar -zxvf dovecot-1.0.12.tar.gz
# cd dovecot-1.0.12
# ./configure --sysconfdir=/etc --with-mysql
# make
# make install
# cp /etc/dovecot-example.conf /etc/dovecot.conf
没有配置好dovecot.conf时,请先别启动dovecot
启动dovecot:
# dovecot -c /etc/dovecot.conf
弄成开机自启动,自己写个简单脚本,仿照mysql的自启动方式。
或者总结在在/etc/rc.d/rc.local加入
dovecot -c /etc/dovecot.conf
4.postfix安装:
# rpm -e sendmail --nodeps    #卸载系统自带的sendmail
# 增加postfix用户和postfix用户组
# adduser postfix -d /dev/null -s /sbin/nologin
# 建立虚拟用户邮件目录
# mkdir /var/vmail
# chown postfix:postfix /var/vmail
# cd /home/xiutuo/software
# tar -zxvf postfix-2.5.1.tar.gz
postfix采用默认安装路径,支持mysql,和dovecot-sasl-auth
# make install
# 注意make install过程会提示postfix各个文件安装路径,直接回车选择默认即可
成功安装后,查看是否启用了cyrus-sasl-auth认证
# make -f Makefile.init makefiles \
'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include \
-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' \
'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm \
-L/usr/local/lib -lsasl2'
# make install
# postconf -a
cyrus
有cyrus说明ok了。
*********************************************
如果要编译其他的请参照postfix安装说明,切记
CCARGS开头的都组合在一起,AUXLIBS开头的组合在一起,如下面的
# make -f Makefile.init makefiles \
'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/ \
-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/sasl2/include/sasl \
-I/usr/local/BerkeleyDB/include \
-DUSE_TLS -I/usr/local/ssl/include/openssl '
'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm \
-L/usr/local/sasl2/lib -lsasl2 \
-L/usr/local/BerkeleyDB/lib \
-L/usr/local/ssl/lib -lssl -lcrypto'
以上编译支持mysql,cyrus_sasl,openssl,BerkeleyDB
------
# make -f Makefile.init makefiles \
'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include \
-DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\"dovecot\"' \
'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm'
*********************************************
5.安装SpamAssassin,以perl 模块方式安装
事先需要安装的perl模块
# perl -MCPAN -e shell
cpan> install HTML::Parser
cpan> install Mail::SPF
cpan> install Mail::SPF::Query
cpan> install IP::Country
cpan> install Razor2
cpan> install Net::Ident
cpan> install IO::Socket::INET6
cpan> install IO::Socket::SSL
cpan> install Compress::Zlib
cpan> install Mail::DomainKeys
cpan> install Mail::DKIM
cpan> install Archive::Tar
cpan> install IO::Zlib
cpan> install Encode::Detect
********************************************
在安装这里模块时候会出现perl模块依赖关系,处理原则,缺什么安装什么。
安装文档全套需要的perl模块列表见文章最后。
这里推荐使用perl命令来安装(比较慢),建议:
a.先下载相关源码安装。源码安装方法
# tar -zxvf perl模块.tar.gz
# cd perl模块目录
# perl Makefile.PL
# make
# make install
b.如果源码方式安装出现out of date错误或者出现未知的perl依赖模块时,
再使用perl命令安装,这样会很好的解决问题。
perl命令安装方式(使用root用户操作):
# perl -MCPAN -e shell
cpan> o conf prerequisites_policy ask
cpan> install Mail::SpamAssassin //安装Mail::SpamAssassin模块
cpan> quit    //退出
*******************************************

6.安装clamav
# 注意安装clamav-0.92.1需要zlib-1.2.3,否则报zlib有bug错误,
# 可以通过--disable-zlib-vcheck 参数忽略zlib报错(不推荐)
# 增加启动clamav的用户clamav
# adduser clamav -d /dev/null -s /sbin/nologin
# id clamav
uid=12347(clamav) gid=12347(clamav) groups=12347(clamav)
# cd /home/xiutuo/software
# tar -zxvf clamav-0.92.1.tar.g
# cd clamav-0.92.1
# zlib-1.2.3安装见apache2的安装文档,安装在/usr/local/zlib目录
***************************************
# tar zvxf zlib-1.2.3.tar.gz
# cd zlib-1.2.3
# ./configure --prefix=/usr/local/zlib --shared
# make
# make test
# make install
**************************************
# ./configure --prefix=/usr/local/clamav/ \
--with-zlib=/usr/local/zlib \
--with-user=clamav --with-group=clamav
# make
# make install
# touch /var/log/clamav/freshclam.log
# chmod 600 /var/log/clamav/freshclam.log
# chown clamav:clamav /var/log/clamav/freshclam.log
# freshclam -d
./freshclam: error while loading shared libraries: libiconv.so.2: cannot open sh
ared object file: No such file or directory
加个连接就好了
# ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
7.安装amavisd-new.tar.gz
需要的模块:
# perl -MCPAN -e shell
cpan> install Archive::Zip
cpan> install Compress::Zlib
cpan> install Convert::TNEF
cpan> install MIME::Base64
cpan> install MIME::Parser
cpan> install Mail::Internet
cpan> install Net::Server
cpan> install Digest::MD5
cpan> install IO::Stringy
cpan> install Time::HiRes
cpan> install Unix::Syslog
cpan> install BerkeleyDB
cpan> install Mail::ClamAV
cpan> install IO::Wrap
cpan> install IO::Stringy
cpan> install Unix::Syslog
cpan> install Compress::Zlib
cpan> install MIME::Words
cpan> install MIME::Head
cpan> install MIME::Body
cpan> install MIME::Entity
cpan> install MIME::Parser
cpan> install MIME::Decoder
cpan> install MIME::Decoder::Base64
cpan> install MIME::Decoder::Binary
cpan> install MIME::Decoder::QuotedPrint
cpan> install MIME::Decoder::NBit
cpan> install MIME::Decoder::UU
cpan> install MIME::Decoder::Gzip64
cpan> install Net::Server
cpan> install Net::Server::PreFork
此安装过程需要其他的perl模块列表见文章最后,提示少什么装什么。
这里我们使用clamav用户来启动amavis,就不单独建立用户了。
# mkdir /var/amavis
# cd /var/amavis
在/var/amavis目录下建立tmp var db home四个目录
# mkdir tmp var db home
# chown -R clamav:clamav /var/amavis
# chmod -R 750 /var/amavis
# cd /home/xiutuo/software
# tar -zxvf amavisd-new.tar.gz
# cd amavisd-new-2.5.4
# 安装amavisd程序,并设置权限
# cp amavisd /usr/local/sbin/
# chown root /usr/local/sbin/amavisd
# chmod 755 /usr/local/sbin/amavisd
# 安装配置文件,并设置权限
# cp amavisd.conf /etc/
# chown root:clamav /etc/amavisd.conf
# chmod 640 /etc/amavisd.conf
建立病毒邮件隔离存放目录,请确保所在文件的属主为非特权用户!
必要定时对该目录清空。
# mkdir /var/virusmails
# chown clamav:clamav /var/virusmails
# chmod 750 /var/virusmails
安装软件部分到此结束

[ 本帖最后由 cckj 于 2008-6-1 13:05 编辑 ]

本文由cckj 发布于Linuxsky 论坛,网址:http://bbs.linuxsky.org/thread-6914-1-1.html

TOP

二:配置文档说明

二:配置文档说明

0. dns的配置见dns实战文档

1.apache2_php5_mysql5配置见lamp实战文档

2.涉及配置主要文件列表
cyrus-sasl:
/etc/sysconfig/saslauthd
/usr/lib/sasl2/smtpd.conf
/etc/pam.d/smtpd

dovecot:
/etc/dovecot.conf
/etc/dovecot-sql.conf

spamassassin:
/etc/mail/local.cf

clamav:
/etc/clamd.conf

amavisd-new:
/etc/amavisd.conf

postfix:
/etc/postfix/mast.cf
/etc/postfix/main.cf
/etc/postfix/mynetworks
/etc/postfix/filter_recipient_domains(可选)
/etc/postfix/mysql_relay_domains_maps.cf
/etc/postfix/mysql_virtual_alias_maps.cf
/etc/postfix/mysql_virtual_domains_maps.cf
/etc/postfix/mysql_virtual_mailbox_maps.cf
/etc/postfix/mysql_virtual_mailbox_limit_maps.cf

____________________________________________________________________

三:具体配置文件内容及说明

0.配置cyrus-sasl

a. # vi /etc/sysconfig/saslauthd 内容如下:
#**************************************************
SOCKETDIR=/var/run/saslauthd
MECH=pam
FLAGS="r"
#**************************************************

b. # vi /usr/lib/sasl2/smtpd.conf内容如下:
#**************************************************
pwcheck_method:saslauthd
#**************************************************

c. # vi/etc/pam.d/smtpd 内容如下:
注意只有auth和account俩行,crypt=3为md5加密方式
这里特别提醒,name字段值一定要是mkdir字段的@前半部分
这里就要求在postfixadmin增加用户邮箱时注意的问题。
#**************************************************
#%PAM-1.0
auth sufficient pam_mysql.so verbose=0 user=postfix passwd=123456 host=localhost db=postfix table=mailbox usercolumn=name passwdcolumn=password crypt=3
account required pam_mysql.so verbose=0 user=postfix passwd=12345 host=localhost db=postfix table=mailbox usercolumn=name passwdcolumn=password crypt=3
#**************************************************
调试时候内容如下,需要为pam_mysql建立logtable表
注意只有auth和account俩行,crypt=3为md5加密方式
#**************************************************
#%PAM-1.0
auth sufficient pam_mysql.so verbose=1 user=postfix passwd=123456 host=localhost db=postfix table=mailbox usercolumn=name passwdcolumn=password crypt=3 logtable=logtable logmsgcolumn=logmsgcolumn logusercolumn=logusercolumn logpidcolumn=logpidcolumn loghostcolumn=loghostcolumn logrhostcolumn=logrhostcolumn logtimecolumn=logtimecolumn sqllog=true
account required pam_mysql.so verbose=1 user=postfix passwd=12345 host=localhost db=postfix table=mailbox usercolumn=name passwdcolumn=password crypt=3 logtable=logtable logmsgcolumn=logmsgcolumn logusercolumn=logusercolumn logpidcolumn=logpidcolumn loghostcolumn=loghostcolumn logrhostcolumn=logrhostcolumn logtimecolumn=logtimecolumn sqllog=true
#**************************************************

1.配置dovecot
a. # vi etc/dovecot.conf 内容如下:
#**************************************************
# ***查看/etc/dovecot.conf,可以通过
# dovecot -n 命令
# ***启动dovecot:
# dovecot -c /etc/dovecot.conf
# 定义pop3,如果需要imap可以protocols: pop3 imap
protocols = pop3
# 启用明文密码认证
disable_plaintext_auth = no
# 定义日志路径
log_path = /var/log/dovelog
# 禁用ssl
ssl_disable = yes
# 使用dovecot用户启动dovecot
login_user = dovecot
# 邮件文件目录采用maildir格式
mail_location = maildir:/var/vmail/%d/%u
# 调试时候使用,以方便mysql认证调试,调试完成后关闭
mail_debug = yes
auth_verbose = yes
# 邮件格式,请务必选择,否则启动dovecot时报错。
protocol pop3 {
pop3_uidl_format = %08Xv%08Xu
}

# 使用dovecot的本地邮件投递代理,方便虚拟用户邮件投递
protocol lda {
# 管理员信箱
postmaster_address = xt@xiutuo.com
# 使用邮件限额功能
# 由于本人使用的是dovecot做为lda,所以:
# In case you're using deliver:
mail_plugins = quota
# 否则,需要增加如下配置
#***********************
# protocol imap {
# mail_plugins = quota imap_quota
# }
# protocol pop3 {
# mail_plugins = quota
#}
# **********************
# dovecot本地投递代理库文件
mail_plugin_dir = /usr/local/lib/dovecot/lda
# dovecot本地投递代理日志
log_path = /var/log/dovecot-deliver.log
info_log_path = /var/log/dovecot-deliver.log
# 邮件服务器mta的使用程序路径,该sendmail是postfix的一个连接文件
sendmail_path = /usr/sbin/sendmail
# 采用socket方式
auth_socket_path = /var/run/dovecot/auth-master
}
# 设置你的realm,这里设置了,dovecot进行认证的时候会自动
# 去除outlook提交的认证用户名中的域名。当然视邮件客户端认证时候是否提交了
# 此格式的用户名:user@domain.com,我这里的域名为 xt.xiutuo.com
# 配置了该参数,outlook输入用户名字的时候可以输入成user@domain.com
#形式如:xiutuo@xt.xiutuo.com, 也可以直接输入用户名user如:xiutuo
# 多个域名请用空格隔开
auth_realms = xt.xiutuo.com xiutuo.com
auth_default_realm = xiutuo.com
# 验证方式,这里采用了mysql明文认证方式,故mechanisms = plain
# mysql认证的用户和密码配置文件为/etc/dovecot-sql.conf
auth default {
mechanisms = plain

passdb sql {
    args = /etc/dovecot-sql.conf
}

userdb sql {
    args = /etc/dovecot-sql.conf
}

userdb prefetch {
}

user = nobody

socket listen {
    master {
      path = /var/run/dovecot/auth-master
      mode = 0660
      user = postfix
      group = postfix
    }
# 因为采用cyrus-sasl-auth所以,以下配置必须注释!
# 以下是使用dovecot-sasl-auth认证的配置,使用postfix用户和组
# dovecot-sasl-auth认证和postfix虚拟用户都使用相同的postfix用户和组,
# 可以避免启动dovecot,再启动postfix时候/var/spool/postfix/private/auth权限访问错误问题
#   client {
#      path = /var/spool/postfix/private/auth
#      mode = 0660
#      user = postfix
#      group = postfix
#   }
}
}

dict {
}

# 邮件大小限制
plugin {
# 这里说明maildir的容量是10M,最大邮件数为1千
quota = maildir:storage=10240:messages=1000
acl = vfile:/etc/dovecot-acls
trash = /etc/dovecot-trash.conf

}


#*********************************************************

b./etc/dovecot-sql.conf内容如下

# vi /etc/dovecot-sql.conf
#*********************************************************

# 数据库认证文件/etc/dovecot-sql.conf
# 其中12345 AS uid和12345 AS gid的12345是postfix用户和组的id
# 可以通过命令id postfix查看postfix用户和组信息,见安装postfix部分

# vi /etc/dovecot-sql.conf 内容如下(此配置文件没有对用户容量限制)
#*********************************************************
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=123456
# default_pass_scheme = PLAIN
user_query = SELECT maildir,12345 AS uid, 12345 AS gid FROM mailbox WHERE username = '%u' AND active = '1'
password_query = SELECT password FROM mailbox WHERE username = '%u' AND active = '1'

#*********************************************************

如果需要对每个用户邮件容量限制,/etc/dovecot-sql.conf 内容如下

#*********************************************************
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=123456
# default_pass_scheme = PLAIN
user_query = SELECT maildir,12345 AS uid, 12345 AS gid,concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'
password_query = SELECT password FROM mailbox WHERE username = '%u' AND active = '1'

#*********************************************************
切记quota格式一定要跟quota = maildir:storage=10240对应,
所以这里才需要用到concat连接函数
concat('maildir:storage=', quota) AS quota意思就是将
maildir:storage=这个字符串连接mailbox表字段quota的值作为quota字段
记得插入用户数据时记得填写quota字段值

2.spamassassin:
/etc/mail/local.cf 内容如下:
可以通过web页面http://www.yrex.com/spam/spamconfig.php配置生成。
#****************************************************************
# SpamAssassin config file for version 3.x
# NOTE: NOT COMPATIBLE WITH VERSIONS 2.5 or 2.6
# See http://www.yrex.com/spam/spamconfig25.php for earlier versions
# Generated by http://www.yrex.com/spam/spamconfig.php (version 1.50)

# How many hits before a message is considered spam.
required_score           5.0

# Change the subject of suspected spam
rewrite_header subject         *****SPAM*****

# Encapsulate spam in an attachment (0=no, 1=yes, 2=safe)
report_safe             1

# Enable the Bayes system
use_bayes               1

# Enable Bayes auto-learning
bayes_auto_learn              1

# Enable or disable network checks
skip_rbl_checks         0
use_razor2              1
use_dcc                 1
use_pyzor               1

# Mail using languages used in these country codes will not be marked
# as being possibly spam in a foreign language.
ok_languages            all

# Mail using locales used in these country codes will not be marked
# as being possibly spam in a foreign language.
ok_locales              all

# Disabled scores. chinese subtitle or context problem
# 以下是防止中文内容误判增加的配置
score HEADER_8BITS 0
score HTML_COMMENT_8BITS 0
score SUBJ_FULL_OF_8BITS 0
score UPPERCASE_25_50 0
score UPPERCASE_50_75 0
score UPPERCASE_75_100 0
#******************************************************************

3.clamav:
/etc/clamd.conf 内容如下:
#******************************************************************
# 指定日志文件
LogFile /var/log/clamav/clamd.log
LogSyslog yes
LogFacility LOG_MAIL
# 开启调试日志,方便调试
LogVerbose yes
# 指定进程文件路径
PidFile /var/run/clamd.pid
# 指定病毒库路径,记得DatabaseDirectory指定目录下有daily.inc目录,
# 指定错误会报错:找不到daily.inc目录
DatabaseDirectory /usr/local/share/clamav/
# 指定clamd.socket路径
LocalSocket /var/run/clamd.socket
#******************************************************************

4.amavisd-new:
# vi /etc/amavisd.conf 以下是*部分*修改的地方,其他均为默认配置
#******************************************************************
# 使用clamav用户和组启动amavis
$daemon_user = 'clamav';   
$daemon_group = 'clamav';
# 域名,这里为xiutuo.com
$mydomain = 'xiutuo.com';
# 指定amavis的主目录
$MYHOME = '/var/amavis';
$TEMPBASE = "$MYHOME/tmp";
$ENV{TMPDIR} = $TEMPBASE;
# 指定amavis的病毒隔离目录
$QUARANTINEDIR = '/var/virusmails'
# 指定bdb nanny/cache/snmp 库目录
$db_home   = "$MYHOME/db";
# 指定为SpamAssassin工作目录
$helpers_home = "$MYHOME/var";
# 指定lock_file路径
$lock_file = "$MYHOME/var/amavisd.lock";
# 指定pid_file路径
$pid_file = "$MYHOME/var/amavisd.pid"
# 修改192.168.0.0/16为192.168.1.0/24
@mynetworks = qw( 127.0.0.0/8 [::1] [FE80::]/10 [FEC0::]/10
                  10.0.0.0/8 172.16.0.0/12 192.168.1.0/24);
# 下面这句很重要,为外来连接设置的端口
# Configuring amavisd-new for incoming connections
$inet_socket_port = 10024;
# 主机名(全域名称)

# 设置通知admin邮箱,一旦用户发送病毒或者spam邮件可以通知的邮箱
$myhostname = 'xt.xiutuo.com';
$virus_admin               = "xt\@$mydomain"; # notifications recip.
$mailfrom_notify_admin     = "xt\@$mydomain"; # notifications sender
$mailfrom_notify_recip     = "xt\@$mydomain"; # notifications sender
$mailfrom_notify_spamadmin = "xt\@$mydomain"; # notifications sender


# 下面俩句很重要, 转发端口配置
# Configuring the reinjection path
$notify_method = 'smtp:[127.0.0.1]:10025';
$forward_method = 'smtp:[127.0.0.1]:10025'; # set to undef with milter!

# 以下四个根据需要调成D_DISCARD或D_BOUNCE或D_REJECT或D_PASS
$final_virus_destiny      = D_DISCARD;
$final_banned_destiny     = D_BOUNCE;
$final_spam_destiny       = D_BOUNCE;
$final_bad_header_destiny = D_PASS;
$bad_header_quarantine_method = undef;
# 开启clamav杀毒功能,注意clamav的socket文件路径/var/run/clamd.socket,
# 一定要跟clamd.conf配置的一致
['ClamAV-clamd',
\&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamd.socket"],
qr/\bOK$/, qr/\bFOUND$/,
qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],
#******************************************************************


5.postfix:

a. # vi /etc/postfix/mast.cf内容如下
#******************************************************************
# smtp定义,默认已有
smtp      inet n       -       n       -       -       smtpd
# 以下均默认配置
pickup    fifo n       -       n       60      1       pickup
cleanup   unix n       -       n       -       0       cleanup
qmgr      fifo n       -       n       300     1       qmgr
tlsmgr    unix -       -       n       1000?   1       tlsmgr
rewrite   unix -       -       n       -       -       trivial-rewrite
bounce    unix -       -       n       -       0       bounce
defer     unix -       -       n       -       0       bounce
trace     unix -       -       n       -       0       bounce
verify    unix -       -       n       -       1       verify
flush     unix n       -       n       1000?   0       flush
proxymap unix -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix -       -       n       -       -       smtp
relay     unix -       -       n       -       -       smtp
-o smtp_fallback_relay=
showq     unix n       -       n       -       -       showq
error     unix -       -       n       -       -       error
retry     unix -       -       n       -       -       error
discard   unix -       -       n       -       -       discard
local     unix -       n       n       -       -       local
virtual   unix -       n       n       -       -       virtual
lmtp      unix -       -       n       -       -       lmtp
anvil     unix -       -       n       -       1       anvil
scache    unix -       -       n       -       1       scache
# 定义使用dovecot为lda(mta)
dovecot   unix -       n       n       -       -       pipe
flags=DRhu user=postfix:postfix argv=/usr/local/libexec/dovecot/deliver -d ${recipient}
# amavis-new和postfix整合的配置,配置成dedicated lmtp-client模式
smtp-amavis unix -      -       n       -       2 lmtp
    -o lmtp_data_done_timeout=1200
    -o lmtp_send_xforward_command=yes
# amavis-new和postfix整合的配置
# Configuring a dedicated SMTP-server for message reinjection
127.0.0.1:10025 inet n -       n       -       - smtpd
    -o content_filter=
    -o local_recipient_maps=
    -o relay_recipient_maps=
    -o smtpd_restriction_classes=
    -o smtpd_client_restrictions=
    -o smtpd_helo_restrictions=
    -o smtpd_sender_restrictions=
    -o smtpd_recipient_restrictions=permit_mynetworks,reject
    -o mynetworks=127.0.0.0/8
    -o strict_rfc821_envelopes=yes
    -o smtpd_error_sleep_time=0
    -o smtpd_soft_error_limit=1001
    -o smtpd_hard_error_limit=1000

#******************************************************************

b. # vi /etc/postfix/main.cf 内容如下
#******************************************************************
# 以下四项是编译安装时候自动配置路径参数
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix

# 指定主机名(也就是全域名称)
myhostname = xt.xiutuo.com
# 指定域名
mydomain = xiutuo.com
myorigin = $myhostname
myorigin = $mydomain
# 指定postfix使用的网络接口,这里选择所有网络接口
inet_interfaces = all
unknown_local_recipient_reject_code = 550
# 指定本地网络,postfix本地网络发送邮件可以不使用认证,
# 但是需要配置本地网络地址,这里采用mynetworks文件来配置
mynetworks = $config_directory/mynetworks
# 指定relay_domains,通过mysql数据库
relay_domains = mysql:$config_directory/mysql_relay_domains_maps.cf

address_verify_map = btree:/var/spool/postfix/address_verify
# 记得去掉默认配置后面的nis项,否则出错:postfix NIS name do not set
alias_maps = hash:/etc/aliases
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5

# 指定postfix程序路径,这里sendmail其实是postfix的一个连接文件
sendmail_path = /usr/sbin/sendmail
# 指定newaliases程序路径
newaliases_path = /usr/bin/newaliases
# 指定mailq程序路径
mailq_path = /usr/bin/mailq
setgid_group = postdrop
# 以下几项是默认安装相关参数
# 不使用帮助的html文件
html_directory = no
manpage_directory = /usr/local/man
sample_directory = /etc/postfix
local_recipient_maps = $virtual_mailbox_maps
readme_directory = no
#
#------------------------virtual configure-----------------------
# 虚拟域和用户配置相关参数
virtual_mailbox_domains = mysql:$config_directory/mysql_virtual_domains_maps.cf
virtual_mailbox_base = /var/vmail
virtual_mailbox_maps = mysql:$config_directory/mysql_virtual_mailbox_maps.cf
virtual_alias_maps = mysql:$config_directory/mysql_virtual_alias_maps.cf
virtual_minimum_uid = 500
# 这里就是虚拟用户映射的真实用户postfix和组postfix,postfix的uid和gid都是12345
virtual_uid_maps = static:12345
virtual_gid_maps = static:12345
# 使用dovecot作为本地投递代理mta(或者叫lda)
virtual_transport = dovecot
#
#---------------------end virtual configure---------------------
#
# 这里采用cyrus-sasl-auth,所以注释dovecot-sasl-auth配置行
#---------------------dovecot-sasl-auth configure---------------
#dovecot_destination_recipient_limit = 1
#
# 启用sasl验证
#smtpd_sasl_auth_enable = yes
# 指定sasl验证方式为dovcecot-sasl-auth
#smtpd_sasl_type = dovecot
#smtpd_sasl_authenticated_header = yes
#smtpd_sasl_security_options = noanonymous
# 邮件客户端用户验证
#smtp_sasl_password_maps = mysql:$config_directory/mysql_virtual_mailbox_maps.cf
#smtpd_sasl_path = /var/spool/postfix/private/auth
#broken_sasl_auth_clients = yes
#
#------------------end dovecot-sasl-auth configure--------------
#
#---------------------cyrus-sasl-auth configure-----------------
# 启用sasl验证
smtpd_sasl_auth_enable = yes
# 指定sasl验证方式为cyrus-sasl-auth
smtpd_sasl_type = cyrus
# 这个就是对应cyrus-sasl配置文件/usr/lib/sasl2/smtpd.conf和/etc/pam.d/smtpd
# 如果smtpd_sasl_path = smtp,就对应/usr/lib/sasl2/smtp.conf和/etc/pam.d/smtp了。
# 如果cyrus-sasl是源码安装,请找对应路径。
smtpd_sasl_path = smtpd
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
#broken_sasl_auth_clients = yes
#
#------------------end cyrus-sasl-auth configure--------------

smtpd_helo_required = yes
disable_vrfy_command = yes
non_fqdn_reject_code = 450
invalid_hostname_reject_code = 450
maps_rbl_reject_code = 450
# 收信规则
smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        permit_tls_clientcerts,
        reject_unauth_destination,
        reject_invalid_helo_hostname,
        warn_if_reject reject_non_fqdn_helo_hostname,
        warn_if_reject reject_unknown_helo_hostname,
        warn_if_reject reject_unknown_client,
        reject_non_fqdn_sender,
        reject_non_fqdn_recipient,
        reject_unknown_sender_domain,
        reject_unknown_recipient_domain,
        warn_if_reject reject_unverified_sender,
        reject_unverified_recipient,
        check_helo_access cidr:$config_directory/mynetworks.deny,
        check_helo_access cidr:$config_directory/reserved_ip.deny,
        check_sender_mx_access cidr:$config_directory/reserved_ip.deny,
        check_recipient_access hash:/etc/postfix/filter_recipient_domains
        reject_rbl_client cbl.abuseat.org,
        reject_rbl_client list.dsbl.org,
        reject_rbl_client opm.blitzed.org,
        reject_rbl_client sbl.spamhaus.org,
        reject_rbl_client bl.spamcop.net,
        reject_rbl_client dnsbl.sorbs.net=127.0.0.2,
        reject_rbl_client dnsbl.sorbs.net=127.0.0.3,
        reject_rbl_client dnsbl.sorbs.net=127.0.0.4,
        reject_rbl_client dnsbl.sorbs.net=127.0.0.5,
        reject_rbl_client dnsbl.sorbs.net=127.0.0.7,
        reject_rbl_client dnsbl.sorbs.net=127.0.0.9,
        reject_rbl_client dnsbl.sorbs.net=127.0.0.11,
        reject_rbl_client dnsbl.sorbs.net=127.0.0.12,
        warn_if_reject reject_rhsbl_sender dsn.rfc-ignorant.org,
        warn_if_reject reject_rhsbl_sender abuse.rfc-ignorant.org,
        warn_if_reject reject_rhsbl_sender whois.rfc-ignorant.org,
        warn_if_reject reject_rhsbl_sender bogusmx.rfc-ignorant.org,
        warn_if_reject reject_rhsbl_sender postmaster.rfc-ignorant.org,
        permit
smtpd_data_restrictions =
        reject_unauth_pipelining,
        reject_multi_recipient_bounce,
        permit
# clamav过滤规则设置
content_filter=smtp-amavis:[127.0.0.1]:10024
#******************************************************************

c. # vi /etc/postfix/mynetworks 内容如下
这里我本地网络是192.168.1.0/24 和本地环回(默认配置)
**当测试sasl认证的时候,请去除192.168.1.0/24,切记。
#******************************************************************
127.0.0.0/8
192.168.1.0/24
#******************************************************************


d. # vi /etc/postfix/filter_recipient_domains 可选
格式是一个域名字段:如
xiutuo.com
然后生成filter_recipient_domains.db文件
# postmap /etc/postfix/filter_recipient_domains

e. # vi /etc/postfix/mysql_relay_domains_maps.cf 内容如下
#******************************************************************
user = postfix
password = 123456
hosts = localhost
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = '1'
#******************************************************************

f. # vi /etc/postfix/mysql_virtual_alias_maps.cf 内容如下
#******************************************************************
user = postfix
password = 123456
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
#******************************************************************

g. # vi /etc/postfix/mysql_virtual_domains_maps.cf 内容如下
#******************************************************************
user = postfix
password = 123456
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'
#******************************************************************

h. # vi /etc/postfix/mysql_virtual_mailbox_maps.cf 内容如下
#******************************************************************
user = postfix
password = 123456
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'
#******************************************************************

j. # vi /etc/postfix/mysql_virtual_mailbox_limit_maps.cf 内容如下
#******************************************************************
user = postfix
password = 123456
dbname = postfix
query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
#******************************************************************


————————————————————————————————————

TOP

四. 整体调试

0. 开启dns服务:service named start
   开启apache:/etc/init.d/apachectl start
   开启mysql:/etc/init.d/mysql start

1. 开启dovecot
# dovecot -c /etc/dovecot.conf
查看是否启动成功
# netstat -tl
tcp 0 0 *:pop3   *:*   LISTEN

或者
# ps -ef | grep dov
root      4280     1 0 11:20 00:00:00 dovecot -c /etc/dovecot.conf
root      4281 4280 0 11:20 00:00:00 dovecot-auth
dovecot   4284 4280 0 11:20 00:00:00 pop3-login
dovecot   4285 4280 0 11:20 00:00:00 pop3-login
dovecot   4298 4280 0 11:41 00:00:00 pop3-login

有pop3代表成功

查看etc/dovecot.conf,可以通过命令
# dovecot -n

2. clamv
a.启动clamav,开启clamd之前务必先配置clamd.conf文件。否则报错。
# clamd
查看是否启动成功
# ps -e | grep clamd
有clamd进程说明启动成功

b.更新clamav病毒库(--quiet参数:不输入更新日志)
以root身份使用计划任务让clamav病毒库自动更新
# crontab -e
N * * * * /usr/local/bin/freshclam --quiet
其中N是你要输入的数字!或者手动输入命令来更新:
# freshclam

c. 测试病毒扫描,进入clamav源码文件夹所在的test目录,其中scan.txt记录扫描结果
# clamscan -r -l scan.txt clamav-x.yz

d. 测试邮件病毒扫描是否启用请看amavis-new测试部分

e.查看日志
# cat /var/log/clamav/clamd.log
# cat /var/log/clamav/freshclam.log
# cat /var/log/maillog

3.postfix
a. 开启
# postfix start
查看是否启动
# ps aux | grep postfix
root     26976 1.0 0.4 5504 1260 ?        Ss   23:20   0:00 /usr/libexec/postfix/master
postfix 26977 0.5 0.5 5476 1284 ?        S    23:20   0:00 qmgr -l -t fifo -u
postfix 26978 0.5 0.4 4644 1236 ?        S    23:20   0:00 pickup -l -t fifo -u
或者
# netstat -tl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             Stat
tcp        0      0 localhost.localdomain:smtp *:*                         LIST
这是没有启动amasiv时的情况如果启动了amasiv时:
# netstat -tl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             Stat
tcp        0      0 localhost.localdomain:10024 *:*                         LIST
tcp        0      0 localhost.localdomain:10025 *:*                         LIST

b. 停止
# postfix stop

修改配置后,重新加载
# postfix reload

查看配置
# postconf -d

查看邮件队列:其中的任何一个命令
# mailq
# sendmail -bp
# postqueue -p

c.测试25,分别用localhost和域名(全域名称)去测试,
只要其中一个telnet不上就可以说明postfix不正常工作

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 xt.xiutuo.com ESMTP Postfix
ehlo localhost
250-xt.xiutuo.com
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN //说明已经加载了cyrus-sasl
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.

说明没有问题

# telnet xiutuo.com 25
Trying 192.168.1.230...
Connected to xiutuo.com (192.168.1.230).
Escape character is '^]'.
220 xt.xiutuo.com ESMTP Postfix
ehlo localhost
250-xt.xiutuo.com
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.

说明没有问题

# telnet xt.xiutuo.com 25
Trying 192.168.1.230...
Connected to xt.xiutuo.com (192.168.1.230).
Escape character is '^]'.
220 xt.xiutuo.com ESMTP Postfix
ehlo localhost
250-xt.xiutuo.com
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.

说明没有问题

d.日志查看
# cat /var/log/maillog

4. 开启amavis-new,此步骤同时开启了spamssassin(perl模块安装的)。
a.先以debug模式开启:
# amavisd -u clamav debug

b. debug 模式下,如果没有错误提示再正常启动:
# amavisd -u clamav start

c. 停止
# amavisd -u clamav stop

d.测试amavis端口和主机

# telnet localhost 10024
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 [127.0.0.1] ESMTP amavisd-new service ready
ehlo localhost //打招呼
250-[127.0.0.1]
250-VRFY
250-PIPELINING
250-SIZE
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 XFORWARD NAME ADDR PROTO HELO
quit
221 2.0.0 [127.0.0.1] amavisd-new closing transmission channel
Connection closed by foreign host.

e.测试dedicated Postfix smtpd-daemon

# telnet localhost 10025
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 xt.xiutuo.com ESMTP Postfix
ehlo localhost //打招呼
250-xt.xiutuo.com
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.

f.测试new transport chain
# telnet localhost 10024
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 [127.0.0.1] ESMTP amavisd-new service ready
helo localhost //打招呼
250 [127.0.0.1]
mail from:<> //发件人:请一定要这样输入
250 2.1.0 Sender <> OK
rcpt to:<xt> //收件人 格式:<用户名>,该用户必须存在
250 2.1.5 Recipient <xt> OK
data //邮件内容
354 End data with <CR><LF>.<CR><LF> //以下几行是测试内容
From: virus-tester
To: undisclosed-recipients:;
Subject: amavisd test - simple - no spam test pattern

This is a simple test message from the amavisd-new test-messages.
.   //结束内容
250 2.0.0 Ok: queued as DF3466BBFF
quit
221 2.0.0 [127.0.0.1] amavisd-new closing transmission channel
Connection closed by foreign host.

成功时候结果显示类似:
Apr 3 15:25:54 xt postfix/smtpd[4361]:
connect from localhost.localdomain[127.0.0.1]
Apr 3 15:25:54 xt postfix/smtpd[4361]:
DF3466BBFF: client=localhost.localdomain[127.0.0.1]
Apr 3 15:25:54 xt postfix/cleanup[4368]:
DF3466BBFF: message-id=<20080403072554.DF3466BBFF@xt.xiutuo.com>
Apr 3 15:25:54 xt postfix/qmgr[4310]:
DF3466BBFF: from=<>, size=749, nrcpt=1 (queue active)
Apr 3 15:25:54 xt postfix/smtpd[4361]:
disconnect from localhost.localdomain[127.0.0.1]
Apr 3 15:25:55 xt amavis[4332]:
(04332-04) Passed BAD-HEADER, <> -> <xt>, mail_id: L-MJhtoG7s8J,
Hits: 2.196, size: 174, queued_as: DF3466BBFF, 20715 ms
Apr 3 15:25:55 xt postfix/pipe[4370]:
DF3466BBFF: to=<xt@xiutuo.com>, orig_to=<xt>, relay=dovecot, delay=0.36,
delays=0.14/0.04/0/0.19, dsn=2.0.0, status=sent(delivered via dovecot service)
Apr 3 15:25:55 xt postfix/qmgr[4310]: DF3466BBFF: removed

g. 测试跟postfix结合是否成功
# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 xt.xiutuo.com ESMTP Postfix
ehlo localhost //打招呼
250-xt.xiutuo.com
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<xt@xiutuo.com> // 发件人
250 2.1.0 Ok
rcpt to:<xt@xiutuo.com>   //收件人
250 2.1.5 Ok
data    //邮件内容
354 End data with . //下面那行为测试内容
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
.    //以.结束邮件内容
250 2.0.0 Ok: queued as BC24E85260
quit //退出
221 2.0.0 Bye
Connection closed by foreign host.

查看日志# cat /var/log/maillog

amavis[4299]: (04299-02) Blocked INFECTED (Eicar-Test-Signature),
MYNETS LOCAL [127.0.0.1] [127.0.0.1] <xt@xiutuo.com> -> <xt@xiutuo.com>,
quarantine: virus-YywJJlObpLBn, Message-ID: <20080402110411.9021C6BBA0@xt.xiutuo.com>,
mail_id: YywJJlObpLBn, Hits: -, size: 400, 926 ms

看到blocked表示amavis-new已经工作


h.查看日志
# cat /var/log/maillog

5.测试spamassassin
# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 xt.xiutuo.com ESMTP Postfix
ehlo localhost //打招呼
250-xt.xiutuo.com
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<xt@xiutuo.com> // 发件人
250 2.1.0 Ok
rcpt to:<xt@xiutuo.com>   //收件人
250 2.1.5 Ok
data    //邮件内容
354 End data with .   //下面那行为测试内容
Subject: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
.   //以.结束邮件内容
250 2.0.0 Ok: queued as BC24E85260
quit //退出
221 2.0.0 Bye
Connection closed by foreign host.

查看日志 # cat /var/log/maillog
amavis[4300]: (04300-02) Blocked SPAM, MYNETS LOCAL [127.0.0.1] [127.0.0.1]
<xt@xiutuo.com> -> <xt@xiutuo.com>, quarantine: spam-YdwH0RxdXoSa.gz,
Message-ID: <20080402110720.308E46BBA0@xt.xiutuo.com>,
mail_id: YdwH0RxdXoSa, Hits: 1003.959, size: 407, 2955 ms
Apr 2 19:07:29 xt postfix/lmtp[4453]: 308E46BBA0: to=<xt@xiutuo.com>,
relay=127.0.0.1[127.0.0.1]:10024, delay=15, delays=12/0.03/0.05/2.9,
dsn=2.5.0, status=sent (250 2.5.0 Ok <xt@xiutuo.com>,
DSN suppressed (554 5.7.0 Reject, id=04300-02- SPAM))

看到spam表明spamassassin已经工作

6.通过邮件客户端测试cyrus-sasl认证
本地测试:
vi /etc/postfix/mynetworks 内容如下
127.0.0.0/8
即去除192.168.1.0/24,切记。否则本地网络测试cyrus-sasl就无效

五:安装webmail:squirrelmail-1.4.13
# cd /home/xiutuo/software
# tar -zxvf squirrelmail-1.4.13.tar.gz
# mv squirrelmail-1.4.13 /usr/local/apache2/htdocs/webmail
# cd /usr/local/apache2/htdocs/webmail
# mkdir data attach
data目录已经有了就不用建了
# chown -R nobody:nobody data attach
# chmod 755 data attach
# cd config
# cp config_default.php config.php
# vi config.php 修改以下重要参数
$domain = 'example.com'; 改为 $domain = 'xiutuo.com';
$imapServerAddress = 'localhost';如果本机就是localhost,否则请填入imap服务器ip
$pop_before_smtp = false;改为true,使用pop3 before SMTP
********************************
也可以通过执行perl的配置文件来配置squirrelmail
# ./conf.pl 就出现了配置菜单,配置好后按s保存并退出。
********************************
修改默认语言:
$squirrelmail_default_language = 'zh_CN';
$default_charset = 'gb2312';
修改后,需要下载squirrelmail.mo文件放到locale/zh_CN/LC_MESSAGES/目录,以支持中文翻译
其他默认就ok,基本上就可以工作了
然后测试该配置文件
http://xiutuo.com/webmail/src/configtest.php提示一些错误
请按照错误提示修改php.ini,记得修改后重启apache。
如:magic_quotes_gpc 错误,把magic_quotes_gpc = On改为magic_quotes_gpc = off就ok
webmail附件最大上传问题,
修改php.ini中upload_max_filesize = 10M
post_max_size = 10M 默认2m 这俩个参数值记得一定要远远小于postfix定义的最大邮件存储容量。
(注意squirrelmail对超过附件最大值的邮件无超过最大值提示,不足的地方)

squirrelmail要求使用imap服务,这里需要配置dovecot为pop3和imap服务
# vi /etc/dove.conf
修改 protocols = pop3 为 protocols = pop3 imap 即可,然后重启dovecot

打开webmail:
http://xiutuo.com/webmail/
输入postfix的虚拟用户帐号和密码,ok!

六:用户邮件容量和web附件大小限制

1.用户邮件容量限制主要在:
a. 修改/etc/dovecot.conf中的
----------------------
增加或者修改以下参数
由于本人使用的是dovecot做为lda,所以:
# In case you're using deliver:
protocol lda {
mail_plugins = quota
}
plugin {
# 100MB and 10000 messages quota limit
# 其中storage单位为m,这里就是100m,最大邮件数1万
quota = dict:storage=102400:messages=1000
b.修改/etc/dovecot-sql.conf 内容如下

#*********************************************************
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=123456
# default_pass_scheme = PLAIN
user_query = SELECT maildir,12345 AS uid, 12345 AS gid,concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'
password_query = SELECT password FROM mailbox WHERE username = '%u' AND active = '1'

#*********************************************************
切记quota格式一定要跟quota = maildir:storage=10240对应,
所以这里才需要用到concat连接函数
concat('maildir:storage=', quota) AS quota意思就是将
maildir:storage=这个字符串连接mailbox表字段quota的值作为quota字段
记得插入用户数据时(通过postfixadmin管理时)记得填写quota字段值。
********************

2.修改postfxiadmin配置文件
# vi config.inc.php
$CONF['quota'] = 'YES'; //如果需要对用户邮箱进行限制,请用yes,这样增加用户邮箱时才有quota字段哦
$CONF['aliases'] = '10'; //根据需要修改单位M
$CONF['mailboxes'] = '10';//根据需要修改单位M
$CONF['maxquota'] = '10';//根据需要修改单位M

3.webmail附件最大上传问题:
修改php.ini中upload_max_filesize = 10M
post_max_size = 10M 默认2m 这俩个参数值记得一定要远远小于postfix定义的最大邮件存储容量。


————————————————————————————————

七. 安装调试中错误和解决方法

1.dns和lamp错误见blog相关文章
特别提醒:
编译php的时候记得加上--enable-mbstring,
否则使用setup.php安装postadmin的时候,(当然可以忽略这个错误)
提示错误如下:Error: Depends on: multibyte string - NOT FOUND

2.dovecot相关错误

a.需要增加dovecot用户,否则启动dovecot提示无dovecot用户
   增加用户:useradd dovecot -d /dev/null -s /sbin/nologin

b. mkdir格式需要指定,否则出错
   修改:default_mail_env = mbox:~/mail/:INBOX=/var/mail/%u
c. 默认编译采用并使用加密认证,这里我使用的明文认证,
   所以这里参数值为yes,否则启动dovecot时报错
   修改:ssl_disable = yes

d. Error: Can't connect to auth server at
   /usr/local/var/run/dovecot/auth-master: No such file or directory
   解决:修改dovecot.conf中 protocal lda auth-master的路径为:
   /var/run/dovecot/auth-master  

---------------------------------

2.clamav和amasiv-new相关错误

a.注意安装clamav-0.92.1需要zlib-1.2.3,否则报zlib有bug错误,
可以通过--disable-zlib-vcheck 参数忽略zlib报错(不推荐)
# ./configure --prefix=/usr/local/clamav/ \
--with-zlib=/usr/local/zlib \
--with-user=clamav --with-group=clamav

b. DatabaseDirectory目录指定错误提示找不到daily.inc目录
修改/etc/clamd.conf中
DatabaseDirectory /usr/local/share/clamav/

c. amavis配置文件指定clamd.socket路径一定要和clamav配置文件中指定的一样
   /etc/clamd.conf中:LocalSocket /var/run/clamd.socket
   /etc/amavisd.conf中:
['ClamAV-clamd',
\&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamd.socket"],
qr/\bOK$/, qr/\bFOUND$/,
qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],

---------------------------------

3.postfix错误

a. Mar 25 17:36:58 xt postfix/pipe[4433]: 831B26BB4E: to=<xt@xiutuo.com>,
relay=dovecot, delay=0.25, delays=0.1/0.1/0/0.06,dsn=4.3.0, status=deferred
(temporary failure. Command output: pipe: fatal: pipe_command:
execvp /usr/libexec/dovecot/deliver: No such file or directory)
修改/etc/postfix/master.cf 中的
dovecot   unix -       n       n       -       -       pipe
flags=DRhu user=vmail:mail argv=/usr/local/libexec/dovecot/deliver -d ${recipient}
的argv中dovecot的deliver路径为/usr/local/libexec/dovecot/deliver

b. deliver(xt@xiutuo.com): Mar 25 17:48:22 Error:
Can't connect to auth server at /var/run/dovecot/auth-master: Permission denied
这个时候跟/var/spool/postfix/private/auth文件的权限问题一样,
我这里启动postfix服务是postfix用户和postfix组,而启动虚拟用户的是vmail和mail组
所以我们最好使用同一帐号启动postfix和做虚拟用户的真是用户的影射,
或者把这个这俩个帐号使用相同的用户组

c.错误:postfix NIS name do not set,warning: dict_nis_init: NIS domain name not set
       - NIS lookups disabled
解决:修改/etc/postfix/main.cf中:
        alias_maps = hash:/etc/postfix/aliases 就可以禁止掉默认的nis

         原因如下:postconf -d | grep nis
         默认是:alias_maps = hash:/etc/aliases, nis:mail.aliases

e.warning: do not list domain xiutuo.com in BOTH mydestination and virtual_mailbox_domains
解决:修改/etc/postfix/main.cf中,注释下面一行
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

f.在本地服务当发往外网用户时:
Recipient address rejected: User unknown in virtual mailbox table
说明已经被列为黑名单了!!

g. RCPT from unknown{局域网内部ip}
   解决:请在/etc/postfix/mynetworks加上本地网络段 如192.168.1.0/24

h.如何把postfix安装在一个新的地方

make -f Makefile.init makefiles \
            AUXLIBS='-L/usr/lib/mysql -lmysqlclient -lz -lm -L/home/postfix/sasl
/lib -lsasl2' \
                CCARGS='-DRECEIVED_ENVELOPE_FROM -DUSE_SASL_AUTH -I/home/postfix
/sasl/include/sasl -DHAS_MYSQL -I/usr/include/mysql \
                        -DDEF_COMMAND_DIR=\"/home/postfix/sbin\" \
                        -DDEF_DAEMON_DIR=\"/home/postfix/libexec\" \
                        -DDEF_PROGRAM_DIR=\"/home/postfix/libexec\" \
                        -DDEF_QUEUE_DIR=\"/home/postfix/spool\" \
                        -DDEF_CONFIG_DIR=\"/home/postfix/etc\" \
                        -DDEF_SENDMAIL_PATH=\"/home/postfix/sbin/sendmail\" \
                        -DDEF_MAILQ_PATH=\"/home/postfix/bin/mailq\" \
                        -DDEF_NEWALIAS_PATH=\"/home/postfix/bin/newaliases\" \
                        -DDEF_SAMPLE_DIR=\"/home/postfix/doc/sample\" ' \
                OPT='-O2'
make || exit 2
sh postfix-install -non-interactive \
       install_root=/ \
       config_directory=/home/postfix/etc \
       daemon_directory=/home/postfix/libexec \
       command_directory=/home/postfix/sbin \
       queue_directory=/home/postfix/spool \
       sendmail_path=/home/postfix/sbin/sendmail \
       newaliases_path=/home/postfix/bin/newaliases \
       mailq_path=/usr/bin/mailq \
       mail_owner=${POSTFIX_USER}\
       setgid_group=${POSTFIX_GRP}\
       manpage_directory=/home/postfix/man \
       sample_directory=/home/postfix/doc/sample \
       readme_directory=/home/postfix/doc/README_FILES

postfix_setup安装包把postfix安装在/home/postfix目录下。


_____________________________________________________________


八.需要perl模块清单[除了一些可选perl模块外]:

Archive-Tar-1.38.tar.gz
Archive-Zip-1.23.tar.gz
BerkeleyDB-0.34.tar.gz
Compress-Raw-Zlib-2.008.tar.gz
Compress-Zlib-2.008.tar.gz
Convert-TNEF-0.17.tar.gz
Convert-UUlib-1.09.tar.gz
Crypt-OpenSSL-Random-0.04.tar.gz
Crypt-OpenSSL-RSA-0.25.tar.gz
dazuko-2.3.4.tar.gz
Digest-MD5-2.36.tar.gz
Digest-SHA-5.45.tar.gz
DocSet-0.19.tar.gz
Encode-Detect-1.00.tar.gz
ExtUtils-CBuilder-0.22.tar.gz
File-Temp-0.20.tar.gz
Handel-1.00010.tar.gz
HTML-Parser-3.56.tar.gz
IO-Compress-Base-2.008.tar.gz
IO-Compress-Zlib-2.008.tar.gz
IO-Socket-INET6-2.54.tar.gz
IO-Socket-SSL-1.13.tar.gz
IO-stringy-2.110.tar.gz
IO-Zlib-1.09.tar.gz
IP-Country-2.24.tar.gz
Mail-DKIM-0.30.1.tar.gz
Mail-DomainKeys-1.0.tar.gz
Mail-SpamAssassin-3.2.4.tar.gz
Mail-SPF-Query-1.999.1.tar.gz
Mail-SPF-v2.005.tar.gz
MailTools-2.02.tar.gz
MIME-tools-5.426.tar.gz
mod_perl-1.30.tar.gz
Net-CIDR-Lite-0.20.tar.gz
Net-DNS-0.63.tar.gz
Net-DNS-Resolver-Programmable-v0.003.tar.gz
Net-Ident-1.20.tar.gz
Net-IP-1.25.tar.gz
Net-Server-0.97.tar.gz
Net-SSLeay-1.32.tar.gz
NetAddr-IP-4.007.tar.gz
Pod-Escapes-1.04.tar.gz
Pod-POM-0.17.tar.gz
Pod-Simple-3.05.tar.gz
Socket6-0.20.tar.gz
Sys-Hostname-Long-1.4.tar.gz
Test-Pod-1.26.tar.gz
Test-Simple-0.78.tar.gz
Time-HiRes-1.9712.tar.gz
TimeDate-1.16.tar.gz
Unix-Syslog-1.0.tar.gz
IO-1.2301.tar.gz

九:附录

调试pam_mysql时候用到的logtable表结构
CREATE TABLE `logtable` (
`id` tinyint(3) unsigned NOT NULL auto_increment,
`logmsgcolumn` varchar(500) NOT NULL,
`logusercolumn` varchar(500) NOT NULL,
`logpidcolumn` varchar(500) NOT NULL,
`loghostcolumn` varchar(500) NOT NULL,
`logrhostcolumn` varchar(500) NOT NULL,
`logtimecolumn` varchar(500) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;


如何让Postfix直接支持SpamAssassin
在/etc/postfix/master.cf中添加下面倒数3行
smtp      inet n       -       n       -       -       smtpd
-o content_filter=spamassassin
spamassassin unix -       n       n       -       -       pipe
user=nobody argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}

Cyrus SASL configuration for the Postfix SMTP server
You need to configure how the Cyrus SASL library should authenticate
a remote SMTP client's username and password.
These settings must be stored in a separate configuration file.

The name of the configuration file (default: smtpd.conf) will be
constructed from a value that the Postfix SMTP server sends to the Cyrus SASL library,
which adds the suffix .conf. The value is configured using one of the following variables:

/etc/postfix/main.cf:
    # Postfix 2.3 and later
    smtpd_sasl_path = smtpd
//默认sasl的smtp认证文件名是/usr/lib/sasl2/smtp.conf,/etc/pam.d/smtp
而不是smtpd.conf所以这里,修改为smtpd_sasl_path = smtp,
//当然你也可以制定成smtpd,对应就是/usr/lib/sasl2/smtpd.conf,/etc/pam.d/smtpd

    # Postfix < 2.3
    smtpd_sasl_application_name = smtpd
Cyrus SASL searches for the configuration file in /usr/local/lib/sasl/ (Cyrus SASL version 1.5.5)
or /usr/local/lib/sasl2/ (Cyrus SASL version 2.1.x).

Note: some Postfix distributions are modified and look for the smtpd.conf file in /etc/postfix/sasl.

Note: some Cyrus SASL distributions look for the smtpd.conf file in /etc/sasl2.

测试cyrus-sasl-auth

testsaslauthd -f /var/run/saslauthd -r -s smtp -u <user@address> -p <pass>

TOP

发新话题