ExtMailinstallforRHEL6
ExtMailSolution结构
ExtMailSolution是一个基于优秀开源软件的电子邮件系统解决方案,核心部件包括了Postfix、Amavisd-new、ClamAV、ExtMail、ExtMan、Courier系列软件。是一个功能相对比较齐全的免费电子邮件系统。以下是其主要的特性列表:
主要特性 支持SMTP/POP3/HTTP协议 支持SMTP认证及ESMTP 可支持大容量邮箱(大于1GB) 高速Web界面访问邮箱 完整的Web管理后台 在线服务端病毒过滤 内建内容过滤 SMTP行为识别垃圾邮件 支持大量反垃圾邮件技术 图形化邮件日志分析 支持别名/多域/域管理员等 支持网络磁盘/POP3邮件 支持读/写HTML格式邮件 支持定制模板及多语言 邮件解决方案的软件组成:
功能模块 功能模块2 功能模块2 操作系统(OS) CentOS664位 CentOS和RHEL是一样的,而且升级免费 Web服务器 Apache2.2.x CentOS自带 数据库/目录服务 MySQL5.1.X CentOS自带 邮件传输代理(MTA) postfix-2.7.3 使用最新版本2.7.3 邮件投递代理(MDA) maildrop2.0.x 支持过滤和强大功能 Web帐户管理后台 ExtMan1.1 支持无限域名、无限用户 WebMail系统 ExtMail1.2.0 支持多语言、全部模板化,功能基本齐全 日志分析及显示 mailgraph_ext 在ExtMan中已经包含了 其他数据认证库 CourierAuthlb0.62 负责courier-imap,maildrop的认证 SMTP认证库 CyrusSASL2.1.x 标准的SASL实现库,可以支持Courierauthlib 内容过滤器 Amavisd-new2.6.4 Content-Filter软件,支持与Camav/SA的挂接 内容级别的反垃圾邮件工具 SpamAssassin-3.3.1 著名的SA,可以支持大量规则 防病毒软件(Anti-Virus) ClamAV0.97.21 最热门的开源杀毒软件 SMTP阶段反垃圾邮件工具 SpamLocker0.99 基于SMTP行为识别的Antispam软件,大量可选插件 高效的反垃圾邮件工具 Dspam-3.8 高精确度的、智能的过滤功能
一、配置mta-postfix
1、安装postfix
安装postfix
#yuminstallpostfix#rpm-esendmail
2、配置postfix
#postconf-n>/etc/postfix/main2.cf#mv/etc/postfix/main.cf/etc/postfix/main.cf.old#mv/etc/postfix/main2.cf/etc/postfix/main.cf
编辑main.cf:
#vi/etc/postfix/main.cf
增加如下内容:
#hostname
mynetworks=127.0.0.1
myhostname=mail.extmail.org
mydestination=$mynetworks$myhostname
#banner
mail_name=Postfix-byextmail.org
smtpd_banner=$myhostnameESMTP$mail_name
#responseimmediately
smtpd_error_sleep_time=0s
#Messageandreturncodecontrol
message_size_limit=5242880
mailbox_size_limit=5242880
show_user_unknown_table_name=no
#Queuelifetimecontrol
bounce_queue_lifetime=1d
maximal_queue_lifetime=1d
设置postfix开机自启:
#chkconfigpostfixon
二、配置courier-authlib
1、安装Courier-Authlib
安装以下软件包:
#yuminstallcourier-authlib#yuminstallcourier-authlib-mysql
编辑/etc/authlib/authmysqlrc文件:
#vi/etc/authlib/authmysqlrc
并将其内容清空,然后增加如下内容:
MYSQL_SERVERlocalhost
MYSQL_USERNAMEextmail
MYSQL_PASSWORDextmail
MYSQL_SOCKET/var/lib/mysql/mysql.sock
MYSQL_PORT3306
MYSQL_OPT0
MYSQL_DATABASEextmail
MYSQL_USER_TABLEmailbox
MYSQL_CRYPT_PWFIELDpassword
MYSQL_UID_FIELDuidnumber
MYSQL_GID_FIELDgidnumber
MYSQL_LOGIN_FIELDusername
MYSQL_HOME_FIELDhomedir
MYSQL_NAME_FIELDname
MYSQL_MAILDIR_FIELDmaildir
MYSQL_QUOTA_FIELDquota
MYSQL_SELECT_CLAUSESELECTusername,password,"",uidnumber,gidnumber,\
CONCAT(''/home/domains/'',homedir),\
CONCAT(''/home/domains/'',maildir),\
quota,\
name\
FROMmailbox\
WHEREusername=''$(local_part)@$(domain)''
修改authdaemonrc文件
#vi/etc/authlib/authdaemonrc
修改如下内容:
authmodulelist="authmysql"
authmodulelistorig="authmysql"
2、启动courier-authlib
#servicecourier-authlibstart
如一切正常,命令行将返回如下信息:
StartingCourierauthenticationservices:authdaemond
修改authdaemonsocket目录权限
如果该目录权限不正确修改,maildrop及postfix等将无法正确获取用户的信息及密码认证:
#chmod755/var/spool/authdaemon/
三、配置maildrop
1、安装maildrop
#yuminstallmaildrop
配置master.cf为了使Postfix支持Maildrop,必须修改/etc/postfix/master.cf文件,注释掉原来的maildrop的配置内容,并改为:
maildropunix-nn--pipe
flags=DRhuuser=vuserargv=maildrop-w90-d${user}@${nexthop}${recipient}${user}${extension}{nexthop}
注意:flags前面有“两个空格”
配置main.cf由于maildrop不支持一次接收多个收件人,因此必须在main.cf里增加如下参数:
maildrop_destination_recipient_limit=1
2、测试maildrop对authlib支持
#maildrop-v
看是否出现以下内容:
maildrop2.0.4Copyright1998-2005DoublePrecision,Inc.
GDBMextensionsenabled.
CourierAuthenticationLibraryextensionenabled.
Maildirquotaextensionenabled.
ThisprogramisdistributedunderthetermsoftheGNUGeneralPublic
License.SeeCOPYINGforadditionalinformation.
注意事项:
1、如需重新编译Maildrop软件包,必须先获得其源码rpm包,并且必须先行安装courier-authlib及其devel软件包,否则编译后的maildrop将无法打开authlib支持。
2、maildropRPM包安装时,会自动创建vuser用户及vgroup用户组,专门用于邮件的存储,vuser:vgroup的uid/gid都是1000,这与一般的邮件文档中提及用postfix用户存邮件不一样。因为postfix用户的uid一般都低于500,而Suexec模块编译时对UID/GID的要求是要大于500,因此使用postfix用户不能满足要求。其次,如果用Maildrop作为投递代理(MDA),以postfix身份投递的话,会导致postfixMTA错误。
四、配置apache
1、虚拟主机设置
编辑httpd.conf文件:
#vi/etc/httpd/conf/httpd.conf
在最后一行加上:
NameVirtualHost:80
Includeconf/vhost_.conf
编辑vhost_extmail.conf
#vi/etc/httpd/conf/vhost_extmail.conf
里面定义虚拟主机的相关内容:
#VirtualHostforExtMailSolution
ServerNamemail.extmail.org
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/
#Suexecconfig
SuexecUserGroupvuservgroup
设置apache开机启动
#chkconfighttpdon
五、配置webmail-extmail
1、安装ExtMail
#yuminstallextsuite-webmail
2、编辑webmail.cf
#cd/var/www/extsuite/extmail#cpwebmail.cf.defaultwebmail.cf#viwebmail.cf
主要变动的内容见下:
SYS_MYSQL_USER=extmail
SYS_MYSQL_PASS=extmail
SYS_MYSQL_DB=extmail
更新cgi目录权限由于SuEXEC的需要,必须将extmail的cgi目录修改成vuser:vgroup权限:
#chown-Rvuser:vgroup/var/www/extsuite/extmail/cgi/
六、配置管理后台-extman
1、yum安装ExtMan
#yuminstallextsuite-webman
更新cgi目录权限由于SuEXEC的需要,必须将extman的cgi目录修改成vuser:vgroup权限:
#chown-Rvuser:vgroup/var/www/extsuite/extman/cgi/
链接基本库到Extmail
#mkdir/tmp/extman#chown-Rvuser:vgroup/tmp/extman
注意事项:
由于RedHat发行版中包含了一个叫tmpwatch的工具,该工具会定期扫描/tmp/下的文件,如果这些文件很久都没被使用,将被删除,因此如果后台长期不使用,/tmp/extman目录有可能被tmpwatch删除,所以要么定期登陆后台,要么修改webman.cf将临时目录修改到另一个地方。此处暂以/tmp/extman默认值为例。
2、数据库初始化
启动Mysql
#servicemysqldstart#chkconfigmysqldon
导入mysql数据库结构及初始化数据,root密码默认为空
#mysql-uroot-p 注意事项:
上述导入初始化SQL时,默认的uidnumber/gidnumber都是1000,这和vuser:vgroup的uid/gid一致,是因为maildrop投递时会从数据库里取uidnumber/gidnumber,而在master.cf里已经定义好了投递时的运行身份(vuser:vgroup),所以这两个字段的内容必须为1000,否则将出现投递错误,例如报0×06等错误。
如果发现mysql数据库没有安装的话,请自行安装就可以了。
3、设置虚拟域和虚拟用户的配置文件
#cd/var/www/extsuite/extman/docs#cpmysql_virtual_alias_maps.cf/etc/postfix/#cpmysql_virtual_domains_maps.cf/etc/postfix/#cpmysql_virtual_mailbox_maps.cf/etc/postfix/#cpmysql_virtual_sender_maps.cf/etc/postfix/
配置main.cf:
#vi/etc/postfix/main.cf
增加以下内容:
#extmailconfighere
virtual_alias_maps=mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains=mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps=mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_transport=maildrop:
重启postfix:
#servicepostfixrestart
4、测试authlib
建立刚才导入mysql的postmaster@extmail.org帐户的Maildir,请输入如下命令:
#cd/var/www/extsuite/extman/tools#./maildirmake.pl/home/domains/extmail.org/postmaster/Maildir#chown-Rvuser:vgroup/home/domains/extmail.org
在命令行下执行:
#/usr/sbin/authtest-sloginpostmaster@extmail.orgextmail
结果如下:
Authenticationsucceeded.
Authenticated:postmaster@extmail.org(uid1000,gid1000)
HomeDirectory:/home/domains/extmail.org/postmaster
Maildir:/home/domains/extmail.org/postmaster/Maildir/
Quota:104857600S
EncryptedPassword:$1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
CleartextPassword:extmail
Options:(none)
这样表明ExtMan的正确安装,数据库也正确导入,courier-authlib能正确连接到mysql数据库。
最后访问http://mail.extmail.org/extmail/,如无意外,将看到webmail的登陆页,不过此时还没有加正式的用户,所以不能登陆,包括postmaster@extmail.org也不行。必须要登陆到http://mail.extmail.org/extman/里增加一个新帐户才能登陆。
ExtMan的默认超级管理员帐户:root@extmail.org,初始密码:extmail123,登陆成功后,建议将密码修改,以确保安全。
注意事项:
如果在执行#/usr/sbin/authtest-sloginpostmaster@extmail.orgextmail报如下错误时:
AuthenticationFAILED:Operationnotpermitted
你可以安装courier-authlib-mysql这个包,然后重启courier-authlib服务即可。
5、配置图形化日志
启动mailgraph_ext
#/usr/local/mailgraph_ext/mailgraph-initstart
启动cmdserver(在后台显示系统信息)
#/var/www/extsuite/extman/daemon/cmdserver--daemon
加入开机自启动:
#echo“/usr/local/mailgraph_ext/mailgraph-initstart”>>/etc/rc.d/rc.local#echo“/var/www/extsuite/extman/daemon/cmdserver-v-d”>>/etc/rc.d/rc.local
使用方法:等待大约15分钟左右,如果邮件系统有一定的流量,即可登陆到extman里,点“图形日志”即可看到图形化的日志。具体每天,周,月,年的则点击相应的图片进入即可。
添加定时任务:
#crontab-e
添加以下内容:
04/var/www/extsuite/extman/tools/expireusers.pl-allpostmaster@extmail.org
304/var/www/extsuite/extman/tools/reportusage.pl-all/home/domainspostmaster@extmail.org
七、配置cyrus-sasl
RHEL-6/CentOS-6的cyrus-sasl默认没有打开authdaemon的支持,为了使用集中认证的authlib,必须打开这个支持。为此我们必须删除系统的cyrus-sasl软件包,替换成打开了authdaemon支持的sasl软件包。
1、安装cyrus-sasl
删除系统的cyrus-sasl:
#rpm-ecyrus-sasl--nodeps
安装新的支持authdaemon的软件包
#yuminstallcyrus-sasl
2、配置main.cf文件
Postfix的SMTP认证需要透过Cyrus-SASL,连接到authdaemon获取认证信息。
编辑main.cf
#vi/etc/postfix/main.cf
增加如下内容:
#smtpdrelatedconfig
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,
#SMTPsenderloginmatchingconfig
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
#SMTPAUTHconfighere
broken_sasl_auth_clients=yes
smtpd_sasl_auth_enable=yes
smtpd_sasl_local_domain=$myhostname
smtpd_sasl_security_options=noanonymous
3、编辑smtpd.conf文件
#vi/usr/lib64/sasl2/smtpd.conf
确保其内容为:
pwcheck_method:authdaemond
log_level:3
mech_list:PLAINLOGIN
authdaemond_path:/var/spool/authdaemon/socket
重新启动postfix:
#servicepostfixstart
4、测试SMTP认证
通过以下命令获得postmaster@extmail.org的用户名及密码的BASE64编码:
#perl-e‘useMIME::Base64;printencode_base64(”postmaster\@extmail.org”)’
内容如下:
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
#perl-e‘useMIME::Base64;printencode_base64(”extmail”)’
内容如下:
ZXh0bWFpbA==
然后本机测试:
#telnetlocalhost25
其过程如下:
Trying127.0.0.1...
Connectedtolocalhost.localdomain(127.0.0.1).
Escapecharacteris''^]''.
220mail.extmail.orgESMTPPostfix-byextmail.org
ehlodemo.domain.tld<<输入内容
250-mail.extmail.org
250-PIPELINING
250-SIZE10240000
250-VRFY
250-ETRN
250-AUTHLOGINPLAIN
250-AUTH=LOGINPLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250DSN
authlogin<<输入内容
334VXNlcm5hbWU6
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==<<输入内容
334UGFzc3dvcmQ6
ZXh0bWFpbA==<<输入内容
2352.0.0Authenticationsuccessful
quit<<输入内容
2212.0.0Bye
最后出现235AuthenticationSuccessful表明认证成功了。
八、配置courier-imap
1、安装Courier-imap
默认的courier-authlib及courier-imap都会增加系统自启动设置,因此下一次服务器启动将自动启动相应的authlib及POP3服务
#yuminstallcourier-imap
配置courier-imap
由于Courier-imap的IMAP目录是按UTF-7编码的,ExtMail目前还没有正式支持IMAP目录,因此需要屏蔽IMAP,只提供pop3服务。而就目前的使用情况来看,IMAP使用的非常少,绝大部分OutLook/Foxmail用户都习惯使用POP3而非IMAP。
#vi/usr/lib/courier-imap/etc/imapd
修改内容如下:
IMAPDSTART=NO
#vi/usr/lib/courier-imap/etc/imapd-ssl
修改内容如下:
IMAPDSSLSTART=NO
然后重新启动courier-imap:
#servicecourier-imapstart
测试POP3请按如下步骤输入pop3命令测试其是否正常工作,注意蓝色的信息是我们输入到POP3服务器的(请首先登录extman自行建立test@extmail.org用户,密码:extmail)
shell
#telnetlocalhost110
其过程如下:
Trying127.0.0.1...
Connectedtolocalhost.localdomain(127.0.0.1).
Escapecharacteris''^]''.
+OKHellothere.
usertest@extmail.org<<输入内容
+OKPasswordrequired.
passextmail<<输入内容
+OKloggedin.
list<<输入内容
+OKPOP3clientsthatbreakhere,theyviolateSTD53.
.
quit<<输入内容
+OKBye-bye.
Connectionclosedbyforeignhost.
九、配置内容、病毒过滤
1、安装amavisd-new
#yuminstallamavisd-new
设置相关目录权限:
#chown-Ramavis.amavis/var/spool/vscan/
2、配置SpamAssassin
Amavisd-new通过Mail::SpamAssassin模块来调用SA的功能,因此这里配置SA和常规配置SA软件有些区别,主要集中在修改local.cf文件上。
#cd/etc
#ln-s/etc/amavisd/amavisd.confamavisd.conf
存盘退出即可。最后运行以下调试命令以确认amavisd没有错误:
#/usr/sbin/amavisd-c/etc/amavisd.confdebug
如果没有异常提示或报错退出则表示一切都正常,按ctrl+c终止,然后正常启动,若提示pid不存在等错误,不必理会。
设置amavisd开机自启:
#serviceamavisdstart#chkconfigamavisdon
注意事项:
在启动服务的过程中可能会遇到下面的错误:
启动MailVirusScanner(amavisd):fetch_modules:errorloadingoptionalmoduleMIME/Decoder/BinHex.pm:
Can''tlocateConvert/BinHex.pmin@INC(@INCcontains:/usr/local/lib64/perl5/usr/local/share/perl5/usr/lib64/perl5/vendor_perl/usr/share/perl5/vendor_perl/usr/lib64/perl5/usr/share/perl5)at/usr/share/perl5/vendor_perl/MIME/Decoder/BinHex.pmline43.
BEGINfailed--compilationabortedat/usr/share/perl5/vendor_perl/MIME/Decoder/BinHex.pmline43.
Compilationfailedinrequireat/usr/sbin/amavisdline197.
这时候就需要安装perl-Convert-BinHex这个软件包,安装完后就可以了。
3、配置ClamAV
安装ClamAV
#yuminstallclamavclamav-develclamav-dbclamd
编辑clamd.conf文件
#vi/etc/clamd.conf
去掉‘LocalSocket/var/run/clamav/clamd.sock’的注释,并注释掉‘TCPSocket3310’,我们将使用unixsocket而不是TCP,两者不可并存。变动内容见下:
#Default:disabled
LocalSocket/var/run/clamav/clamd.sock
#TCPSocket3310
设置相关目录权限:将clamav加到amavis运行组里,并调整目录权限,否则clamav将无法扫描amavisd-new产生的临时文件
#gpasswd-aclamavamavis#usermod-Gamavisclamav#chownamavis.amavis/var/spool/vscan#chmod750/var/spool/vscan#chownamavis.amavis/var/spool/vscan/tmp#chmod750/var/spool/vscan/tmp
默认的/var/spool/vscan目录属性是:
drwxr-x---5amavisamavis
对于clamav用户而言,则无任何权限访问该目录,因此maillog里amavisd-new会提示:
May1908:38:53as3amavis[1752]:(01752-01)ask_av(ClamAV-clamd)FAILED-unexpectedresult:/var/spool/vscan/tmp/amavis-20050519T
083853-01752/parts:Accessdenied.ERROR\n
May1908:38:53as3amavis[1752]:(01752-01)WARN:allprimaryvirusscannersfailed,consideringbackups
启动ClamAV及开机自启:
#serviceclamdstart
#chkconfigclamdon#freshclam–daemon
4、配置amavisd.con文件
修改amavisd.conf
#vi/etc/amavisd.conf
修改的主要参数如下:
$mydomain=''extmail.org'';
$db_home="$MYHOME/db";
$lock_file="$MYHOME/amavisd.lock";#-L
$pid_file="$MYHOME/amavisd.pid";#-P
$myhostname=''mail.extmail.org'';
@local_domains_maps=qw(.);
@mynetworks=qw(127.0.0.0/8);
对本地发出的邮件不进行内容过滤
$policy_bank{''MYNETS''}={#mailoriginatingfrom@mynetworks
originating=>1,#istrueinMYNETSbydefault,butlet''smakeitexplicit
os_fingerprint_method=>undef,#don''tqueryp0fforinternalclients
allow_disclaimers=>1,#enablesdisclaimerinsertionifavailable
bypass_spam_checks_maps=>[1],
bypass_banned_checks_maps=>[1],
bypass_header_checks_maps=>[1],
};
$sa_spam_modifies_subj=0;#当邮件被认为是垃圾邮件时,是否修改邮件的主题
$remove_existing_x_scanned_headers=1;#凡是经过Amavisd过滤的邮件,都会在邮件头中被加入一行邮件头信息
$remove_existing_spam_headers=1;
#修改投递/拦截的方法:
$final_virus_destiny=D_DISCARD;
$final_banned_destiny=D_DISCARD;
$final_spam_destiny=D_PASS;
$final_bad_header_destiny=D_PASS;
#配置Amavisd与Clamav结合
@av_scanners=(
[''ClamAV-clamd'',
\&ask_daemon,["CONTSCAN{}\n","/var/run/clamav/clamd.sock"],
qr/\bOK$/,qr/\bFOUND$/,
qr/^.?:(?!InfectedArchive)(.)FOUND$/],
);
@av_scanners_backup=(
[''ClamAV-clamscan'',''clamscan'',
"--stdout--no-summary-r--tempdir=$TEMPBASE{}",
[0],qr/:.\sFOUND$/,qr/^.?:(?!InfectedArchive)(.)FOUND$/],
);
amavisd.conf常用参数说明:
$max_servers=10;设置最大可使用的进程数
$sa_spam_subject_tag=''[SPAM]'';加[SPAM]标记
$mydomain=''mail.extmail.org'';设置域名
$myhostname=''mail.extmail.org'';设置主机名
@local_domains_maps=qw(.);对所有的域检查
$sa_tag2_level_deflt=5.0;超过这个分数,允许在邮件标题加入[SPAM]标记
$sa_kill_level_deflt=5.0;超过这个分数,直接將信件备份后删除
$final_virus_destiny:检测到病毒时的动作
$final_banned_destiny:检测到受禁止的内容时的动作
$final_spam_destiny:检测到垃圾邮件、广告邮件(spam)时的动作
$final_bad_header_destiny:检测到不良信件时的动作
默认有以下几种动作:
D_PASS:无论信件是否有问题,都会将信件发给收件人
D_DISCARD:信件将被丢弃,并且不会告知收件人及发件人
D_BOUNCE:信件不会发送给收件人,但会通知发件人邮件没有被投递
D_REJECT:邮件不会被投递给收件人,但会通知发件人邮件被拒绝
注意事项:
上述$mydomain参数与$myhostname参数相同,主要是为了方便之后的病毒/垃圾汇报邮件发给系统管理员时,能投递到本地的别名里,再转交到虚拟域的特定用户。
5、配置Postfix集成amavisd-new
增加邮件别名
#vi/etc/postfix/aliases
增加如下信息,注意:默认的aliases数据库里已有一条virusalert的别名,请删除,再输入下面的别名记录,并确保所有记录都是唯一的:
virusalert:root
spam.police:root
postfix:test@extmail.org
保存并执行newaliases命令生成新的别名数据库,重新启动amavisd:
#newaliases#serviceamavisdrestart
编辑master.cf文件:
#vi/etc/postfix/master.cf
增加如下内容:
smtp-amavisunix--n-3smtp
-osmtp_data_done_timeout=1200
-osmtp_send_xforward_command=yes
-odisable_dns_lookups=yes
-omax_use=10
127.0.0.1:10025inetn-n--smtpd
-ocontent_filter=
-olocal_recipient_maps=
-orelay_recipient_maps=
-osmtpd_restriction_classes=
-osmtpd_client_restrictions=
-osmtpd_helo_restrictions=
-osmtpd_sender_restrictions=
-osmtpd_recipient_restrictions=permit_mynetworks,reject
-omynetworks=127.0.0.0/8
-ostrict_rfc821_envelopes=yes
-osmtpd_error_sleep_time=0
-osmtpd_soft_error_limit=1001
-osmtpd_hard_error_limit=1000
-oreceive_override_options=no_unknown_recipient_checks,no_header_body_checks
编辑main.cf文件:
#vi/etc/postfix/main.cf
增加如下内容:
#Content-Filter
content_filter=smtp-amavis:[127.0.0.1]:10024
receive_override_options=no_address_mappings
注意:receive_override_options这里必须增加,禁止地址展开/影射,否则如果遇到别名的时候会引起冗余邮件的产生。
重启postfix:
#servicepostfixrestart
重新启动amavisd:
#serviceamavisdrestart
6、测试Clamav
#telnetlocalhost25
其过程如下:
Trying127.0.0.1...
Connectedtolocalhost.
Escapecharacteris''^]''.
220mail.extmail.orgESMTPPostfix-byextmail.org
mailfrom:
2502.1.0Ok
rcptto:
2502.1.5Ok
data
354Enddatawith.
alksjfdlkajfd
aldfja
sfdlkjasf
.
2502.0.0Ok:queuedas2B0EB631BE
quit
2212.0.0Bye
Connectionclosedbyforeignhost.
在邮件日志里,应该有相应的信息出现:
Jun100:42:36testamavis[3466]:(03466-01)PassedCLEAN,MYNETSLOCAL[127.0.0.1][127.0.0.1]->,Message-ID:<20130531164231.2B0EB631BE@mail.extmail.org>,mail_id:RzcjEdy2Lbu4,Hits:-,size:386,queued_as:421EC631C0,405ms
如果看到类似这样的日志,表明Clamav+Amavisd-new工作正常。
十、配置spam_locker
1、安装Spam_Locker
#yuminstallextsuite-slockd
配置resolv.conf
请确认/etc/resolv.conf里的dns服务器是离你的邮件服务器最近,速度最快的dnsserver,slockd很依赖dns的好坏,因此给系统配置一个快速的dns能大幅度提高处理速度。以下给出一个配置仅供参考:
#vi/etc/resolv.conf
增加以下内容:
nameserver172.16.86.168
上述dns服务器是我自己搭建的DNS服务器,如果可能的话,请配置一个简单的bind,成为本地的dnscacheserver,可以获得最高性能。这里略过这一步骤,但您必须确保dns的配置是正确并且可靠的,否则slockd将不能工作!
2、测试slockd
启动slockd
#/usr/local/slockd/slockd-initstart
此时slockd将启动,并进入非daemon方式的监听模式,接受来自10030端口的请求,命令行下将显示如下调试信息:
Startingspamlockerdaemon:slockd
打开另一个ssh/终端窗口:
#cd/usr/local/slockd/tools
输入:
#perlpolicy_sig-hlocalhost-p10030--heloFOOBAR--ip192.168.0.1--fromtest@foo.com--totest@bar.com
此时,程序应该返回如下错误信息:这表示slockd初步的正常工作了。
action=554blockedusinghostkarma.junkemailfilter.com,seehttp://bl.extmail.org/cgi/rbl?192.168.0.1
设置slockd开机自启动
#echo“/usr/local/slockd/slockd-initstart”>>/etc/rc.d/rc.local
3、配置Postfix
slockd调试正常后,必须配置postfix以使其打开对slockd的支持。
编辑main.cf文件
#vi/etc/postfix/main.cf
将check_policy_serviceinet:127.0.0.1:10030这一行记录增加到smtpd_recipient_restrictions里,例如:
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_serviceinet:127.0.0.1:10030
重新启动postfix以使配置生效
#servicepostfixrestart
注意事项:上述配置是将slockd的查询放到最后,这也是进一步提高资源利用律的办法,因为有部分功能postfix已实现了,所以就先由postfix检测,如果检测不到再由slockd完成。
十一、配置dspam
1、安装dspam
Dspam的配置主要参考《Dspam+Amavis-new+SA-ClamavforEMOS》
链接:http://www.extmail.org/forum/thread-10393-1-1.html
#yuminstalldspam-mysql
2、导入DSPAM训练库
#cd/root/#wgethttp://www.extmail.org/download/misc/dspam/dspam-trained-data.sql.gz#gzip-ddspam-trained-data.sql.gz#rm-rf/var/lib/mysql/dspam/(备注:如果没有dspam的库,可以不用执行)#mysql-uroot-p-e“createdatabasedspam”#mysql-uroot-p-e“grantallondspam.todspam@localhostidentifiedby‘dspam’”#mysql-udspam-pdspamdspam DSPAM的token数据库的定时清理:
#crontab-e
加入以下内容:
00/usr/bin/mysql-udspam-p''dspam''dspam 00/usr/bin/dspam_logrotate-a30-d/var/spool/dspam/data
3、配置dspam.conf文件
#vi/etc/dspam/dspam.conf
变动内容如下:
DeliveryHost127.0.0.1
DeliveryPort10024
DeliveryIdentlocalhost
DeliveryProtoSMTP
Trustextmail
Preference"signatureLocation=headers"#''message''or''headers''
Preference"showFactors=off"
MySQLUIDInSignatureon
MySQLServer/var/lib/mysql/mysql.sock
MySQLUserdspam
MySQLPassdspam
MySQLDbdspam
MySQLCompresstrue
MySQLConnectionCache10
ServerHost127.0.0.1
ServerPort10028
ServerQueueSize32
ServerPID/var/spool/dspam/dspamd.pid
ServerModeauto
ServerPass.Relay1"secret"
ServerParameters"--userextmail--deliver=innocent,spam"
ServerIdent"localhost.localdomain"
ClientHost127.0.0.1
ClientPort10028
ClientIdent"secret@Relay1"
3、启动dspam进程
#chkconfigdspamdon#servicedspamdstart
查看dspam启动进程
#psaux|grepdspam
显示以下内容:
dspam39451002:00?00:00:00/usr/sbin/dspamd--daemon
root39753075002:01pts/000:00:00grepdspam
4、修改main.cf文件
#vi/etc/postfix/main.cf
增加以下内容:
header_checks=regexp:/etc/postfix/dspam_header_checks
设置邮件标题过滤管理以防止重复X-DSPAM-Signature标题,可以防止签名被报道为垃圾。这发生在当你从一个已经运行Dspam的服务器收到邮件,或被用于通过伪造的、滥发邮件来阻止你训练数据库,
#vi/etc/postfix/dspam_header_checks
增加以下内容:
/^(X-DSPAM-.)/IGNORE
/^(X-Spam-.)/IGNORE
重启postfix:
#servicepostfixrestart
5、编辑amavisd.conf文件
#vi/etc/amavisd/amavisd.conf
增加以下内容:
$dspam=''/usr/bin/dspam'';
@spam_scanners=(
[''SpamAssassin'',''Amavis::SpamControl::SpamAssassin''],
[''DSPAM'',''Amavis::SpamControl::ExtProg'',$dspam,
[qw(--client--stdout--deliver=spam,innocent--mode=teft--userextmail)],
],
);
SA增加DSpam插件:
#cd/usr/share/perl5/Mail/SpamAssassin/Plugin/#wgethttp://www.extmail.org/download/misc/dspam/dspam.pm
编辑local.cf文件
#cd/etc/mail/spamassassin/#wgethttp://www.extmail.org/download/misc/dspam/dspam.cf#vilocal.cf
在下面增加以下内容
includedspam.cf
编辑init.pre文件:
#viinit.pre
在下面增加以下内容
loadpluginMail::SpamAssassin::Plugin::dspam
重启amavisd
#serviceamavisdrestart
6、增加extmail的垃圾邮件举报
说明:Extmail1.0.9正式加入垃圾邮件举报功能,主要基于(xueron)的补丁包,并进行了一定的调整,使该功能可以兼容DSPAM及Spamassassin两种内容过滤软件的训练。Extmail1.1.1加入(stvictor)提供的spamassassin举报功能,感谢!
修改webmail.cf
#vi/var/www/extsuite/extmail/webmail.cf
主要变动的内容如下:
SYS_SPAM_REPORT_ON=1
SYS_SPAM_REPORT_TYPE=dspam
设置maidrop的全局过滤
#vi/etc/maildroprc
内容如下:
#Decoderforhighqualitykeywordfiltering
#Author:hzqbbc-ExtMailDevTeam
DECODER="/var/www/extsuite/extmail/tools/decode-v"
if((/^(From|Sender|Return-Path):.MAILER\-DAEMON/))
{
BADSENDER=1
}
#CustomfilterandautodelivertoJunkmailboxsupport
#needtestcommandandotherUnixcommand
`test-f$HOME/.mailfilter&&exit1||exit0`
#Nocustomizefilteringrules
if($RETURNCODE==0)
{
if(/^X-Spam-Flag:.YES/||/^X-DSPAM-Result:.Spam/)
{
exception{
to"$HOME/Maildir/.Junk/."
}
}
}
7、配置DSPAMWeb界面
备注:Dspam_WebUIforNginx配置:
http://www.extmail.org/forum/thread-22976-1-1.html
安装相关的rpm包:
#yuminstallperl-GD-Graph#yuminstallperl-GD-Graph3d#yuminstalldspam-web
创建dspam-web认证用户:
#cd/usr/share/dspam/webui/cgi-bin#echo“extmail”>admins#htpasswd-c.htpasswdextmail
输入认证密码
Newpassword:
Re-typenewpassword:
Addingpasswordforuserextmail
启动dspam-web守护进程
#servicedspam-webdstart
这实际是启动了mini_httpd进程,查看mini_httpd是否启动正常:
#psaux|grepmini
显示以下内容:
dspam21661017:55?00:00:00/usr/bin/mini_httpd-C/etc/dspam/webui.conf
root21702103017:56pts/000:00:00grepmini
重启apache
#servicehttpdrestart
访问dspam-web
http://mail.extmail.org/dspam
输入你在.htpasswd文件中创建的用户和密码
|
|