extmail的安裝

   ExtMail Solution 是一個基於優秀開源軟件的電子郵件系統解決方案,核心部件包括了Postfix、Amavisd-new、ClamAV、ExtMail、ExtMan、Courier系列軟件。是一個功能相對比較齊全的免費電子郵件系統php

clip_p_w_picpath002

其項目官網爲:http://www.extmail.orghtml

全部者:Extmail Dev Teamnode

本文檔在RedHat Enterprise及CentOS系統上能夠安裝,僅以CentOS 爲例mysql

1、extmail_solutionz概述linux

一、ExtMail Solution 結構
web

如下是其主要的特性列表: sql

主要特性shell

支持SMTP/POP3/HTTP協議數據庫

支持SMTP認證及ESMTPapache

可支持大容量郵箱(大於1GB)

高速Web界面訪問郵箱

完整的Web管理後臺

在線服務端病毒過濾

內建內容過濾

SMTP行爲識別垃圾郵件

支持大量反垃圾郵件技術

圖形化郵件日誌分析

支持別名/多域/域管理員等

支持網絡磁盤/POP3郵件

支持讀/寫HTML格式郵件

支持定製模板及多語言

二、硬件配置

要流暢地運行郵件系統,建議的硬件配置以下:

名稱

說明

物理內存       

512M+ 推薦1024M

交換區:

2倍物理內存大小

CPU

PIII 1G+ 推薦P4及其以上級別

主板

推薦Intel原裝

網卡

100M/1000M 推薦3Com/Intel

2、操做系統安裝(以CentOS5.5爲例)

只安裝以下的組件:

Web Server:

要注意必須選中httpd-suexec軟件包,不然下文的配置將失效。

MYSQL數據庫:

注意必須選中mysql-server, libdbi-dbd-mysql, perl-DBD-mysql等模塊,不然extmail將沒法鏈接mysql

VIM編輯器:

強烈建議安裝vim-enhanced軟件包,它支持main.cf彩色高亮語法分析。

其他的Xwindows, 打印,KDE/Gnore, 服務器配置工具,網絡工具,開發包等所有都不是必選組件。安裝完畢進入操做系統後,爲增長系統安全性,建議禁止root直接登錄,並增長一個非root賬 戶,例如sysadmin。這樣沒法以root帳戶直接登錄系統,必須先以sysadmin身份登錄再su到root執行。

2、CentOS4.7安裝步驟圖解:

如下將以詳細的圖解來介紹如何安裝CentOS5.5

clip_p_w_picpath004

CentOS啓動光盤的啓動畫面,直接回車便可。

clip_p_w_picpath005

系統提示「是否須要校驗CD媒質」,請選擇「Skip」

clip_p_w_picpath007

安裝歡迎界面

clip_p_w_picpath009

clip_p_w_picpath011

clip_p_w_picpath012

clip_p_w_picpath014

clip_p_w_picpath016

clip_p_w_picpath017

clip_p_w_picpath019

clip_p_w_picpath021

clip_p_w_picpath023

clip_p_w_picpath025

clip_p_w_picpath027

clip_p_w_picpath029

clip_p_w_picpath031

clip_p_w_picpath033

clip_p_w_picpath035

clip_p_w_picpath037

系統界面

3、配置SSH:

以root身份登進系統後,增長一個非root賬戶,名稱爲sysadmin,密碼按您的需求設置一個便可。接下來咱們要禁止root直接登錄。

shell

# vi /etc/ssh/sshd_config

修改如下配置爲:

PermitRootLogin no

而後從新啓動sshd,這樣禁止了root直接登錄。

shell

# /etc/init.d/sshd restart

4、配置SELinux

自從RHEL4/CentOS4之後,系統默認打開了SELinux支持,簡單說SELinux就是一個強制性的安全機制,可是它也帶來了很多麻煩,爲了不編寫煩瑣的policy規則,本文檔將屏蔽掉SELinux對MySQL及httpd的保護。方法以下:

shell

# setsebool httpd_disable_trans=1
# setsebool mysqld_disable_trans=1

操做完畢後,從新啓動mysql及apache,並將以下命令加入/etc/rc.d/rc.local以便服務器啓動後能自動生效:

shell

# vi /etc/rc.d/rc.local

加入如下內容:

/usr/sbin/setsebool httpd_disable_trans=1

/usr/sbin/setsebool mysqld_disable_trans=1

/etc/init.d/mysqld restart

/etc/init.d/httpd restart

3、製做_yum_倉庫 1、下載軟件包

整個系統的安裝全過程都要求以root身份執行,若是機器沒有訪問外部網絡的能力,則事先下載好EMOS光盤映像,並上傳到服務器。

備註:若是要在CentOS 5.x上面進行配置,請下載EMOS-1.5.ISO,配置方法不變;

shell

# su - root

# cd /root

# wget ftp://www5.extmail.org/emos/EMOS_1.5.iso

2、製做本地 yum 倉庫

使用EMOS1.5.ISO光盤製做本地 yum 倉庫;

此外,咱們假設本次安裝默認域是extmail.org,主機名爲:mail.extmail.org

安裝CentOS光盤中createrepo工具

shell

# rpm -ivh createrepo*

加載EMOS1.5的光盤,請把emos的光盤放到光驅中

shell

# mkdir /mnt/EMOS

# mount /dev/cdrom /mnt/EMOS

# cd /mnt

# createrepo .

3、建立客戶端 yum 的定義文件:

shell

# cd /etc/yum.repos.d

# mkdir backup

# mv *.repo ./backup

# vi EMOS.repo

加入如下內容:

[EMOS]

name=EMOS

baseurl=file:///mnt/

enabled=1

gpgcheck=0

從新獲取最新的倉庫信息:

shell

# yum clean all

# yum list

4、配置mta-postfix 1、安裝postfix

安裝postfix

shell

# yum install postfix

# rpm -e sendmail

2、配置postfix

shell

# 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:

shell

# vi /etc/postfix/main.cf

增長以下內容:(添加到文件的後面)

# hostname

mynetworks = 127.0.0.1

myhostname = mail.extmail.org

mydestination = $mynetworks $myhostname

# banner

mail_name = Postfix - by extmail.org

smtpd_banner = $myhostname ESMTP $mail_name

# response immediately

smtpd_error_sleep_time = 0s

# Message and return code control

message_size_limit = 5242880

mailbox_size_limit = 5242880

show_user_unknown_table_name = no

# Queue lifetime control

bounce_queue_lifetime = 1d

maximal_queue_lifetime = 1d

設置postfix開機自啓:

shell

# chkconfig postfix on

5、配置courier-authlib 1、安裝Courier-Authlib

安裝如下軟件包:

shell

# yum install courier-authlib

# yum install courier-authlib-mysql

編輯/etc/authlib/authmysqlrc文件:

shell

# vi /etc/authlib/authmysqlrc

並將其內容清空,而後增長以下內容:

MYSQL_SERVER localhost

MYSQL_USERNAME extmail

MYSQL_PASSWORD extmail

MYSQL_SOCKET /var/lib/mysql/mysql.sock

MYSQL_PORT 3306

MYSQL_OPT 0

MYSQL_DATABASE extmail

MYSQL_USER_TABLE mailbox

MYSQL_CRYPT_PWFIELD password

MYSQL_UID_FIELD uidnumber

MYSQL_GID_FIELD gidnumber

MYSQL_LOGIN_FIELD username

MYSQL_HOME_FIELD homedir

MYSQL_NAME_FIELD name

MYSQL_MAILDIR_FIELD maildir

MYSQL_QUOTA_FIELD quota

MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber,\

CONCAT('/home/domains/',homedir), \

CONCAT('/home/domains/',maildir), \

quota, \

name \

FROM mailbox \

WHERE username = '$(local_part)@$(domain)'

修改authdaemonrc文件

shell

# vi /etc/authlib/authdaemonrc

修改以下內容:

authmodulelist="authmysql"

authmodulelistorig="authmysql"

2、啓動courier-authlib:

shell

# service courier-authlib start

如一切正常,命令行將返回以下信息:

Starting Courier authentication services: authdaemond

修改authdaemon socket目錄權限

若是該目錄權限不正確修改,maildrop及postfix等將沒法正確獲取用戶的信息及密碼認證:

shell

# chmod 755 /var/spool/authdaemon/

6、配置maildrop 1、安裝maildrop

shell

# yum install maildrop

配置master.cf 爲了使Postfix支持Maildrop,必須修改/etc/postfix/master.cf文件,註釋掉原來的maildrop的配置內容,並改成:

maildrop unix - n n - - pipe

flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}

配置main.cf 因爲maildrop不支持一次接收多個收件人,所以必須在main.cf裏增長以下參數:

maildrop_destination_recipient_limit = 1

2、測試maildrop對authlib支持

shell

# maildrop -v

看是否出現如下內容:

maildrop 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 Public

License. See COPYING for additional information.

注意事項:

一、如需從新編譯Maildrop軟件包,必須先得到其源碼rpm包,而且必須先行安裝courier-authlib及其devel軟件包,不然編譯後的maildrop將沒法打開authlib支持。

二、maildrop RPM包安裝時,會自動建立vuser用戶及vgroup用戶組,專門用於郵件的存儲,vuser:vgroup的uid/gid都是1000,這與通常的郵件文檔中說起用postfix用戶存郵件不同。由於postfix用戶的uid通常都低於500,而Suexec模塊編譯時對UID/GID的要求是要大於500,所以使用postfix用戶不能知足要求。其次,若是用Maildrop做爲投遞代理(MDA),以postfix身份投遞的話,會致使postfix MTA錯誤。

7、配置apache 1、虛擬主機設置

編輯httpd.conf文件:

shell

# vi /etc/httpd/conf/httpd.conf

在最後一行加上:

NameVirtualHost *:80

Include conf/vhost_*.conf

編輯 vhost_extmail.conf

shell

# vi /etc/httpd/conf/vhost_extmail.conf

裏面定義虛擬主機的相關內容:

# VirtualHost for ExtMail Solution

<VirtualHost *:80>

ServerName mail.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/

# Suexec config

SuexecUserGroup vuser vgroup

</VirtualHost>

設置apache開機啓動

shell

# chkconfig httpd on

8、配置webmail-extmail 1、安裝ExtMail

shell

# yum install extsuite-webmail

2、編輯webmail.cf

shell

# cd /var/www/extsuite/extmail

# cp webmail.cf.default webmail.cf

# vi webmail.cf

主要變更的內容見下:

SYS_MYSQL_USER = extmail

SYS_MYSQL_PASS = extmail

SYS_MYSQL_DB = extmail

更新cgi目錄權限 因爲SuEXEC的須要,必須將extmail的cgi目錄修改爲vuser:vgroup權限:

shell

# chown -R vuser:vgroup /var/www/extsuite/extmail/cgi/

9、配置管理後臺-extman 1、yum安裝ExtMan

shell

# yum install extsuite-webman

更新cgi目錄權限 因爲SuEXEC的須要,必須將extman的cgi目錄修改爲vuser:vgroup權限:

shell

# chown -R vuser:vgroup /var/www/extsuite/extman/cgi/

連接基本庫到Extmail

shell

# mkdir /tmp/extman

# chown -R vuser:vgroup /tmp/extman

# chmod –R 777 /tmp/extman

2、數據庫初始化

啓動Mysql

shell

# service mysqld start

# chkconfig mysqld on

導入mysql數據庫結構及初始化數據,root密碼默認爲空

shell

# mysql -u root -p < /var/www/extsuite/extman/docs/extmail.sql

# mysql -u root -p &lt; /var/www/extsuite/extman/docs/init.sql

注意事項:

上面命令行中最後一個cd $OLDPWD是返回原始路徑(即ExtMail Solution軟件包根目錄)

因爲RedHat發行版中包含了一個叫tmpwatch的工具,該工具會按期掃描/tmp/下的文件,若是這些文件好久都沒被使用,將被刪除,所以若是後臺長期不使用,/tmp/extman目錄有可能被tmpwatch刪除,因此要麼按期登錄後臺,要麼修改 webman.cf將臨時目錄修改到另外一個地方。此處暫以/tmp/extman默認值爲例。

上述導入初始化SQL時,默認的uidnumber/gidnumber都是1000,這和vuser:vgroup 的uid/gid一致,是由於maildrop投遞時會從數據庫裏取uidnumber/gidnumber,而在master.cf裏已經定義好了投遞時的運行身份(vuser:vgroup),因此這兩個字段的內容必須爲1000,不然將出現投遞錯誤,例如報0×06等錯誤。

3、設置虛擬域和虛擬用戶的配置文件

shell

# cd /var/www/extsuite/extman/docs

# cp mysql_virtual_alias_maps.cf /etc/postfix/

# cp mysql_virtual_domains_maps.cf /etc/postfix/

# cp mysql_virtual_mailbox_maps.cf /etc/postfix/

# cp mysql_virtual_sender_maps.cf /etc/postfix/

配置main.cf:

shell

# vi /etc/postfix/main.cf

增長如下內容:

# extmail config here

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 :

shell

# service postfix restart

4、測試authlib

在命令行下執行:

shell

# /usr/sbin/authtest -s login postmaster@extmail.org extmail

結果以下:

Authentication succeeded.

Authenticated: postmaster@extmail.org (uid 1000, gid 1000)

Home Directory: /home/domains/extmail.org/postmaster

Maildir: /home/domains/extmail.org/postmaster/Maildir/

Quota: 104857600S

Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0

Cleartext Password: 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,初始密碼:extmail*123*,登錄成功後,建議將密碼修改,以確保安全。

5、配置圖形化日誌

啓動mailgraph_ext

shell

# /usr/local/mailgraph_ext/mailgraph-init start

啓動cmdserver(在後臺顯示系統信息)

shell

# /var/www/extsuite/extman/daemon/cmdserver --daemon

加入開機自啓動:

shell

# echo 「/usr/local/mailgraph_ext/mailgraph-init start」 >&gt; /etc/rc.d/rc.local

# echo 「/var/www/extsuite/extman/daemon/cmdserver -v -d」 &gt;&gt; /etc/rc.d/rc.local

使用方法: 等待大約15分鐘左右,若是郵件系統有必定的流量,便可登錄到extman裏,點「圖形日誌」便可看到圖形化的日誌。具體天天,周,月,年的則點擊相應的圖片進入便可。

10、配置cyrus-sasl

RHEL4/CentOS4的cyrus-sasl默認沒有打開authdaemon的支持,爲了使用集中認證的authlib,必須打開這個支持。爲此咱們必須刪除系統的cyrus-sasl軟件包,替換成打開了authdaemon支持的sasl軟件包。

1、安裝cyrus-sasl

刪除系統的cyrus-sasl:

shell

# rpm -e cyrus-sasl --nodeps

安裝新的支持authdaemon的軟件包

shell

# yum install cyrus-sasl

2、配置main.cf文件

Postfix的SMTP認證須要透過Cyrus-SASL,鏈接到authdaemon獲取認證信息。

編輯main.cf

shell

# vi /etc/postfix/main.cf

增長以下內容:

# smtpd related config

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,

# SMTP sender login matching config

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

# SMTP AUTH config here

broken_sasl_auth_clients = yes

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $myhostname

smtpd_sasl_security_options = noanonymous

3、編輯smtpd.conf文件

shell

# vi /usr/lib/sasl2/smtpd.conf

確保其內容爲:

pwcheck_method: authdaemond

log_level: 3

mech_list: PLAIN LOGIN

authdaemond_path:/var/spool/authdaemon/socket

從新啓動postfix:

shell

# service postfix start

4、測試SMTP認證

經過如下命令得到postmaster@extmail.org的用戶名及密碼的BASE64編碼:

shell

# perl -e ‘use MIME::Base64; print encode_base64(」postmaster\@extmail.org」)’

內容以下:

cG9zdG1hc3RlckBleHRtYWlsLm9yZw==

shell

# perl -e ‘use MIME::Base64; print encode_base64(」extmail」)’

內容以下:

ZXh0bWFpbA==

而後本機測試:

shell

# 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.org

ehlo demo.domain.tld <&lt; 輸入內容

250-mail.extmail.org

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH LOGIN PLAIN

250-AUTH=LOGIN PLAIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

auth login &lt;&lt; 輸入內容

334 VXNlcm5hbWU6

cG9zdG1hc3RlckBleHRtYWlsLm9yZw== &lt;&lt; 輸入內容

334 UGFzc3dvcmQ6

ZXh0bWFpbA== &lt;&lt; 輸入內容

235 2.0.0 Authentication successful

quit &lt;&lt; 輸入內容

221 2.0.0 Bye

最後出現235 Authentication Successful 代表認證成功了。

11、配置courier-imap 1、安裝Courier-imap

默認的courier-authlib及courier-imap都會增長系統自啓動設置,所以下一次服務器啓動將自動啓動相應的authlib及POP3服務

shell

# yum install courier-imap

配置courier-imap

因爲Courier-imap的IMAP目錄是按UTF-7編碼的,ExtMail目前尚未正式支持IMAP目錄,所以須要屏蔽IMAP,只提供pop3服務。而就目前的使用狀況來看,IMAP使用的很是少,絕大部分OutLook/Foxmail用戶都習慣使用POP3而非IMAP。

shell

# vi /usr/lib/courier-imap/etc/imapd

修改內容以下:

IMAPDSTART=NO

shell

# vi /usr/lib/courier-imap/etc/imapd-ssl

修改內容以下:

IMAPDSSLSTART=NO

而後從新啓動courier-imap:

shell

# service courier-imap start

測試POP3 請按以下步驟輸入pop3命令測試其是否正常工做,注意藍色的信息是咱們輸入到POP3服務器的(請首先登陸extman自行創建test@extmail.org用戶,密碼:extmail)

shell

# telnet localhost 110

其過程以下:

Trying 127.0.0.1...

Connected to localhost.localdomain (127.0.0.1).

Escape character is '^]'.

+OK Hello there.

user test@extmail.org &lt;&lt; 輸入內容

+OK Password required.

pass extmail &lt;&lt; 輸入內容

+OK logged in.

list &lt;&lt; 輸入內容

+OK POP3 clients that break here, they violate STD53.

.

quit &lt;&lt; 輸入內容

+OK Bye-bye.

Connection closed by foreign host.

12、配置內容、病毒過濾 1、安裝amavisd-new

shell

# yum install amavisd-new

設置相關目錄權限:

shell

# chown -R amavis.amavis /var/spool/vscan/

2、配置SpamAssassin

Amavisd-new 經過Mail::SpamAssassin 模塊來調用SA的功能,所以這裏配置SA和常規配置SA軟件有些區別,主要集中在修改local.cf文件上。

增長中文規則: 用於處理中文(簡體)垃圾郵件。

shell

# wget -N -P /usr/share/spamassassin www.ccert.edu.cn/spam/sa/Chinese_rules.cf

設置規則自動更新:

shell

# /usr/bin/crontab -e

而後輸入以下的內容:

0 0 1 * * wget -N -P /usr/share/spamassassin www.ccert.edu.cn/spam/sa/Chinese_rules.cf; /etc/init.d/amavisd restart

存盤退出便可。最後運行如下調試命令以確認amavisd沒有錯誤:

shell

# /usr/sbin/amavisd -c /etc/amavisd/amavisd.conf debug

若是沒有異常提示或報錯退出則表示一切都正常,按ctrl+c終止,而後正常啓動,若提示pid不存在等錯誤,沒必要理會。

設置amavisd開機自啓:

shell

# service amavisd start

# chkconfig amavisd on

3、配置ClamAV

安裝ClamAV

shell

# yum install clamd

編輯clamd.conf文件

shell

# vi /etc/clamd.conf

去掉 ‘LocalSocket /var/run/clamav/clamd.sock’的註釋,並註釋掉 ‘TCPSocket 3310’,咱們將使用unix socket而不是TCP,二者不可並存。

變更內容見下:

# Default: disabled

LocalSocket /var/run/clamav/clamd.sock

#TCPSocket 3310

設置相關目錄權限:

將clamav加到amavis運行組裏,並調整目錄權限,不然clamav將沒法掃描amavisd-new產生的臨時文件

shell

# gpasswd -a clamav amavis

# usermod -G amavis clamav

# chown amavis.amavis /var/spool/vscan

# chmod 750 /var/spool/vscan

# chown amavis.amavis /var/spool/vscan/tmp

# chmod 750 /var/spool/vscan/tmp

默認的/var/spool/vscan 目錄屬性是:

drwxr-x--- 5 amavis amavis

對於clamav用戶而言,則無任何權限訪問該目錄,所以maillog裏amavisd-new會提示:

May 19 08:38:53 as3 amavis[1752]: (01752-01) ask_av (ClamAV-clamd) FAILED - unexpected result: /var/spool/vscan/tmp/amavis-20050519T

083853-01752/parts: Access denied. ERROR\n

May 19 08:38:53 as3 amavis[1752]: (01752-01) WARN: all primary virus scanners failed, considering backups

啓動ClamAV及freshclam開機自啓:

shell

# service clamd start

# freshclam –daemon

# echo 「/usr/bin/freshclam –daemon」 >&gt; /etc/rc.d/rc.local

4、配置amavisd.con文件

修改amavisd.conf

shell

# 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'} = { # mail originating from @mynetworks

originating =&gt; 1, # is true in MYNETS by default, but let's make it explicit

os_fingerprint_method =&gt; undef, # don't query p0f for internal clients

allow_disclaimers =&gt; 1, # enables disclaimer insertion if available

bypass_spam_checks_maps =&gt; [1],

bypass_banned_checks_maps =&gt; [1],

bypass_header_checks_maps =&gt; [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結合

['ClamAV-clamd',

\&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd.sock"],

qr/\bOK$/, qr/\bFOUND$/,

qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],

);

@av_scanners_backup = (

['ClamAV-clamscan', 'clamscan',

"--stdout --no-summary -r --tempdir=$TEMPBASE {}",

[0], qr/:.*\sFOUND$/, qr/^.*?: (?!Infected Archive)(.*) 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

增長郵件別名

shell

# vi /etc/postfix/aliases

增長以下信息,注意:默認的aliases數據庫裏已有一條virusalert的別名,請刪除,再輸入下面的別名記錄,並確保全部記錄都是惟一的:

virusalert: root

spam.police: root

postfix: test@extmail.org

保存並執行newaliases命令生成新的別名數據庫,從新啓動amavisd:

shell

# newaliases

# service amavisd restart

編輯master.cf文件:

shell

# 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=10

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

-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks

編輯main.cf文件:

shell

# 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 :

shell

# service postfix restart

從新啓動amavisd:

shell

# service amavisd restart

6、測試Clamav

shell

# 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.org

mail from:<postmaster@extmail.org> <&lt; 輸入內容

250 2.1.0 Ok

rcpt to:&lt;test@extmail.org> <&lt; 輸入內容

250 2.1.5 Ok

data &lt;&lt; 輸入內容

354 End data with .

X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* &lt;&lt; 輸入內容

.

250 2.0.0 Ok: queued as BC24E85260

quit &lt;&lt; 輸入內容

221 2.0.0 Bye

Connection closed by foreign host.

在郵件日誌裏,應該有相應的信息出現:

Mar 22 06:43:15 localhost amavis[15405]: (15405-01) Blocked INFECTED (Eicar-Test-Signature), [192.168.0.235] ->, quarantine:

virus-mI6vbjkWZ2Tz, Message-ID: <003401c88c1a$74706360$eb00a8c0@nbk00045>, mail_id: mI6vbjkWZ2Tz, Hits: -, size: 1757, 474 ms

若是看到相似這樣的日誌,代表Clamav+Amavisd-new工做正常。

十3、配置spam_locker 1、安裝Spam_Locker

shell

# yum install extsuite-slockd

配置resolv.conf

請確認/etc/resolv.conf裏的dns服務器是離你的郵件服務器最近,速度最快的dns server,slockd很依賴dns的好壞,所以給系統配置一個快速的dns能大幅度提升處理速度。如下給出一個配置僅供參考:

shell

# vi /etc/resolv.conf

增長如下內容: nameserver 61.134.1.5

上述dns服務器是西安電信的DNS服務器,對於非廣東朋友,請改成離你最近的DNS服務器IP,若是可能的話,請配置一個簡單的bind,成爲本地的dns cache server,能夠得到最高性能。這裏略過這一步驟,但您必須確保dns的配置是正確而且可靠的,不然slockd將不能工做!

2、測試slockd

啓動slockd

shell

# /usr/local/slockd/slockd-init start

此時slockd將啓動,並進入非daemon方式的監聽模式,接受來自10030端口的請求,命令行下將顯示以下調試信息:

Starting spam locker daemon: slockd

starting child 2908

starting child 2909

打開另外一個ssh/終端窗口:

shell

# cd /usr/local/slockd/tools

輸入:

shell

# perl policy_sig -h localhost -p 10030 --helo FOOBAR --ip 192.168.0.1 --from test@foo.com --to test@bar.com

此時,程序應該返回以下錯誤信息:這表示slockd初步的正常工做了。

action=554 blocked using zen.spamhaus.org, see http://bl.extmail.org/cgi/rbl?192.168.0.1

設置slockd開機自啓動

shell

# /usr/local/slockd/slockd-init start # echo 「/usr/local/slockd/slockd-init start」 &gt;&gt; /etc/rc.d/rc.local

3、配置Postfix

slockd調試正常後,必須配置postfix以使其打開對slockd的支持。

編輯main.cf文件

shell

# 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_unauth_pipelining,

reject_invalid_hostname,

check_policy_service inet:127.0.0.1:10030

從新啓動postfix以使配置生效

shell

# service postfix restart

注意事項: 上述配置是將slockd的查詢放到最後,這也是進一步提升資源利用律的辦法,由於有部分功能postfix已實現了,因此就先由postfix檢測,若是檢測不到再由slockd完成。

十4、配置dspam 1、安裝dspam

Dspam的配置主要參考本文最後的附錄部分

shell

# yum install dspam-mysql

2、導入 DSPAM 訓練庫

shell

# 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 database dspam」

# mysql -u root -p -e 「grant all on dspam.* to dspam@localhost identified by ‘dspam’」

# mysql -u dspam -p dspam dspam < /root/dspam-trained-data.sql

DSPAM的token數據庫的定時清理:

shell

# crontab -e

加入如下內容:

0 0 * * * /usr/bin/mysql -u dspam -p'dspam' dspam &lt; /usr/share/dspam/sql/mysql/purge.sql

0 0 * * * /usr/bin/dspam_logrotate -a 30 -d /var/spool/dspam/data

3、配置 dspam.conf 文件

shell

# vi /etc/dspam/dspam.conf

變更內容以下:

DeliveryHost 127.0.0.1

DeliveryPort 10024

DeliveryIdent localhost

DeliveryProto SMTP

Trust extmail

Preference "signatureLocation=headers" # 'message' or 'headers'

Preference "showFactors=off"

MySQLUIDInSignature on

MySQLServer /var/lib/mysql/mysql.sock

MySQLUser dspam

MySQLPass dspam

MySQLDb dspam

MySQLCompress true

MySQLConnectionCache 10

ServerPort 10028

ServerQueueSize 32

ServerPID /var/spool/dspam/dspamd.pid

ServerMode auto

ServerPass.Relay1 "secret"

ServerParameters "--user extmail --deliver=innocent,spam"

ServerIdent "localhost.localdomain"

ClientHost 127.0.0.1

ClientPort 10028

ClientIdent "secret@Relay1"

3、啓動 dspam 進程

shell

# chkconfig dspamd on

# service dspamd start

查看dspam啓動進程

shell

# ps aux |grep dspam

顯示如下內容:

dspam 18407 0.0 0.5 5452 1344 pts/0 S 19:16 0:00 /usr/sbin/dspamd --daemon

root 18412 0.0 0.2 5140 668 pts/0 S+ 19:17 0:00 grep dspamd

4、修改main.cf文件

shell

# vi /etc/postfix/main.cf

增長如下內容:

header_checks = regexp:/etc/postfix/dspam_header_checks

設置郵件標題過濾管理 以防止重複X-DSPAM-Signature標題,能夠防止簽名被報道爲垃圾。這發生在當你從一個已經運行Dspam的服務器收到郵件,或被用於經過僞造的、濫發郵件來阻止你訓練數據庫,

shell

# vi /etc/postfix/dspam_header_checks

增長如下內容:

/^(X-DSPAM-.*)/ IGNORE

/^(X-Spam-.*)/ IGNORE

重啓postfix :

shell

# service postfix restart

5、編輯 amavisd.conf 文件

shell

# 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 --user extmail)],

],

);

SA增長DSpam插件:

shell

# cd /usr/lib/perl5/vendor_perl/5.8.5/Mail/SpamAssassin/Plugin

# wget http://www.extmail.org/download/misc/dspam/dspam.pm

編輯 local.cf 文件

shell

# cd /etc/mail/spamassassin/

# wget http://www.extmail.org/download/misc/dspam/dspam.cf

# vi local.cf

在下面增長如下內容

include dspam.cf

編輯 init.pre 文件:

shell

# vi init.pre

在下面增長如下內容

loadplugin Mail::SpamAssassin::Plugin::dspam

重啓amavisd

shell

# service amavisd restart

6、增長 extmail 的垃圾郵件舉報

說明:

Extmail 1.0.9正式加入垃圾郵件舉報功能,主要基於(xueron)的補丁包,並進行了必定的調整,使該功能能夠兼容DSPAM及Spamassassin兩種內容過濾軟件的訓練。

Extmail1.1.1加入(stvictor)提供的spamassassin舉報功能,感謝!

修改 webmail.cf

shell

# vi /var/www/extsuite/extmail/webmail.cf

主要變更的內容以下:

SYS_SPAM_REPORT_ON = 1

SYS_SPAM_REPORT_TYPE = dspam

設置maidrop的全局過濾

shell

# vi /etc/maildroprc

內容以下:

# Decoder for high quality key word filtering

# Author: hzqbbc &lt;hzqbbc@hzqbbc.com> - ExtMail Dev Team

DECODER="/var/www/extsuite/extmail/tools/decode -v"

if ((/^(From|Sender|Return-Path):.*MAILER\-DAEMON/))

{

BADSENDER=1

}

# Custom filter and auto deliver to Junk mailbox support

# need test command and other Unix command

`test -f $HOME/.mailfilter && exit 1 || exit 0`

# No customize filtering rules

if ( $RETURNCODE == 0 )

{

if (/^X-Spam-Flag:.*YES/ || /^X-DSPAM-Result:.*Spam/)

{

exception {

to "$HOME/Maildir/.Junk/."

}

}

}

7、配置DSPAM Web 界面

安裝相關的rpm包:

shell

# yum install perl-GDGraph

# yum install perl-GD-Graph3d

# yum install dspam-web

建立dspam-web 認證用戶:

shell

# cd /usr/share/dspam/webui/cgi-bin

# echo 「extmail」 &gt; admins

# htpasswd -c .htpasswd extmail

輸入認證密碼

New password:

Re-type new password:

Adding password for user extmail

啓動 dspam-web 守護進程

shell

# service dspam-webd start

這實際是啓動了mini_httpd進程,查看 mini_httpd 是否啓動正常:

shell

# ps aux |grep mini

顯示如下內容:

dspam 18580 0.0 0.3 4152 820 ? Ss 20:05 0:00 mini_httpd -C /etc/dspam/webui.conf

root 18582 0.0 0.2 5316 668 pts/0 S+ 20:05 0:00 grep mini

重啓 apache

shell

# /etc/init.d/httpd restart

訪問 dspam-web

http://mail.example.com/dspam

輸入你在 .htpasswd 文件中建立的用戶和密碼

十5、補充設置

如下是補充的ExtMail Solution有關文檔,主要是爲但願進一步瞭解mail系統運行,並提升extmail效能的朋友準備,對於初學者而言,建議要先打好基礎再進行測試。

1、增長FCGI支持

爲extmail增長FCGI的支持,主要是爲了得到優異的web效能,克服CGI不能應付大量訪問及低效率的缺陷。根據咱們的測試,CGI模式下的頁面效率只有FCGI下的1/10~1/100,所以建議有條件的用戶仍是使用FCGI。往後ExtMail Solution的web CGI程序將所有都支持FCGI。

Extmail開發團隊花了大量時間從新設計了FCGI server的進程管理模型,並參考了apache的機制,新版dispatch.fcgi 終於能夠象apache同樣定義max server數,min server(啓動進程數)以及每進程服務次數,每進程執行時限等,可較好的利用系統cpu/內存資源,既保證很少佔內存,又可保證請求數上升時能有足夠進程數服務。

就咱們搜索發現,目前網上尚未開源版的FastCGI server能實現上述自適應負載功能(例如php-fpm還未實現,POE等也未實現),因此Extmail的dispatch.fcgi也許是第一個實現了這個功能。

mod_fastcgi 是針對Apache Web服務器的FCGI支持模塊,下載地址: http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz

安裝mod_fastcgi :

shell

# wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz

# tar xfz mod_fastcgi-2.4.6.tar.gz

# cd mod_fastcgi-2.4.6

# cp Makefile.AP2 Makefile

# make top_dir=/etc/httpd install

安裝perl-FCGI 除了Apache須要FCGI的支持外,extmail也須要相應的perl-FCGI模塊。

shell

# yun install perl-FCGI

配置虛擬主機:

shell

# vi /etc/httpd/conf/vhost_extmail.conf

增長內容以下:

LoadModule fastcgi_module modules/mod_fastcgi.so

<Ifmodule mod_fastcgi.c>

FastCgiExternalServer /usr/bin/dispatch.fcgi -host 127.0.0.1:8888 -idle-timeout 240

</Ifmodule>

#同時,去掉以下行:

#ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/

#改成:

Alias /extmail/cgi/ /usr/bin/dispatch.fcgi/

<Location "/extmail/cgi">

SetHandler fastcgi-script

</Location>

重啓Apache和fastcgi server開機自啓動:

shell

# service httpd restart

# /var/www/extsuite/extmail/dispatch-init start

# echo 「/var/www/extsuite/extmail/dispatch-init start」 &gt;&gt; /etc/rc.d/rc.local

結束語:

經過此文檔,讀者應該可以較容易地架設一個功能較齊全的電子郵件系統。本文檔將繼續保持更新,逐步將一些高級的設置方法公佈出來,爭取ExtMail Solution更加完整,力求完美。

已知Bugs:

整個ExtMail Solution盡力將Opensource軟件的優勢發揮到極至,但免不了仍是有bug。如下是幾個已知的問題:

Amavisd-new

退信模板仍是英文的

產生的彙報信息不夠友好

Spam Locker

錯誤識別一些配置異常的mail服務器

與內容過濾器結合不夠緊密

TODO 列表

支持SMTP 及 POP3/IMAP的TLS/SSL加密

HTTP及SMTP/POP3等CA證書的配置

更精細的Anti-Spam策略及關鍵字過濾

附錄 Dspam+Amavis-new+SA+Clamav

編寫本文的初衷,是爲了提升反垃圾郵件效果,並克服dspam初期訓練、配置的各類困難過程,減輕系統管理員的負擔,架設一個全功能,全自動的反垃圾郵件系統;

DSPAM 的特色:

DSPAM是一個專爲企業設計的可擴展而且基於開放源碼的垃圾郵件過濾器.在正確配置系統,過濾成功率達99.5 % - 99.95%。 DSPAM支持多種MTA,並還能夠部署做爲一個獨立的SMTP設備。對於軟件開發商而言,DSPAM的核心引擎( libdspam )能夠很容易地直接引入其過濾器系統,目前,DSPAM已經應用到350000個郵箱中。

DSPAM是很流行的防垃圾工具之一,DSPAM可以學習每一個用戶的不一樣郵件的習性:根據這些習性告訴過濾器什麼是垃圾郵件。這就使得即便在一個很龐大的系統中,DSPAM仍爲每一個用戶提供高精確度的、智能的過濾功能。並提供了一個可以學習每一個用戶的郵件習性的管理維護功能,這些習性可能會有些誤判。

目前DSPAM支持的存儲包括SQLite,Berkeley DB,MySQL,PostgreSQL,Oracle和hash。能夠與任何的MTA (Mail Transfer Agent)Sendmail, Postfix, Exim, Courier, Communigate Pro, 和 QMail 工做。

DSPAM的缺點就是依賴用戶長時期培訓才能取得很是高的垃圾郵件捕獲率,不過通過咱們的努力,能夠減輕甚至克服這個問題。

相關軟件的下載站點:

http://mirror.extmail.org/yum

相關 rpm 包

dspam-3.8.0-10ext.i386.rpm

libdspam-3.8.0-10ext.i386.rpm

dspam-mysql-3.8.0-10ext.i386.rpm

perl-GDGraph-1.44-1.ext.noarch.rpm

perl-GDTextUtil-0.86-1.ext.noarch.rpm

perl-GD-Graph3d-0.63-2.ext.noarch.rpm

mini_httpd-1.19-1ext.i386.rpm

dspam-web-3.8.0-10ext.i386.rpm

extmail-1\[1\]\[1\].1.0.tar.gz

20050311_spam_2.tar.bz2

20030228_easy_ham_2.tar.bz2

dspam-trained-data.sql.gz

dspam.pm

dspam.cf

1、配置 dspam 1、安裝dspam

如下爲軟件的存放目錄:/root/rpm ,安裝和配置所有以root身份進行

# cd /root/rpm

# rpm -ivh libdspam-3.8.0-10ext.i386.rpm

# rpm -ivh dspam-3.8.0-10ext.i386.rpm

# rpm -ivh dspam-mysql-3.8.0-10ext.i386.rpm

2、建立dspam所需的數據庫

# cd /usr/share/dspam/sql/mysql/

# mysql -u root -p -e "create database dspam"

Enter password:

# mysql -u root -p -e "grant all on dspam.* to dspam@localhost identified by 'dspam'"

Enter password:

# mysql -u dspam -pdspam dspam < mysql_objects-4.1.sql

# mysql -u dspam -pdspam dspam &lt; virtual_users.sql

3、DSPAM的token數據庫的定時清理:

# crontab -e

加入如下內容:

引用:

0 0 * * * /usr/bin/mysql -u dspam -p'dspam' dspam &lt; /usr/share/dspam/sql/mysql/purge-4.1.sql

0 0 * * * /usr/bin/dspam_logrotate -a 30 -d /var/spool/dspam/data

4、配置 dspam.conf 文件,內容以下:

# vi /etc/dspam/dspam.conf

引用:

Home /var/spool/dspam

StorageDriver /usr/lib/libmysql_drv.so

TrustedDeliveryAgent "/usr/sbin/sendmail"

OnFail error

DeliveryHost 127.0.0.1

DeliveryPort 10024

DeliveryIdent localhost

DeliveryProto SMTP

Trust root

Trust dspam

Trust extmail

TrainingMode teft

TestConditionalTraining on

Feature whitelist

Algorithm graham burton

Tokenizer chain

PValue bcr

WebStats on

Preference "signatureLocation=headers" # 'message' or 'headers'

Preference "showFactors=off"

AllowOverride trainingMode

AllowOverride spamAction spamSubject

AllowOverride statisticalSedation

AllowOverride enableBNR

AllowOverride enableWhitelist

AllowOverride signatureLocation

AllowOverride showFactors

AllowOverride optIn optOut

AllowOverride whitelistThreshold

MySQLUIDInSignature on

MySQLServer /var/lib/mysql/mysql.sock

MySQLUser dspam

MySQLPass dspam

MySQLDb dspam

MySQLCompress true

MySQLConnectionCache 10

Notifications off

PurgeSignatures 14 # Stale signatures

PurgeNeutral 90 # Tokens with neutralish probabilities

PurgeUnused 90 # Unused tokens

PurgeHapaxes 30 # Tokens with less than 5 hits (hapaxes)

PurgeHits1S 15 # Tokens with only 1 spam hit

PurgeHits1I 15 # Tokens with only 1 innocent hit

LocalMX 127.0.0.1

SystemLog on

UserLog on

Opt out

MaxMessageSize 1048576

ServerPort 10028

ServerQueueSize 32

ServerPID /var/spool/dspam/dspamd.pid

ServerMode auto

ServerPass.Relay1 "secret"

ServerParameters "--user extmail --deliver=innocent,spam"

ServerIdent "localhost.localdomain"

ClientHost 127.0.0.1

ClientPort 10028

ClientIdent "secret@Relay1"

ProcessorURLContext on

ProcessorBias on

5、啓動 dspam 後臺進程:

# chkconfig dspamd on

# /etc/init.d/dspamd start

查看dspam啓動進程

# ps aux |grep dspam

dspam 18407 0.0 0.5 5452 1344 pts/0 S 19:16 0:00 /usr/sbin/dspamd --daemon

root 18412 0.0 0.2 5140 668 pts/0 S+ 19:17 0:00 grep dspamd

2、Postfix的配置 1、main.cf 修改如下內容:

# cd /etc/postfix

# vi /main.cf

變更內容以下:

引用:

smtpd_client_restrictions =

permit_sasl_authenticated,

permit_mynetworks,

check_client_access pcre:/etc/postfix/dspam_filter_access

header_checks = regexp:/etc/postfix/header_checks

# Content-Filter

#content_filter = smtp:[127.0.0.1]:10024

2、過濾進來的郵件

# vi dspam_filter_access

加入如下內容:

引用:

/./ FILTER lmtp:[127.0.0.1]:10028

3、設置郵件標題過濾管理

# vi header_checks

加入如下內容:

引用:

/^(X-DSPAM-.*)/ IGNORE

/^(X-Spam-.*)/ IGNORE

4、修改 master.cf 如下內容:

# vi master.cf

引用:

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

-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks

5、重啓postfix :

# /etc/init.d/postfix restart

3、DSpam模塊作爲SpamAssassin的插件:

SA增長DSpam插件,根據郵件頭上dspam的結果增減不一樣的分數

1、複製 dspam.pm 模塊

# cd /usr/lib/perl5/vendor_perl/5.8.5/Mail/SpamAssassin/Plugin

# cp /root/rpm/dspam.pm ./

2、編輯 local.cf 文件

# cd /etc/mail/spamassassin/

# cp /root/rpm/dspam.cf ./

# vi local.cf

在下面增長如下內容

include dspam.cf

3、編輯 init.pre 文件:

# vi init.pre

在下面增長如下內容

loadplugin Mail::SpamAssassin::Plugin::dspam

4、安裝 ExtMail

說明:

Extmail 1.0.9正式加入垃圾郵件舉報功能,主要基於(xueron)的補丁包,並進行了必定的調整,使該功能能夠兼容DSPAM及Spamassassin兩種內容過濾軟件的訓練。Extmail1.1.1加入(stvictor)提供的spamassassin舉報功能,感謝!

1、安裝 ExtMail

# cd /var/www/extsuite/

# mv extmail extmail-bak

# tar zxvf /root/src/extmail-1.1.1.tar.gz

# mv extmail-1.1.1extmail

2、設置 webmail.cf

# cd extmail

# cp webmail.cf.default webmail.cf

# vi webmail.cf

主要變更的內容見下:其它變更根據實際狀況修改

引用:

SYS_SPAM_REPORT_ON = 1

SYS_SPAM_REPORT_TYPE = dspam

3、設置maidrop的全局過濾

如下的maildroprc 文件同時支持調用ExtMail 多語言過濾器×××,若是用戶已創建自定義過濾規則,則此條全局規則無效(以用戶爲準)。

# vi /etc/maildroprc

引用:

# Decoder for high quality key word filtering

logfile "/var/log/maildrop.log"

# Author: hzqbbc &lt;hzqbbc@hzqbbc.com> - ExtMail Dev Team

DECODER="/var/www/extsuite/extmail/tools/decode -v"

if ((/^(From|Sender|Return-Path):.*MAILER\-DAEMON/))

{

BADSENDER=1

}

# Auto deliver to Junk mailbox support if there is no custom

# mailfilter, need test command and correct PATH env

`test -f $HOME/.mailfilter && exit 1 || exit 0`

# No customize filtering rules

if ( $RETURNCODE == 0 )

{

if (/^X-Spam-Flag:.*YES/ || /^X-DSPAM-Result:.*Spam/)

{

exception {

to "$HOME/Maildir/.Junk/."

}

}

}

添加maildrop日誌文件:

# touch /var/log/maildrop.log

# chown vuser.vgroup /var/log/maildrop.log

5、訓練 DSPAM

# cd /root/rpm

# tar xvfj 20050311_spam_2.tar.bz2

# tar xvfj 20030228_easy_ham_2.tar.bz2

# dspam_train extmail spam_2/ easy_ham_2/

訓練完成後會顯示:

TRAINING COMPLETE

Training Snapshot:

dspam

TP: 1314 TN: 1401 FP: 0 FN: 83 SC: 8 NC: 0

SHR: 94.06% HSR: 0.00% OCA: 97.03%

Overall Statistics:

dspam

TP: 1314 TN: 1401 FP: 0 FN: 83 SC: 8 NC: 0

SHR: 94.06% HSR: 0.00% OCA: 97.03%

2、不訓練的辦法 (建議使用)

爲了進一步下降管理員的工做量,咱們進行了大量的測試和摸索工做,目前提供一個簡單的縮減訓練週期和工做量的方法。 咱們提供一個已經預先訓練好的dspam數據庫文件(mysql only),該庫是由3000封ham+3000封spam訓練而成,用戶只要在新的dspam系統裏導入該數據庫,原理上就可免除初期蒐集最新spam及最新ham並進行訓練的痛苦。

安裝方法:

# cd /root/rpm

# gzip -d dspam-trained-data.sql.gz

# cd /var/lib/mysql

# rm -rf dspam/ (備註:若是沒有dspam的庫,能夠不用執行)

# mysql -u root -p -e "create database dspam"

# mysql -u root -p -e "grant all on dspam.* to dspam@localhost identified by 'dspam'"

# mysql -u dspam -pdspam dspam < /root/rpm/dspam-trained-data.sql

6、配置DSPAM Web 界面 1、安裝相關的rpm包:

# rpm -ivh perl-GDTextUtil-0.86-1.rf.noarch.rpm

# rpm -ivh perl-GDGraph-1.44-1.rf.noarch.rpm

# rpm -ivh perl-GD-Graph3d-0.63-2.rf.noarch.rpm

# rpm -ivh mini_httpd-1.19-1ext.i386.rpm

# rpm -ivh dspam-web-3.8.0-10ext.i386.rpm

備註:由於我是以 EMOS 爲基礎,裏面包含了 perl-GD ,若是沒有安裝 perl-GD 的, 請自行安裝

2、建立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 extmail

3、啓動 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.conf

root 18582 0.0 0.2 5316 668 pts/0 S+ 20:05 0:00 grep mini

4、重啓 apache

# /etc/init.d/httpd restart

5、訪問 dspam-web

http://mail.example.com/dspam

輸入你在 .htpasswd 文件中建立的用戶和密碼

十5、補充設置

如下是補充的ExtMail Solution有關文檔,主要是爲但願進一步瞭解mail系統運行,並提升extmail效能的朋友準備,對於初學者而言,建議要先打好基礎再進行測試。

1、增長FCGI支持

爲extmail增長FCGI的支持,主要是爲了得到優異的web效能,克服CGI不能應付大量訪問及低效率的缺陷。根據咱們的測試,CGI模式下的頁面效率只有FCGI下的1/10~1/100,所以建議有條件的用戶仍是使用FCGI。往後ExtMail Solution的web CGI程序將所有都支持FCGI。

Extmail開發團隊花了大量時間從新設計了FCGI server的進程管理模型,並參考了apache的機制,新版dispatch.fcgi 終於能夠象apache同樣定義max server數,min server(啓動進程數)以及每進程服務次數,每進程執行時限等,可較好的利用系統cpu/內存資源,既保證很少佔內存,又可保證請求數上升時能有足夠進程數服務。

就咱們搜索發現,目前網上尚未開源版的FastCGI server能實現上述自適應負載功能(例如php-fpm還未實現,POE等也未實現),因此Extmail的dispatch.fcgi也許是第一個實現了這個功能。

mod_fastcgi 是針對Apache Web服務器的FCGI支持模塊,下載地址: http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz

安裝mod_fastcgi :

shell

# wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
# tar xfz mod_fastcgi-2.4.6.tar.gz
# cd mod_fastcgi-2.4.6
# cp Makefile.AP2 Makefile
# make top_dir=/etc/httpd install

安裝perl-FCGI 除了Apache須要FCGI的支持外,extmail也須要相應的perl-FCGI模塊。

shell

# yun install perl-FCGI

配置虛擬主機:

shell

# vi /etc/httpd/conf/vhost_extmail.conf

增長內容以下:

LoadModule fastcgi_module modules/mod_fastcgi.so

<Ifmodule mod_fastcgi.c>

FastCgiExternalServer /usr/bin/dispatch.fcgi -host 127.0.0.1:8888 -idle-timeout 240

</Ifmodule>

#同時,去掉以下行:

#ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/

#改成:

Alias /extmail/cgi/ /usr/bin/dispatch.fcgi/

<Location "/extmail/cgi">

SetHandler fastcgi-script

</Location>

重啓Apache和fastcgi server開機自啓動:

shell

# service httpd restart
# /var/www/extsuite/extmail/dispatch-init start
# echo 「/var/www/extsuite/extmail/dispatch-init start」 &gt;&gt; /etc/rc.d/rc.local

結束語:
經過此文檔,讀者應該可以較容易地架設一個功能較齊全的電子郵件系統。本文檔將繼續保持更新,逐步將一些高級的設置方法公佈出來,爭取ExtMail Solution更加完整,力求完美。

已知Bugs:
整個ExtMail Solution盡力將Opensource軟件的優勢發揮到極至,但免不了仍是有bug。如下是幾個已知的問題:

Amavisd-new

退信模板仍是英文的

產生的彙報信息不夠友好

Spam Locker

錯誤識別一些配置異常的mail服務器

與內容過濾器結合不夠緊密

TODO 列表

支持SMTP 及 POP3/IMAP的TLS/SSL加密

HTTP及SMTP/POP3等CA證書的配置

更精細的Anti-Spam策略及關鍵字過濾

系統安全配置(基於iptables)

 

相關文章
相關標籤/搜索