1、CentOS6.4 安装 EMOS1.6 邮件系统1 安装前的准备工作1.1 关闭 selinux1、临时关闭(不用重启机器):#setenforce 0 #设置 SELinux 成为 permissive 模式#setenforce 1 设置 SELinux 成为 enforcing 模式2、修改配置文件需要重启机器:vi /etc/selinux/config将 SELINUX=enforcing 改为 SELINUX=disabled重启机器即可3、查看 selinux 状态:#/usr/sbin/sestatus -v #如果 SELinux status 参数为 enabled 即为
2、开启状态SELinux status: enabled1.2 yum 先安装好以下组件:#yum -y install createrepo 制作 yum 仓库文件工具#yum -y install httpd #yum -y install mysql mysql-server mysql-devel 安装 mysql数据库支持Extmail#groupadd -g 1000 vgroup 配置好邮件虚拟组和用户#useradd -u 1000 -g 1000 -M vuser1.下载 EMOS 镜像# su - root# mkdir /path# cd /path#wget http:/
3、210.21.119.141/EMOS_1.6_x86_64.iso制作本地 yum 仓库# mkdir /mnt/EMOS# mount -o loop /path/EMOS_1.6_x86_64.iso /mnt/EMOS 装载 ios 镜像文件至EMOS 目录# cd /mnt# createrepo . 创建 yum 源配置文件# cd /etc/yum.repos.d# mkdir backup# mv *.repo ./backup# vi EMOS.repo加入以下内容EMOSname=EMOSbaseurl=file:/mnt/enabled=1gpgcheck=0# yum
4、clean all# yum list2 配置 MTApostfix2.1 检查 postfixCenOS6.4 默认安装了 postfix,并且可以支持 mysql 了,所以不用再安装了#rpm -qa |grep postfixpostfix-2.6.6-2.2.el6_1.x86_642.2 配置 postfix# postconf -n /etc/postfix/main2.cf# mv /etc/postfix/main.cf /etc/postfix/main.cf.bak# mv /etc/postfix/main2.cf /etc/postfix/main.cf# vi /et
5、c/postfix/main.cf #修改 main.cf 配置文件增加以下内容# hostnamemynetworks = 127.0.0.1myhostname = mail.extmail.orgmydestination = $mynetworks $myhostname# bannermail_name = Postfix - by extmail.orgsmtpd_banner = $myhostname ESMTP $mail_name# response immediatelysmtpd_error_sleep_time = 0s# Message and return cod
6、e controlmessage_size_limit = 5242880mailbox_size_limit = 5242880show_user_unknown_table_name = no# Queue lifetime controlbounce_queue_lifetime = 1dmaximal_queue_lifetime = 1d2.3 设置 postfix 开机自启# chkconfig postfix on3 配置 courier-authlib3.1 安装 courier-authlib# yum install courier-authlib courier-auth
7、lib-mysql3.2 修改 authlib 配置文件# rm -f /etc/authlib/authmysqlrc# vi /etc/authlib/authmysqlrcMYSQL_SERVER localhostMYSQL_USERNAME extmailMYSQL_PASSWORD extmailMYSQL_SOCKET /var/lib/mysql/mysql.sockMYSQL_PORT 3306MYSQL_OPT 0MYSQL_DATABASE extmailMYSQL_USER_TABLE mailboxMYSQL_CRYPT_PWFIELD passwordMYSQL_U
8、ID_FIELD uidnumberMYSQL_GID_FIELD gidnumberMYSQL_LOGIN_FIELD usernameMYSQL_HOME_FIELD homedirMYSQL_NAME_FIELD nameMYSQL_MAILDIR_FIELD maildirMYSQL_QUOTA_FIELD quotaMYSQL_SELECT_CLAUSE SELECT username,password,“,uidnumber,gidnumber,CONCAT(/home/domains/,homedir), CONCAT(/home/domains/,maildir), quota
9、, name FROM mailbox WHERE username = $(local_part)$(domain)3.3 修改 authmysqlrc 的权限和拥有者# chown daemon.daemon /etc/authlib/authmysqlrc# chmod 660 /etc/authlib/authmysqlrc3.4 修改 authdaemonrc # vi /etc/authlib/authdaemonrcauthmodulelist=“authmysql“authmodulelistorig=“authmysql“3.5 启动 courier-authlib# ser
10、vice courier-authlib startStarting Courier authentication services: authdaemond3.6 修改 authdaemon socket 目录权限,否则以下面的测试 SMTP 认证就不能通过# chmod 755 /var/spool/authdaemon/4 配置 maildrop4.1 安装 maildrop# yum install maildrop4.2 配置 maildrop配置 master.cf 为了使 Postfix 支持 Maildrop,必须修改/etc/postfix/master.cf 文件,注释掉原
11、来的 maildrop 的配置内容,并改为:# vi /etc/postfix/master.cfmaildrop unix - n n - - pipeflags=DRhu user=vuser argv=maildrop -w 90 -d $user$nexthop $recipient $user $extension nexthop注意:flags 前面有“两个空格”配置 main.cf 由于 maildrop 不支持一次接收多个收件人,因此必须在/etc/postfix/main.cf 里增加如下参数:# vi /etc/postfix/main.cfmaildrop_destina
12、tion_recipient_limit = 14.3 测试 maildrop 对 authlib 支持#maildrop vmaildrop 2.0.4 Copyright 1998-2005 Double Precision, Inc.GDBM extensions enabled.Courier Authentication Library extension enabled.Maildir quota extension enabled.This program is distributed under the terms of the GNU General PublicLicens
13、e. See COPYING for additional information.注意事项: 1、如需重新编译 Maildrop 软件包,必须先获得其源码 rpm 包,并且必须先行安装courier-authlib 及其 devel 软件包,否则编译后的 maildrop 将无法打开 authlib 支持。 2、maildrop RPM 包安装时,会自动创建 vuser 用户及 vgroup 用户组,专门用于邮件的存储,vuser:vgroup 的 uid/gid 都是 1000,这与一般的邮件文档中提及用 postfix 用户存邮件不一样。因为 postfix 用户的 uid 一般都低于
14、500,而 Suexec 模块编译时对 UID/GID 的要求是要大于 500,因此使用 postfix 用户不能满足要求。其次,如果用 Maildrop 作为投递代理(MDA) ,以 postfix 身份投递的话,会导致 postfix MTA 错误。5 配置 apache5.1 修改 apache 配置文件# vi /etc/httpd/conf/httpd.conf在最后一行加上NameVirtualHost *:80Include conf/vhost_*.conf新建 vhost_extmail.conf# vi /etc/httpd/conf/vhost_extmail.conf#
15、 VirtualHost for ExtMail SolutionServerName mail.extmail.orgDocumentRoot /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/h
16、tml/# Suexec configSuexecUserGroup vuser vgroup设置 apache 开机启动# chkconfig httpd on6 配置 extmail+extman6.1 安装 extmail 和 extman # yum install extsuite-webmail extsuite-webman6.2 配置 extmail 和 extman# cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf# vi /var/www/extsuit
17、e/extmail/webmail.cf修改以下两项SYS_MYSQL_USER = extmailSYS_MYSQL_PASS = extmailSYS_MYSQL_DB = extmail更新 cgi 目录权限 由于 SuEXEC 的需要,必须将 cgi 目录修改成 vuser:vgroup 权限:# chown -R vuser:vgroup /var/www/extsuite/extmail/cgi/# chown -R vuser:vgroup /var/www/extsuite/extman/cgi/链接基本库到 Extmail# mkdir /tmp/extman# chown
18、-R vuser:vgroup /tmp/extman/由于 RedHat 发行版中包含了一个叫 tmpwatch 的工具,该工具会定期扫描/tmp/下的文件,如果这些文件很久都没被使用,将被删除,因此如果后台长期不使用,/tmp/extman 目录有可能被 tmpwatch 删除,所以要么定期登陆后台,要么修改 webman.cf 将临时目录修改到另一个地方。此处暂以/tmp/extman 默认值为例。7 配置数据库7.1 数据库初始化# service mysqld start设置开机启动# chkconfig mysqld on7.2 导入数据且初始化(默认的 mysql 都没有密码的,
19、所以以下命令都不需要认证密码)# vi /var/www/extsuite/extman/docs/init.sql把里面所有 extmail.org 的改为 extmail.org此处可更改以后使用邮件的域名,安装时可以不修改。# mysql /etc/rc.d/rc.local# echo “/var/www/extsuite/extman/daemon/cmdserver -v -d“ /etc/rc.d/rc.local添加定时任务:shell# crontab -e添加以下内容:0 4 * * * /var/www/extsuite/extman/tools/expireusers.
20、pl -all postmasterextmail.org30 4 * * * /var/www/extsuite/extman/tools/reportusage.pl -all /home/domains postmasterextmail.org可以加,也可不加注:Extmail url: http:/ip/extmailExtman url: http:/ip/extmanExtman 管理员用户名:rootextmail.org管理员默认密码: extmail*123*Extmail 登录时,域名项应改为 extmail.org9 配置 cyrus-sasl9.1 删除系统自带的 c
21、yrus-sasl# rpm -e -nodeps cyrus-sasl9.2 安装 EMOS1.6 里的 cyrus-sasl# yum install cyrus-sasl注:此处如果安装有问题的话,请配置 yum源,至 163上下载包;9.3 修改 postfix 配置文件# vi /etc/postfix/main.cf增加以下内容# smtpd related configsmtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_hostname, reje
22、ct_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname,# SMTP sender login matching configsmtpd_sender_restrictions = permit_mynetworks, reject_sender_login_mismatch, reject_authenticated_sender_login_mismatch, reject_unauthenticat
23、ed_sender_login_mismatchsmtpd_sender_login_maps = mysql:/etc/postfix/mysql_virtual_sender_maps.cf, mysql:/etc/postfix/mysql_virtual_alias_maps.cf# SMTP AUTH config herebroken_sasl_auth_clients = yessmtpd_sasl_auth_enable = yessmtpd_sasl_local_domain = $myhostnamesmtpd_sasl_security_options = noanony
24、mous9.4 配置 smtpd.conf建立目录:# mkdir /usr/lib/sasl2/# vi /usr/lib/sasl2/smtpd.conf(32 位系统使用此条命令)# vi /usr/lib64/sasl2/smtpd.conf(64 位系统使用此条命令)清空后改为以下内容pwcheck_method: authdaemondlog_level: 3mech_list: PLAIN LOGINauthdaemond_path:/var/spool/authdaemon/socket10 重启 postfix# service postfix restart10.1 测试
25、SMTP 认证通过以下命令获得 postmasterextmail.org 的用户名及密码的 BASE64 编码:# perl -e use MIME:Base64; print encode_base64(“postmasterextmail.org“)结果:cG9zdG1hc3RlckBleHRtYWlsLm9yZw=# perl -e use MIME:Base64; print encode_base64(“extmail“)结果:ZXh0bWFpbA=开始测试# telnet localhost 25Trying 127.0.0.1.Connected to localhost.lo
26、caldomain (127.0.0.1).Escape character is .220 mail.extmail.org ESMTP Postfix - by extmail.orgehlo demo.domain.tld 1, # is true in MYNETS by default, but lets make it explicitos_fingerprint_method = undef, # dont query p0f for internal clientsallow_disclaimers = 1, # enables disclaimer insertion if
27、availablebypass_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_
28、DISCARD;$final_banned_destiny = D_DISCARD;$final_spam_destiny = D_PASS;$final_bad_header_destiny = D_PASS;# 配置 Amavisd 与 Clamav 结合av_scanners = (ClamAV-clamd,av_scanners_backup = (ClamAV-clamscan, clamscan,“-stdout -no-summary -r -tempdir=$TEMPBASE “,0, qr/:.*sFOUND$/, qr/.*?: (?!Infected Archive)(.
29、*) 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; 超过这个分数,直接將信
30、件备份后删除$final_virus_destiny: 检测到病毒时的动作 $final_banned_destiny: 检测到受禁止的内容时的动作 $final_spam_destiny: 检测到垃圾邮件、广告邮件( spam)时的动作 $final_bad_header_destiny: 检测到不良信件时的动作 默认有以下几种动作: D_PASS: 无论信件是否有问题,都会将信件发给收件人 D_DISCARD: 信件将被丢弃,并且不会告知收件人及发件人 D_BOUNCE: 信件不会发送给收件人,但会通知发件人邮件没有被投递 D_REJECT: 邮件不会被投递给收件人,但会通知发件人邮件被拒
31、绝 注意事项:上述$mydomain 参数与$myhostname 参数相同,主要是为了方便之后的病毒 /垃圾汇报邮件发给系统管理员时,能投递到本地的别名里,再转交到虚拟域的特定用户。5、配置 Postfix 集成 amavisd-new增加邮件别名# vi /etc/postfix/aliases增加如下信息,注意:默认的 aliases 数据库里已有一条 virusalert 的别名,请删除,再输入下面的别名记录,并确保所有记录都是唯一的:virusalert: rootspam.police: rootpostfix: testextmail.org保存并执行 newaliases 命令
32、生成新的别名数据库,重新启动 amavisd:# newaliases# service amavisd restart编辑 master.cf 文件:# vi /etc/postfix/master.cf增加如下内容:smtp-amavis unix - - n - 3 smtp-o smtp_data_done_timeout=1200-o smtp_send_xforward_command=yes-o disable_dns_lookups=yes-o max_use=10127.0.0.1:10025 inet n - n - - smtpd-o content_filter=-o
33、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
34、smtpd_soft_error_limit=1001-o smtpd_hard_error_limit=1000-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks编辑 main.cf 文件:# vi /etc/postfix/main.cf增加如下内容:# Content-Filtercontent_filter = smtp-amavis:127.0.0.1:10024receive_override_options = no_address_mappings注意:receive_ove
35、rride_options 这里必须增加,禁止地址展开/影射,否则如果遇到别名的时候会引起冗余邮件的产生。重启 postfix :# service postfix restart重新启动 amavisd:# service amavisd restart6、测试 Clamav# telnet localhost 25其过程如下:Trying 127.0.0.1.Connected to localhost.localdomain (127.0.0.1).Escape character is .220 mail.extmail.org ESMTP Postfix - by extmail.o
36、rgmail from: , quarantine: virus-mI6vbjkWZ2Tz, Message-ID: , mail_id: mI6vbjkWZ2Tz, Hits: -, size: 1757, 474 ms如果看到类似这样的日志,表明 Clamav+Amavisd-new 工作正常。14 配置 spam_locker1、安装 Spam_Locker# yum install extsuite-slockd配置 resolv.conf请确认/etc/resolv.conf 里的 dns 服务器是离你的邮件服务器最近,速度最快的 dns server,slockd 很依赖 dns
37、的好坏,因此给系统配置一个快速的 dns 能大幅度提高处理速度。以下给出一个配置仅供参考:shell# vi /etc/resolv.conf增加以下内容:nameserver 8.8.8.8 #也可以指定自己内部的 DNS,如果在内部网络搭建上述 dns 服务器是上海电信的 DNS 服务器,对于非上海的朋友,请改为离你最近的 DNS服务器 IP,如果可能的话,请配置一个简单的 bind,成为本地的 dns cache server,可以获得最高性能。这里略过这一步骤,但您必须确保 dns 的配置是正确并且可靠的,否则 slockd 将不能工作!2、测试 slockd启动 slockdshel
38、l# /usr/local/slockd/slockd-init start此时 slockd 将启动,并进入非 daemon 方式的监听模式,接受来自 10030 端口的请求,命令行下将显示如下调试信息:Starting spam locker daemon: slockdstarting child 2908starting child 2909打开另一个 ssh/终端窗口:# cd /usr/local/slockd/tools# perl policy_sig -h localhost -p 10030 -helo FOOBAR -ip 192.168.0.1 -from -to 此
39、时,程序应该返回如下错误信息:这表示 slockd 初步的正常工作了。action=554 blocked using zen.spamhaus.org, see http:/bl.extmail.org/cgi/rbl?192.168.0.1设置 slockd 开机自启动# /usr/local/slockd/slockd-init start # echo “/usr/local/slockd/slockd-init start” /etc/rc.d/rc.local3、配置 Postfixslockd 调试正常后,必须配置 postfix 以使其打开对 slockd 的支持。编辑 mai
40、n.cf 文件# vi /etc/postfix/main.cf将 check_policy_service inet: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_
41、unauth_pipelining,reject_invalid_hostname,check_policy_service inet:127.0.0.1:10030重新启动 postfix 以使配置生效# service postfix restart注意事项: 上述配置是将 slockd 的查询放到最后,这也是进一步提高资源利用律的办法,因为有部分功能 postfix 已实现了,所以就先由 postfix 检测,如果检测不到再由 slockd 完成。15 配置 dspam1、安装 dspamDspam 的配置主要参考Dspam+Amavis-new+SA-Clamav for EMOS链接
42、: http:/www.extmail.org/forum/thread-10393-1-1.html# yum y install dspam-mysql2、导入 DSPAM 训练库# cd /root/# wget http:/www.extmail.org/download/misc/dspam/dspam-trained-data.sql.gz# gzip -d dspam-trained-data.sql.gz# rm -rf /var/lib/mysql/dspam/ (备注:如果没有 dspam 的库,可以不用执行)# mysql -u root -p -e “create da
43、tabase dspam”# mysql -u root -p -e “grant all on dspam.* to dspamlocalhost identified by dspam” # mysql -u dspam -p dspam dspam - ExtMail Dev TeamDECODER=“/var/www/extsuite/extmail/tools/decode -v“if (/(From|Sender|Return-Path):.*MAILER-DAEMON/)BADSENDER=1# Custom filter and auto deliver to Junk mai
44、lbox support# need test command and other Unix commandtest -f $HOME/.mailfilter & exit 1 | exit 0# No customize filtering rulesif ( $RETURNCODE = 0 )if (/X-Spam-Flag:.*YES/ | /X-DSPAM-Result:.*Spam/)exception to “$HOME/Maildir/.Junk/.“7、配置 DSPAM Web 界面备注: Dspam_WebUI for Nginx 配置:http:/www.extmail.o
45、rg/forum/thread-22976-1-1.html安装相关的 rpm 包:# yum y install perl-GDGraph# yum -y install perl-GD-Graph3d# yum y install dspam-web创建 dspam-web 认证用户:# cd /usr/share/dspam/webui/cgi-bin# echo “extmail” admins# htpasswd -c .htpasswd extmail输入认证密码New password: Re-type new password: Adding password for user
46、 extmail启动 dspam-web 守护进程# service dspam-webd start这实际是启动了 mini_httpd 进程,查看 mini_httpd 是否启动正常:# ps aux |grep mini显示以下内容:dspam 18580 0.0 0.3 4152 820 ? Ss 20:05 0:00 mini_httpd -C /etc/dspam/webui.confroot 18582 0.0 0.2 5316 668 pts/0 S+ 20:05 0:00 grep mini重启 apache# service httpd restart访问 dspam-web输入你在 .htpasswd 文件中创建的用户和密码 用户名:extmail 密码是之前设置的最后安装 DNS 测试收发情况1 安装和配置 DNS iptables 开放 tcp udp 53 portyum -y install caching-nameserver bind bind-chroot bind-dyndb*2 登录 extmail 开用户,管理, ,收发电邮3 outlook foxmail 收发电邮