extmail搭建

Extmail搭建



目錄

一、背景介紹............1

二、實戰演練............1

2.1 操作系統安裝............1

2.2 製作YUM倉庫............1

2.3 配置MTA-postfix............1

2.3.1 安裝postfix............1

2.3.2 配置postfix............1

2.4 配置Courier-Authlib............2

2.4.1 安裝Courier-Authlib............2

2.4.2 配置Courier-Authlib............2

2.5 配置Maildrop............3

2.5.1 安裝Maildrop............3

2.5.2 配置Maildrop............3

2.5.3 測試maildrop對authlib支持............4

2.6 配置Apache............4

2.7 配置Webmail-ExtMail............5

2.7.1 安裝ExtMail............5

2.7.2 編輯webmail.cf............5

2.8 配置管理後臺-ExtMan............5

2.8.1 yum安裝ExtMan............5

2.8.2 數據庫初始化............5

2.8.3 設置虛擬域和虛擬用戶的配置文件............6

2.8.4 測試authlib............6

2.8.5 配置圖形化日誌............7

2.9 配置Cyrus-SASL............7

2.9.1 安裝cyrus-sasl............7

2.9.2 配置main.cf文件............8

2.9.3 編輯smtpd.conf文件............8

2.9.4 測試SMTP認證............9

2.10 配置Courier-IMAP............9

2.10.1 安裝Courier-imap............9

2.10.2 測試POP3工作是否正常............10

三、注意事項............10


一、背景介紹

ExtMail Solution 是一個基於優秀開源軟件的電子郵件系統解決方案,核心部件包括了PostfixAmavisd-newClamAVExtMailExtManCourier系列軟件。是一個功能相對比較齊全的免費電子郵件系統。本次環境中使用的是CentOS

二、實戰演練

2.1 操作系統安裝

採用系統光盤進行安裝,然後按照日常安裝步驟依次進行是否校驗介質、安裝界面語言等選項……注意必須安裝MYSQL數據庫。

2.2 製作YUM倉庫

使用EMOS光盤製作本地 yum倉庫,CentOS系統安裝完成之後在/etc/yum.repos.d/下會生成4個配置文件。其中CentOS-Media.repo是本地YUM源的配置文件,可以在該配置文件中把EMOS光盤的路徑進行添加完成本地YUM源的配置。

2.3 配置MTA-postfix

2.3.1安裝postfix

# yum install postfix

# rpm -e sendmail

2.3.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

# vi /etc/postfix/main.cf(編輯main.cf文件,將文件中標紅的字體替換成自己的域名)

增加如下內容,最後保存退出:

# hostname

mynetworks = 127.0.0.1

myhostname = (mail.extmail.orgàmail.test.com)

mydestination = $mynetworks $myhostname

# banner

mail_name = Postfix - by (extmail.orgàtest.com)

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啓動及開機自啓:

#service postfix restart

#chkconfig postfix on

2.4 配置Courier-Authlib

2.4.1安裝Courier-Authlib

# yum install courier-authlib

# yum install courier-authlib-mysql

2.4.2配置Courier-Authlib

# 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     SELECTusername,password,"",uidnumber,gidnumber,\

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

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

                  quota,                           \                     name                                     \

                FROM mailbox                                \

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

# vi /etc/authlib/authdaemonrc

修改如下內容:

authmodulelist="authmysql"

authmodulelistorig="authmysql"

啓動courier-authlib

# service courier-authlib start

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

Starting Courier authentication services:authdaemond

修改authdaemon socket目錄權限,如果該目錄權限不正確修改,maildroppostfix等將無法正確獲取用戶的信息及密碼認證:

# chmod 755 /var/spool/authdaemon/

2.5 配置Maildrop

2.5.1安裝Maildrop

# yum install maildrop

2.5.2配置Maildrop

配置master.cf 爲了使Postfix支持Maildrop,必須修改/etc/postfix/master.cf文件,註釋掉maildrop中和圖例1結構類似的配置內容,將該語句添加到maildrop配置文件中,注意:flags前面有兩個空格wKiom1Y7C4-wnMf_AABS3xOVjVY322.jpg


配置main.cf,由於maildrop不支持一次接收多個收件人,因此必須在main.cf裏增加如下參數:

maildrop_destination_recipient_limit = 1

2.5.3測試maildrop對authlib支持

# maildrop –v

看是否出現以下內容:

maildrop 2.1.0 Copyright 1998-2005 DoublePrecision, Inc.

GDBM/DB extensions enabled.

Courier Authentication Library extensionenabled.

Maildir quota extension enabled.

This program is distributed under the termsof the GNU General Public

License. See COPYING for additionalinformation.

注意事項:

1、如需重新編譯Maildrop軟件包,必須先獲得其源碼rpm包,並且必須先行安裝courier-authlib及其devel軟件包,否則編譯後的maildrop將無法打開authlib支持。

2maildrop RPM包安裝時,會自動創建vuser用戶及vgroup用戶組,專門用於郵件的存儲,vuser:vgroupuid/gid都是1000,這與一般的郵件文檔中提及用postfix用戶存郵件不一樣。因爲postfix用戶的uid一般都低於500,而Suexec模塊編譯時對UID/GID的要求是要大於500,因此使用postfix用戶不能滿足要求。其次,如果用Maildrop作爲投遞代理(MDA),以postfix身份投遞的話,會導致postfix MTA錯誤。

2.6 配置Apache

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

在最後一行加上:

NameVirtualHost *:80

Include conf/vhost_*.conf

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

裏面定義虛擬主機的相關內容(將文件中標紅的字體替換成自己的域名)

# VirtualHost for ExtMail Solution

<VirtualHost *:80>

ServerName (mail.extmail.orgàmail.test.com)

DocumentRoot/var/www/extsuite/extmail/html/

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

Alias /extmail/var/www/extsuite/extmail/html/

 

ScriptAlias /extman/cgi//var/www/extsuite/extman/cgi/

Alias /extman /var/www/extsuite/extman/html/

 

# Suexec config

SuexecUserGroup vuser vgroup

</VirtualHost>

 

設置apache重啓及開機自啓


#service httpd restart

# chkconfig httpd on

2.7 配置Webmail-ExtMail

2.7.1安裝ExtMail

# yum install extsuite-webmail

2.7.2編輯webmail.cf

# 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的需要,必須將extmailcgi目錄修改成vuser:vgroup權限:

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

2.8 配置管理後臺-ExtMan

2.8.1yum安裝ExtMan

# yum install extsuite-webman

 

更新cgi目錄權限由於SuEXEC的需要,必須將extmancgi目錄修改成vuser:vgroup權限:

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

 

鏈接基本庫到Extmail

# mkdir /tmp/extman

# chown -R vuser:vgroup /tmp/extman

2.8.2數據庫初始化

啓動Mysql且開機自啓動

# service mysqld start

# chkconfig mysqld on

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

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

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

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

注意:由於公網上的文檔資料是以mail.extmail.org爲域名,所以需要將數據庫中的所有extmail.org替換成自己本地的域名(test.com),可以用linux下的Vi編輯器打開數據庫文件,該文件的位置是/var/www/extsuite/extman/docs。然後依次打開init.sqlextmail.sql將所有的extmail.org替換成test.com。如圖例2所示已經替換完成。最後使用update命令將數據庫extmail中的所有表數據記錄均完成extmail.orgtest.com的替換。

wKioL1Y7DNCRODiuAAVhkFN95cM054.jpg

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

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


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

 

# service postfix restart

2.8.4測試authlib

# cd /var/www/extsuite/extman/tools

# ./maildirmake.pl/home/domains/extmail.org/postmaster/Maildir

# chown -R vuser:vgroup/home/domains/extmail.org

 

# /usr/sbin/authtest -s login postmaster@(extmail.org-->test.com) extmail

結果如下:

Authentication succeeded.

     Authenticated: [email protected] (uid 1000, gid 1000)

   Home Directory: /home/domains/test.com/postmaster

          Maildir: /home/domains/test.com/postmaster/Maildir/

            Quota: 104857600S

Encrypted Password:$1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0

Cleartext Password: extmail

          Options: (none)

這樣表明ExtMan的正確安裝,數據庫也正確導入,courier-authlib能正確連接到mysql數據庫

最後訪問http://mail.test.com/extmail/,如無意外,將看到webmail的登陸頁,不過此時還沒有加正式的用戶,所以不能登陸,包括[email protected]也不行。必須要登陸到http://mail.test.com/extman/ 裏增加一個新帳戶才能登陸。

 

ExtMan的默認超級管理員帳戶:[email protected],初始密碼:extmail*123*,登陸成功後,建議將密碼修改,以確保安全。

2.8.5配置圖形化日誌

啓動mailgraph_ext

# /usr/local/mailgraph_ext/mailgraph-initstart

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

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

加入開機自啓動:

# echo"/usr/local/mailgraph_ext/mailgraph-init start" >>/etc/rc.d/rc.local

# echo"/var/www/extsuite/extman/daemon/cmdserver -v -d" >>/etc/rc.d/rc.local

用方法:等待大約15分鐘左右,如果郵件系統有一定的流量,即可登陸到extman裏,點“圖形日誌”即可看到圖形化的日誌。具體每天,周,月,年的則點擊相應的圖片進入即可。


添加定時任務:

# crontab –e

wKiom1Y7DYDR_nnYAAEiprv3Uzk817.jpg

2.9 配置Cyrus-SASL

2.9.1安裝cyrus-sasl

刪除系統的cyrus-sasl

# rpm -e cyrus-sasl –nodeps

安裝新的支持authdaemon的軟件包

# yum install cyrus-sasl

2.9.2配置main.cf文件

PostfixSMTP認證需要透過Cyrus-SASL,連接到authdaemon獲取認證信息。

# 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

2.9.3編輯smtpd.conf文件

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

確保其內容爲:

pwcheck_method: authdaemond

log_level: 3

mech_list: PLAIN LOGIN

authdaemond_path:/var/spool/authdaemon/socket

重新啓動postfix

# service postfix start

2.9.4測試SMTP認證

通過以下命令獲得[email protected]的用戶名及密碼的BASE64編碼:

# perl -e 'use MIME::Base64; print encode_base64("postmaster\@test.com")'

內容如下結構:

cG9zdG1hc3RlckBleHRtYWlsLm9yZw==

# perl -e 'use MIME::Base64; printencode_base64("extmail")'

內容如下結構:

ZXh0bWFpbA==

# telnet localhost 25(需要本機安裝telnet軟件包)

過程如下:

Trying 127.0.0.1...

Connected to localhost.localdomain(127.0.0.1).

Escape character is '^]'.

220 mail.test.com ESMTP Postfix - by test.com

ehlo demo.domain.tld     << 輸入內容

250-mail.test.com

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     << 輸入內容

334 VXNlcm5hbWU6

cG9zdG1hc3RlckBleHRtYWlsLm9yZw==     << 輸入內容(通過per命令獲取的用戶名)

334 UGFzc3dvcmQ6

ZXh0bWFpbA==     << 輸入內容(通過per命令獲取的用戶名密碼)

235 2.0.0 Authentication successful

quit    << 輸入內容

221 2.0.0 Bye

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

2.10 配置Courier-IMAP

2.10.1安裝Courier-imap

默認的courier-authlibcourier-imap都會增加系統自啓動設置,因此下一次服務器啓動將自動啓動相應的authlibPOP3服務

# yum install courier-imap

由於Courier-imapIMAP目錄是按UTF-7編碼的,ExtMail目前還沒有正式支持IMAP目錄,因此需要屏蔽IMAP,只提供pop3服務。

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

修改內容如下:

IMAPDSTART=NO

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

修改內容如下:

IMAPDSSLSTART=NO

然後重新啓動courier-imap

# service courier-imap start

2.10.2測試POP3工作是否正常

測試POP3 請按如下步驟輸入pop3命令測試其是否正常工作,注意藍色的信息是我們輸入到POP3服務器的(請首先登錄extman自行建立[email protected]用戶,密碼:123qaz!)

# telnet localhost 110

其過程如下:

Trying 127.0.0.1...

Connected to localhost.localdomain(127.0.0.1).

Escape character is '^]'.

+OK Hello there.

user [email protected]     << 輸入內容

+OK Password required.

pass 123qaz!     << 輸入內容

+OK logged in.

list    << 輸入內容

+OK POP3 clients that break here, theyviolate STD53.

.

quit    << 輸入內容

+OK Bye-bye.

Connection closed by foreign host.

出現以上內容說明配置正確。

三、注意事項

以上手冊內容的結構體系引自http://wiki.extmail.org/extmail_solution_for_centos-5,但由於官網編寫較粗略,其中個別細節問題需要注意。

  • 2.9.4測試SMTP認證時會出現錯誤,通過查看錯誤信息/var/log/messages,執行#cp -f /usr/lib/sasl2/smtpd.conf /usr/lib64/sasl2/             #/etc/init.d/saslauthd restart完成以上兩步操作之後就可以成功通過SMTP測試。

  • 2.10.2測試POP3工作是否正常之前需要提前在mail.test.com/extman後臺管理端添加用戶,否則會出現錯誤。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章