CentOS郵箱服務(wù)器搭建系列——SMTP服務(wù)器的構(gòu)建( Postfix )
前言
在CentOS中,默認(rèn)的郵件服務(wù)器(SMTP方面)是sendmail,但sendmail有若干的缺點(diǎn),比如,配置復(fù)雜、安全漏洞曾被多次發(fā)現(xiàn)--并且依然存在隱患、郵件發(fā)送速度慢等等,這里就不再一一敘述。而另一個(gè)被廣泛應(yīng)用于郵件服務(wù)方面的“Postfix”的缺點(diǎn)就少得多,或者說(shuō)它就是針對(duì)于sendmail的缺點(diǎn),而被設(shè)計(jì)的。對(duì)應(yīng)sendmail的短處,它在各方面也比較成熟。所以,無(wú)特殊要求,這里不推薦用sendmail來(lái)構(gòu)建郵件服務(wù)器。本站介紹的郵件服務(wù)器配置方法,也將基于Postfix。
添加MX記錄(這里假設(shè)使用動(dòng)態(tài)域名)
由于MX記錄添加后,可能生效要等待一段時(shí)間(通常為數(shù)分鐘或數(shù)十分鐘,也可能馬上生效),所以在安裝配置前,我們首先為動(dòng)態(tài)域名添加MX記錄。添加方法也會(huì)因域名ISP的不同而不同,但大致信息如下:
mx mail.centospub.com. 10a mail 服務(wù)器的IP地址
mail為別名,10為優(yōu)先度。這個(gè)別名指向服務(wù)器的IP地址。(如有疑問(wèn)或需要幫忙請(qǐng)到 技術(shù)論壇 發(fā)貼。)
確認(rèn)MX記錄的添加是否生效的方法:
[root@sample ~]# host -t mx centospub.com
centospub.com mail is handled by 10 mail.centospub.com. ← 確認(rèn)MX記錄生效
安裝Postfix
然后,安裝Postfix。
[root@sample ~]# yum -y install postfix ← 在線(xiàn)安裝Postfix
Setting up Install ProcessSetting up repositoriesdag 100% |=========================| 1.1 kB 00:00update 100% |=========================| 951 B 00:00base 100% |=========================| 1.1 kB 00:00addons 100% |=========================| 951 B 00:00extras 100% |=========================| 1.1 kB 00:00Reading repository metadata in from local filesprimary.xml.gz 100% |=========================| 28 kB 00:04update : ################################################## 84/84Added 84 new packages, deleted 1499 old in 3.44 secondsprimary.xml.gz 100% |=========================| 157 B 00:00Added 0 new packages, deleted 1499 old in 1.97 secondsprimary.xml.gz 100% |=========================| 26 kB 00:00extras : ################################################## 102/102Added 102 new packages, deleted 1499 old in 2.73 secondsReducing Dag RPM Repository for Red Hat Enterprise Linux to included packages onlyFinishedParsing package install argumentsResolving Dependencies--> Populating transaction set with selected packages. Please wait.---> Downloading header for postfix to pack into transaction set.postfix-2.2.10-1.RHEL4.2. 100% |=========================| 40 kB 00:00---> Package postfix.i386 2:2.2.10-1.RHEL4.2 set to be updated--> Running transaction checkDependencies Resolved
=============================================================================Package Arch Version Repository Size=============================================================================Installing:postfix i386 2:2.2.10-1.RHEL4.2 base 3.0 M
Transaction Summary=============================================================================Install 1 Package(s)Update 0 Package(s)Remove 0 Package(s)Total download size: 3.0 MDownloading Packages:(1/1): postfix-2.2.10-1.R 100% |=========================| 3.0 MB 00:05Running Transaction TestFinished Transaction TestTransaction Test SucceededRunning TransactionInstalling: postfix ######################### [1/1]
Installed: postfix.i386 2:2.2.10-1.RHEL4.2Complete!
配置Postfix及相關(guān)組件
[1] 對(duì)Postfix進(jìn)行配置。
[root@sample ~]# vi /etc/postfix/main.cf ← 編輯Postfix的配置文件
#myhostname = host.domain.tld ← 找到此行,將等號(hào)后面的部分改寫(xiě)為主機(jī)名↓myhostname = sample.centospub.com ← 變?yōu)榇藸顟B(tài),設(shè)置系統(tǒng)的主機(jī)名
#mydomain = domain.tld ← 找到此行,將等號(hào)后面的部分改寫(xiě)為域名↓mydomain = centospub.com ← 變?yōu)榇藸顟B(tài),設(shè)置域名(我們將讓此處設(shè)置將成為E-mail地址“@”后面的部分)
#myorigin = $mydomain ← 找到此行,將行首的#去掉↓myorigin = $mydomain ← 變?yōu)榇藸顟B(tài),將發(fā)信地址“@”后面的部分設(shè)置為域名(非系統(tǒng)主機(jī)名)
inet_interfaces = localhost ← 找到此行,將“l(fā)ocalhost”改為“all”↓inet_interfaces = all ← 變?yōu)榇藸顟B(tài),接受來(lái)自所有網(wǎng)絡(luò)的請(qǐng)求
mydestination = $myhostname, localhost.$mydomain, localhost ← 找到此行,在行為添加“$mydomain”↓mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ← 變?yōu)榇藸顟B(tài),指定發(fā)給本地郵件的域名
#relay_domains = $mydestination ← 找到此行,將行首的#去掉↓relay_domains = $mydestination ← 變?yōu)榇藸顟B(tài),定義允許轉(zhuǎn)發(fā)的域名
#mynetworks = 168.100.189.0/28, 127.0.0.0/8 ← 找到此行,依照自己的內(nèi)網(wǎng)情況修改↓mynetworks = 168.100.189.0/28, 127.0.0.0/8 ← 變?yōu)榇藸顟B(tài),指定內(nèi)網(wǎng)和本地的IP地址范圍
#home_mailbox = Maildir/ ← 找到這一行,去掉行首的#↓home_mailbox = Maildir/ ← 變?yōu)榇藸顟B(tài),指定用戶(hù)郵箱目錄
# SHOW SOFTWARE VERSION OR NOT## The smtpd_banner parameter specifies the text that follows the 220# code in the SMTP server’s greeting banner. Some people like to see# the mail version advertised. By default, Postfix shows no version.## You MUST specify $myhostname at the start of the text. That is an# RFC requirement. Postfix itself does not care.##smtpd_banner = $myhostname ESMTP $mail_name#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version) ← 找到這一行,接此行添加如下行:smtpd_banner = $myhostname ESMTP unknow ← 添加這一行,不顯示SMTP服務(wù)器的相關(guān)信息
在配置文件的文尾,添加如下行:
smtpd_sasl_auth_enable = yes ← 服務(wù)器使用SMTP認(rèn)證smtpd_sasl_local_domain = $myhostname ← 指定SMTP認(rèn)證的本地域名(主機(jī)名)smtpd_sasl_security_options = noanonymous ← 不允許匿名的方式認(rèn)證smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destinationmessage_size_limit = 15728640 ← 規(guī)定郵件最大尺寸為15MB
[2] 配置SMTP認(rèn)證的相關(guān)選項(xiàng)
為了提高安全性,我們不將系統(tǒng)用戶(hù)的密碼作為相應(yīng)用戶(hù)SMTP認(rèn)證的密碼,而將在后面為用戶(hù)建立SMTP認(rèn)證專(zhuān)用的密碼。
[root@sample ~]# vi /usr/lib/sasl2/smtpd.conf ← 編輯SMTP認(rèn)證的配置文件
pwcheck_method: saslauthd ← 找到此行,將“saslauthd”改為“auxprop”↓pwcheck_method: auxprop ← 不使用系統(tǒng)用戶(hù)密碼作為用戶(hù)的SMTP認(rèn)證密碼
[root@sample ~]# vi /etc/sysconfig/saslauthd
MECH=shadow ← 找到這一行,在前面加#↓#MECH=shadow ← 不使用shadow機(jī)制
FLAGS= ← 找到此行,在等號(hào)后面添加“sasldb”↓FLAGS=sasldb ← 定義認(rèn)證方式為sasldb2
[3] 建立用戶(hù)的郵箱目錄
首先建立用戶(hù)模板下的郵箱目錄,以便于建立新用戶(hù)時(shí),相應(yīng)用戶(hù)的郵箱目錄自動(dòng)被建立。
[root@sample ~]# mkdir /etc/skel/Maildir ← 在用戶(hù)模板下建立用戶(hù)郵箱目錄
[root@sample ~]# chmod 700 /etc/skel/Maildir ← 設(shè)置用戶(hù)郵箱目錄屬性為700
然后再為已經(jīng)存在的用戶(hù)建立相應(yīng)郵箱目錄。
[root@sample ~]# mkdir /home/centospub/Maildir ← 為用戶(hù)(這里以centospub用戶(hù)為例)建立郵箱目錄
[root@sample ~]# chmod 700 /home/centospub/Maildir ← 設(shè)置該用戶(hù)郵箱目錄屬性為700
[root@sample ~]# chown centospub. /home/centospub/Maildir ← 設(shè)置該用戶(hù)郵箱目錄為該用戶(hù)所有
[4] 為用戶(hù)設(shè)置SMTP認(rèn)證密碼
[root@sample ~]# saslpasswd2 -u sample.centospub.com -c centospub ← 為centospub用戶(hù)設(shè)置SMTP認(rèn)證密碼
Password: ← 在這里輸入密碼(不會(huì)顯示)Again (for verification): ← 再次輸入密碼
[5] 改變SALS的屬性及歸屬
[root@sample ~]# chgrp postfix /etc/sasldb2 ← 將數(shù)據(jù)庫(kù)歸屬改為postfix,
[root@sample ~]# chmod 640 /etc/sasldb2 ← 將數(shù)據(jù)庫(kù)屬性改為640
[6] 關(guān)閉sendmail服務(wù)及設(shè)置默認(rèn)MTA
因?yàn)樵谟肞ostfix作為SMTP服務(wù)器的前提下,我們不準(zhǔn)備再用sendmail,所以將sendmail服務(wù)關(guān)掉,以確保安全及節(jié)省系統(tǒng)資源。
[root@sample ~]# /etc/rc.d/init.d/sendmail stop ← 關(guān)閉sendmail服務(wù)
Shutting down sendmail: [ OK ]Shutting down sm-client: [ OK ]
[root@sample ~]# chkconfig sendmail off ← 關(guān)閉sendmail自啟動(dòng)
[root@sample ~]# chkconfig --list sendmail ← 確認(rèn)sendmail自啟動(dòng)已被關(guān)閉(都為off就OK)sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
然后再將默認(rèn)的MTA設(shè)置為Postfix。
[root@sample ~]# alternatives --config mta ← 設(shè)置默認(rèn)MTAThere are 2 programs which provide ’mta’.
Selection Command-----------------------------------------------*+ 1 /usr/sbin/sendmail.sendmail ← 當(dāng)前狀態(tài):sendmail為默認(rèn)MTA2 /usr/sbin/sendmail.postfix
Enter to keep the current selection[+], or type selection number: 2 ← 在這里輸入2,使Postfix成為默認(rèn)MTA
啟動(dòng)相應(yīng)服務(wù)
最后,啟動(dòng)SMTP認(rèn)證及Postfix服務(wù),并設(shè)置相應(yīng)服務(wù)為自啟動(dòng)。
[root@sample ~]# chkconfig saslauthd on ← 將SMTP-Auth設(shè)置為自啟動(dòng)
[root@sample ~]# chkconfig --list saslauthd ← 確認(rèn)SMTP-Auth服務(wù)狀態(tài)saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 確認(rèn)2~5為on的狀態(tài)就OK
[root@sample ~]# /etc/rc.d/init.d/saslauthd start ← 啟動(dòng)SMTP-Auth
Starting saslauthd: [ OK ]
[root@sample ~]# chkconfig postfix on ← 將Postfix設(shè)置為自啟動(dòng)
[root@sample ~]# chkconfig --list postfix ← 確認(rèn)Postfix服務(wù)狀態(tài)postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 確認(rèn)2~5為on的狀態(tài)就OK
[root@sample ~]# /etc/rc.d/init.d/postfix start ← 啟動(dòng)Postfix
Starting postfix: [ OK ]
至此,就完成了SMTP服務(wù)器方面的配置,但目前只具從備客戶(hù)端通過(guò)服務(wù)器發(fā)送郵件的功能。做為完整的郵件服務(wù)器,還需具備從客戶(hù)端通過(guò)POP/IMAP協(xié)議接受郵件到本地的功能。POP/IMAP服務(wù)器的構(gòu)建請(qǐng)參見(jiàn)下一節(jié) < POP / IMAP 服務(wù)器的構(gòu)建( Dovecot ) >。
相關(guān)文章:
1. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)2. CSS可以做的幾個(gè)令你嘆為觀(guān)止的實(shí)例分享3. PHP session反序列化漏洞超詳細(xì)講解4. ASP基礎(chǔ)入門(mén)第二篇(ASP基礎(chǔ)知識(shí))5. ASP基礎(chǔ)知識(shí)Command對(duì)象講解6. Spring注入Date類(lèi)型的三種方法總結(jié)7. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享8. Xml簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理9. 解析原生JS getComputedStyle10. ASP實(shí)現(xiàn)加法驗(yàn)證碼
