爛泥:Postfix郵件伺服器搭建之軟體安裝與配置

來源:互聯網
上載者:User

標籤:郵件伺服器   微軟雅黑   blank   target   color   

本文由ilanniweb提供友情贊助,首發於爛泥行天下

想要獲得更多的文章,可以關注我的ilanniweb

Postfix郵件伺服器的搭建需要使用到幾個軟體,分別是cyrus-sasl、postfix、dovecot、postfixadmin、roundcubemail,只有這幾個軟體相互配合才能搭建一套完整的郵件伺服器。

PS:本次實驗在centos6.5 64bit上進行。

一、軟體功能介紹

cyrus-sasl、postfix、dovecot、postfixadmin、roundcubemail,這五款軟體,分別有各自的功能。下面就分別一一介紹各自的功能。

1.1 cyrus-sasl功能介紹

cyrus-sasl(Simple Authentication Security Layer)簡單認證安全層, SASL主要是用於SMTP認證。而cyrus-sasl在OS裡面,saslauthd是其守護進程。

1.2 postfix功能介紹

postfix是一個電子郵件伺服器,它為了改良sendmail郵件伺服器而產生的,並且它的設定檔比sendmail簡單得多,配置相當容易。

postfix作為發送郵件伺服器。

1.3 dovecot功能介紹

dovecot是一個開源的IMAP和POP3郵件伺服器,支援Linux/Unix系統。

POP/IMAP是MUA從郵件伺服器中讀取郵件時使用的協議。其中,與POP3是從郵件伺服器中下載郵件存起來,IMAP則是將郵件留在伺服器端直接對郵件進行管理、操作。

dovecot可以被其他具有相同功能的軟體替代,比如:cyrus-imapd。

dovecot作為內送郵件伺服器。

1.4 postfixadmin功能介紹

postfixadmin是一個基於web的postfix郵件發送伺服器的管理工具,可以直接管理postfix的虛擬網域名稱和郵件使用者,前提是這些資料是儲存在mysql或者是PostgreSQL資料庫中。

postfix的郵件使用者和虛擬網域名稱的管理都是通過postfixadmin來進行的。

1.5 roundcubemail功能介紹

roundcubemail是一個基於瀏覽器,支援多國語言的IMAP用戶端,它的操作介面看起像一個傳統型應用程式。它提供一個email用戶端應該具備的所有功能,包括MIME支援,地址薄,檔案夾操作,資訊搜尋和拼字檢查等。

roundcubemail採用PHP+Ajax開發並且需要MySQL資料庫來儲存資料。 使用者介面採用XHTML+CSS2設計。

roundcubemail可以被其他具有相同功能的軟體替代,比如:openwebmail、squireelmail。

roundcubemail作為web端的郵件用戶端。

這幾個軟體中除了postfixadmin是通過單獨下載安裝的,其他的幾個軟體都是直接使用yum方式進行安裝。但是yum方式安裝的不是各個軟體的最新版本,所以在下面的介紹中,我們還會介紹到最新版本的軟體。

二、cyrus-sasl安裝與配置

在本章節會介紹cyrus-sasl的安裝和配置,先來介紹cyrus-sasl的安裝。

2.1 cyrus-sasl安裝

cyrus-sasl的安裝很簡單,使用如下命令:

yum -y install cyrus-sasl

650) this.width=650;" title="clip_image001" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image001" src="http://s3.51cto.com/wyfs02/M02/7D/AB/wKiom1bsw8eTEP04AAAsLRWOjHg750.png" width="566" height="103" />

查看版本cyrus-sasl,使用如下命令:

/usr/sbin/saslauthd -v

650) this.width=650;" title="clip_image002" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image002" src="http://s3.51cto.com/wyfs02/M02/7D/A8/wKioL1bsxFnxIKdzAAAkyAXoHQs405.png" width="475" height="89" />

前面我們介紹了saslauthd是認證服務cyrus-sasl的守護進程,所以我們就可以通過saslauthd查看cyrus-sasl的版本。

2.2 cyrus-sasl配置

cyrus-sasl安裝完畢後,我們現在來配置cyrus-sasl。

修改saslauthd檔案把MECH的值修改為shadow,如下:

vim /etc/sysconfig/saslauthd

SOCKETDIR=/var/run/saslauthd

MECH=shadow

FLAGS=

650) this.width=650;" title="clip_image003" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image003" src="http://s3.51cto.com/wyfs02/M00/7D/A8/wKioL1bsxFmzH0FoAAA9x6zs1d8812.png" width="378" height="193" />

修改smtpd.conf檔案,添加如下代碼:

vim /etc/sasl2/smtpd.conf

pwcheck_method: saslauthd

mech_list: plain login

log_level: 3

saslauthd_path:/var/run/saslauthd/mux

650) this.width=650;" title="clip_image004" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image004" src="http://s3.51cto.com/wyfs02/M02/7D/A8/wKioL1bsxFnCmpqZAAAq__I9IGo997.png" width="417" height="119" />

2.3 測試cyrus-sasl

cyrus-sasl配置完畢後,我們來測試其是否正常。建立系統使用者ilanni,並修改其密碼,如下:

useradd ilanni &&echo ‘ilannimail‘| passwd --stdin ilanni

su - ilanni

mkdir -p ~/mail/.imap/INBOX

650) this.width=650;" title="clip_image005" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image005" src="http://s3.51cto.com/wyfs02/M00/7D/AB/wKiom1bsw8njRH8yAABDToEKr74224.png" width="569" height="168" />

使用者建立完畢後,要啟動cyrus-sasl,如下:

/etc/init.d/saslauthd start

chkconfig saslauthd on

650) this.width=650;" title="clip_image006" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image006" src="http://s3.51cto.com/wyfs02/M01/7D/AB/wKiom1bsw8mAc1ojAAAmCKAyHQU563.png" width="500" height="93" />

現在來使用剛剛建立的使用者進行認證測試,如下:

testsaslauthd -u ilanni -p ‘ilannimail‘

650) this.width=650;" title="clip_image007" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image007" src="http://s3.51cto.com/wyfs02/M02/7D/AB/wKiom1bsw8mRPDcTAAAdNP_4qH8811.png" width="510" height="79" />

通過,我們可以很明顯的看出cyrus-sasl已經正常啟動,並且我們的配置也是完全正確的。

三、postfix安裝與基本配置

在本章節會介紹postfix的安裝和基本配置,先來介紹postfix的安裝。

3.1 postfix安裝

安裝postfix,使用如下命令:

yum -y install postfix

650) this.width=650;" title="clip_image008" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image008" src="http://s3.51cto.com/wyfs02/M02/7D/AB/wKiom1bsw8rxxPQkAAAsWpUt2l0859.png" width="548" height="102" />

Centos6.5預設安裝的是postfix2.6.6版本,所以以下的所有配置都是在postfix2.6.6版本上進行的。

如果你想使用稍微新版本的話,可以通過如下的方式進行安裝,如下:

wget -P /etc/yum.repos.d https://repos.fedorapeople.org/repos/mstevens/postfix/epel-postfix.repo

yum -y install postfix

postconf -d | grep mail_version

650) this.width=650;" title="clip_image009" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image009" src="http://s3.51cto.com/wyfs02/M02/7D/A8/wKioL1bsxFuza0EiAACBdxPtZgI929.png" width="845" height="325" />

注意:postconf是檢查posftix配置的命令。

如果想安裝最新版本的postfix的話,我們也可以通過如下串連下載安裝,如下:

wget http://repos.oostergo.net/6/postfix-3.1/postfix-3.1.0-1.el6.x86_64.rpm

rpm -ivh postfix-3.1.0-1.el6.x86_64.rpm

postconf -d | grep mail_version

650) this.width=650;" title="clip_image010" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image010" src="http://s3.51cto.com/wyfs02/M00/7D/AB/wKiom1bsw8vwndzaAACAPbwyqSo959.png" width="700" height="313" />

Posftxi安裝完畢後,我們現在來開始postfix的基本配置。

3.2 postfix基本配置

為什麼說是postfix的基本配置呢?因為postfix的配置選項特別多,其他的功能我們在下一篇文章中進行介紹,在此只先介紹基本的發送郵件配置。

postfix的設定檔是main.cf,main.cf檔案配置選項很多,下面我們就給出最常使用的配置,紅色部分是要根據自己的實際情況修改的,如下:

vim /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 = mail.ilanni.com

mydomain = ilanni.com

myorigin = $mydomain

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost

local_recipient_maps =

unknown_local_recipient_reject_code = 550

alias_maps = hash:/etc/aliases

alias_database = 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

sendmail_path = /usr/sbin/sendmail.postfix

newaliases_path = /usr/bin/newaliases.postfix

mailq_path = /usr/bin/mailq.postfix

setgid_group = postdrop

html_directory = no

manpage_directory = /usr/share/man

sample_directory = /usr/share/doc/postfix-2.6.6/samples

readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES

3.3 測試postfix配置

postfix配置完畢後,我們需要測試postfix是否可以正常發送郵件。

現在來啟動postfix,使用如下命令:

/etc/init.d/postfix start

chkconfig postfix on

netstat -tunlp

ps -ef |grep postfix

650) this.width=650;" title="clip_image011" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image011" src="http://s3.51cto.com/wyfs02/M01/7D/AB/wKiom1bsw8vw4a04AABojPC2na4125.png" width="711" height="267" />

通過,我們可以很明顯的看到postfix已經正常啟動,並且監聽的是tcp的25連接埠。

postfix啟動後,我們也可以通過postfix的日誌進行查看。postfix的記錄檔為/var/log/maillog。如下:

tail -f /var/log/maillog

650) this.width=650;" title="clip_image012" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image012" src="http://s3.51cto.com/wyfs02/M02/7D/AB/wKiom1bsw8uBf-mHAAAudQEJtaQ570.png" width="803" height="76" />

現在我們來測試postfix是否可以發送郵件,如下:

telnet mail.ilanni.com 25

mail from:[email protected]

rcpt to:[email protected]

data

.

quit

650) this.width=650;" title="clip_image013" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image013" src="http://s3.51cto.com/wyfs02/M00/7D/A8/wKioL1bsxF2jT7kHAABFL1GRJX4060.png" width="355" height="266" />

注意:上述命令中mail from:[email protected]中的[email protected]是隨便填寫的,而rcpt to:[email protected]中的郵箱則是確實存在的。

現在我們再切換到那個QQ郵箱的收件匣,查看是否收到剛剛發送的郵件,如下:

650) this.width=650;" title="clip_image014" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image014" src="http://s3.51cto.com/wyfs02/M00/7D/AB/wKiom1bsw8zCJQfAAACI1FNk2Lc732.png" width="350" height="246" />

通過,我們可以很明顯的看出postfix已經可以正常發送郵件了。

四、dovecot安裝與基本配置

在本章節會介紹dovecot的安裝和基本配置,先來介紹dovecot的安裝。

4.1 dovecot安裝

安裝dovecot,使用如下命令:

yum -y install dovecot dovecot-devel dovecot-mysql pam-devel

dovecot --version

650) this.width=650;" title="clip_image015" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image015" src="http://s3.51cto.com/wyfs02/M01/7D/A8/wKioL1bsxF6haOgXAABLoDGOlks413.png" width="596" height="168" />

Centos6.5安裝的dovecot版本為2.0.9,如有要安裝最新版的話,我們可以通過如下命令。

wget -P /etc/yum.repos.d/ http://repos.fedorapeople.org/repos/mstevens/dovecot/epel-dovecot.repo

yum -y install dovecot dovecot-devel dovecot-mysql pam-devel

dovecot --version

650) this.width=650;" title="clip_image016" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image016" src="http://s3.51cto.com/wyfs02/M01/7D/A8/wKioL1bsxF_QMttTAACmNPHv-q8535.png" width="847" height="406" />

4.2 dovecot基本配置

dovecot安裝完畢後,我們現在來配置dovecot。dovecot的配置選項也是很多,在此只先介紹基本的功能。

dovecot的設定檔都在/etc/dovecot/目錄下。

vim /etc/dovecot/dovecot.conf

protocols = imap pop3

listen = *

!include conf.d/*.conf

650) this.width=650;" title="clip_image017" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image017" src="http://s3.51cto.com/wyfs02/M02/7D/A8/wKioL1bsxF_w2PxLAAAijEiF_Ak776.png" width="403" height="109" />

vim /etc/dovecot/conf.d/10-auth.conf

disable_plaintext_auth = no

auth_mechanisms = plain login

!include auth-system.conf.ext

650) this.width=650;" title="clip_image018" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image018" src="http://s3.51cto.com/wyfs02/M00/7D/A8/wKioL1bsxF_gpX7CAAAk3rfreCk636.png" width="478" height="94" />

禁用ssl認證,如下:

vim /etc/dovecot/conf.d/10-ssl.conf

ssl = no

650) this.width=650;" title="clip_image019" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image019" src="http://s3.51cto.com/wyfs02/M01/7D/A8/wKioL1bsxGDz_TsGAAAcX44laJw010.png" width="454" height="84" />

啟用dovecot的日誌,如下:

vim /etc/dovecot/conf.d/10-logging.conf

650) this.width=650;" title="clip_image020" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image020" src="http://s3.51cto.com/wyfs02/M02/7D/AB/wKiom1bsw8-wNpy5AAAlsYF2scs997.png" width="481" height="111" />

現在我們來啟動dovecot,使用如下命令:

/etc/init.d/dovecot start

chkconfig dovecot on

/etc/init.d/portreserve stop

chkconfig portreserve off

650) this.width=650;" title="clip_image021" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image021" src="http://s3.51cto.com/wyfs02/M00/7D/AB/wKiom1bsw9Cgxa_VAAA0c0ukHtE861.png" width="528" height="117" />

注意:上述命令中的portreserve服務相關的兩行,這個如果啟動的話,你會發現系統重啟後dovecot會無法啟動,這是因為portreserve佔用了dovecot的連接埠,所以在此我們禁用portreserve服務。

4.3 測試dovecot

Dovecot啟動完畢後,我們現在來測試dovecot,使用如下命令:

telnet mail.ilanni.com 110

telnet mail.ilanni.com 143

出現+Ok Dovecot ready,則表示dovecot配置正確。

650) this.width=650;" title="clip_image022" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image022" src="http://s3.51cto.com/wyfs02/M00/7D/AB/wKiom1bsw9DC9SQvAAA6zPaJQXs041.png" width="470" height="214" />

下面我們來測試使用郵件用戶端工具foxmail來串連測試,注意這個使用者就是我們第2.3章節中建立的ilanni使用者,具體過程如下:

650) this.width=650;" title="clip_image023" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image023" src="http://s3.51cto.com/wyfs02/M00/7D/A8/wKioL1bsxGGxq2yrAAAxJnjWUpg002.png" width="471" height="372" />

650) this.width=650;" title="clip_image024" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image024" src="http://s3.51cto.com/wyfs02/M01/7D/AB/wKiom1bsw9GQbSX5AABTbPk9mfo616.png" width="490" height="377" />

注意:在此我們選擇的伺服器類型是POP3類型,而不是IMAP類型。如果選擇IMAP類型的話,會提示許可權錯誤。

650) this.width=650;" title="clip_image025" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image025" src="http://s3.51cto.com/wyfs02/M02/7D/AB/wKiom1bsw9HBwq3hAABKywYoBVk551.png" width="265" height="316" />

通過,我們可以很明顯的看到系統使用者ilanni,已經正確串連到郵件伺服器,這也說明了dovecot配置成功了。

爛泥:Postfix郵件伺服器搭建之軟體安裝與配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.