本文由ilanniweb提供友情贊助,首發於爛泥行天下html
想要得到更多的文章,能夠關注個人微信ilanniwebmysql
Postfix郵件服務器的搭建須要使用到幾個軟件,分別是cyrus-sasl、postfix、dovecot、postfixadmin、roundcubemail,只有這幾個軟件相互配合才能搭建一套完整的郵件服務器。web
PS:本次實驗在centos6.5 64bit上進行。sql
1、軟件功能介紹數據庫
cyrus-sasl、postfix、dovecot、postfixadmin、roundcubemail,這五款軟件,分別有各自的功能。下面就分別一一介紹各自的功能。vim
1.1 cyrus-sasl功能介紹centos
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方式安裝的不是各個軟件的最新版本,因此在下面的介紹中,咱們還會介紹到最新版本的軟件。
2、cyrus-sasl安裝與配置
在本章節會介紹cyrus-sasl的安裝和配置,先來介紹cyrus-sasl的安裝。
2.1 cyrus-sasl安裝
cyrus-sasl的安裝很簡單,使用以下命令:
yum -y install cyrus-sasl
查看版本cyrus-sasl,使用以下命令:
/usr/sbin/saslauthd -v
前面咱們介紹了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=
修改smtpd.conf文件,添加以下代碼:
vim /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
log_level: 3
saslauthd_path:/var/run/saslauthd/mux
2.3 測試cyrus-sasl
cyrus-sasl配置完畢後,咱們來測試其是否正常。建立系統用戶ilanni,並修改其密碼,以下:
useradd ilanni &&echo 'ilannimail'| passwd --stdin ilanni
su - ilanni
mkdir -p ~/mail/.imap/INBOX
用戶建立完畢後,要啓動cyrus-sasl,以下:
/etc/init.d/saslauthd start
chkconfig saslauthd on
如今來使用剛剛建立的用戶進行認證測試,以下:
testsaslauthd -u ilanni -p 'ilannimail'
經過上圖,咱們能夠很明顯的看出cyrus-sasl已經正常啓動,而且咱們的配置也是徹底正確的。
3、postfix安裝與基本配置
在本章節會介紹postfix的安裝和基本配置,先來介紹postfix的安裝。
3.1 postfix安裝
安裝postfix,使用以下命令:
yum -y install postfix
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
注意: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
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
經過上圖,咱們能夠很明顯的看到postfix已經正常啓動,而且監聽的是tcp的25端口。
postfix啓動後,咱們也能夠經過postfix的日誌進行查看。postfix的日誌文件爲/var/log/maillog。以下:
tail -f /var/log/maillog
如今咱們來測試postfix是否能夠發送郵件,以下:
telnet mail.ilanni.com 25
mail from:admin@ilanni.com
rcpt to:xxxx36022@qq.com
data
.
quit
注意:上述命令中mail from:admin@ilanni.com中的admin@ilanni.comn是隨便填寫的,而rcpt to:xxxx36022@qq.com中的郵箱則是確實存在的。
如今咱們再切換到那個QQ郵箱的收件箱,查看是否收到剛剛發送的郵件,以下:
經過上圖,咱們能夠很明顯的看出postfix已經能夠正常發送郵件了。
4、dovecot安裝與基本配置
在本章節會介紹dovecot的安裝和基本配置,先來介紹dovecot的安裝。
4.1 dovecot安裝
安裝dovecot,使用以下命令:
yum -y install dovecot dovecot-devel dovecot-mysql pam-devel
dovecot --version
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
4.2 dovecot基本配置
dovecot安裝完畢後,咱們如今來配置dovecot。dovecot的配置選項也是不少,在此只先介紹基本的功能。
dovecot的配置文件都在/etc/dovecot/目錄下。
vim /etc/dovecot/dovecot.conf
protocols = imap pop3
listen = *
!include conf.d/*.conf
vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = plain login
!include auth-system.conf.ext
禁用ssl認證,以下:
vim /etc/dovecot/conf.d/10-ssl.conf
ssl = no
啓用dovecot的日誌,以下:
vim /etc/dovecot/conf.d/10-logging.conf
如今咱們來啓動dovecot,使用以下命令:
/etc/init.d/dovecot start
chkconfig dovecot on
/etc/init.d/portreserve stop
chkconfig portreserve off
注意:上述命令中的portreserve服務相關的兩行,這個若是啓動的話,你會發現系統重啓後dovecot會沒法啓動,這是由於portreserve佔用了dovecot的端口,因此在此咱們禁用portreserve服務。
4.3 測試dovecot
Dovecot啓動完畢後,咱們如今來測試dovecot,使用以下命令:
telnet mail.ilanni.com 110
telnet mail.ilanni.com 143
出現+Ok Dovecot ready,則表示dovecot配置正確。
下面咱們來測試使用郵件客戶端工具foxmail來鏈接測試,注意這個用戶就是咱們第2.3章節中建立的ilanni用戶,具體過程以下:
注意:在此咱們選擇的服務器類型是POP3類型,而不是IMAP類型。若是選擇IMAP類型的話,會提示權限錯誤。
經過上圖,咱們能夠很明顯的看到系統用戶ilanni,已經正確鏈接到郵件服務器,這也說明了dovecot配置成功了。