WIKI使用導(dǎo)航
站長百科導(dǎo)航
站長專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機
- cPanel
- 網(wǎng)址導(dǎo)航專題
- 云計算
- 微博營銷
- 虛擬主機管理系統(tǒng)
- 開放平臺
- WIKI程序與應(yīng)用
- 美國十大主機
CentOS/SMTP服務(wù)器的構(gòu)建:修訂間差異
? |
|||
第126行: | 第126行: | ||
smtpd_sasl_local_domain = $myhostname ← 指定SMTP認證的本地域名(主機名) | smtpd_sasl_local_domain = $myhostname ← 指定SMTP認證的本地域名(主機名) | ||
smtpd_sasl_security_options = noanonymous ← 不允許匿名的方式認證 | smtpd_sasl_security_options = noanonymous ← 不允許匿名的方式認證 | ||
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination ? | smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, ? | ||
reject_unauth_destination ? | |||
message_size_limit = 15728640 ← 規(guī)定郵件最大尺寸為15MB</pre> | message_size_limit = 15728640 ← 規(guī)定郵件最大尺寸為15MB</pre> | ||
第188行: | 第189行: | ||
2 /usr/sbin/sendmail.postfix | 2 /usr/sbin/sendmail.postfix | ||
Enter to keep the current selection[+], or type selection number: 2 ← | Enter to keep the current selection[+], or type selection number: 2 ← 在這里輸入2, | ||
使Postfix成為默認MTA</pre> | |||
==啟動相應(yīng)服務(wù)== | ==啟動相應(yīng)服務(wù)== |
2011年2月1日 (二) 16:48的最新版本
CentOS | CentOS安裝 | CentOS使用手冊 |
在CentOS中,默認的郵件服務(wù)器(SMTP方面)是sendmail,但sendmail有若干的缺點,比如,配置復(fù)雜、安全漏洞曾被多次發(fā)現(xiàn)--并且依然存在隱患、郵件發(fā)送速度慢等等,這里就不再一一敘述。
而另一個被廣泛應(yīng)用于郵件服務(wù)方面的“Postfix”的缺點就少得多,或者說它就是針對于sendmail的缺點,而被設(shè)計的。對應(yīng)sendmail的短處,它在各方面也比較成熟。所以,無特殊要求,這里不推薦用sendmail來構(gòu)建郵件服務(wù)器。本條目介紹的郵件服務(wù)器配置方法,也將基于Postfix。
添加MX記錄[ ]
這里假設(shè)使用動態(tài)域名。
由于MX記錄添加后,可能生效要等待一段時間(通常為數(shù)分鐘或數(shù)十分鐘,也可能馬上生效),所以在安裝配置前,我們首先為動態(tài)域名添加MX記錄。添加方法也會因域名ISP的不同而不同,但大致信息如下: mx mail.centospub.com. 10 a mail 服務(wù)器的IP地址 mail為別名,10為優(yōu)先度。這個別名指向服務(wù)器的IP地址。
確認MX記錄的添加是否生效的方法:
[root@sample ~]# host -t mx centospub.com centospub.com mail is handled by 10 mail.centospub.com. ← 確認MX記錄生效
安裝Postfix[ ]
[root@sample ~]# yum -y install postfix ← 在線安裝Postfix Setting up Install Process Setting up repositories dag 100% |=========================| 1.1 kB 00:00 update 100% |=========================| 951 B 00:00 base 100% |=========================| 1.1 kB 00:00 addons 100% |=========================| 951 B 00:00 extras 100% |=========================| 1.1 kB 00:00 Reading repository metadata in from local files primary.xml.gz 100% |=========================| 28 kB 00:04 update : ################################################## 84/84 Added 84 new packages, deleted 1499 old in 3.44 seconds primary.xml.gz 100% |=========================| 157 B 00:00 Added 0 new packages, deleted 1499 old in 1.97 seconds primary.xml.gz 100% |=========================| 26 kB 00:00 extras : ################################################## 102/102 Added 102 new packages, deleted 1499 old in 2.73 seconds Reducing Dag RPM Repository for Red Hat Enterprise Linux to included packages only Finished Parsing package install arguments Resolving 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 check Dependencies 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 M Downloading Packages: (1/1): postfix-2.2.10-1.R 100% |=========================| 3.0 MB 00:05 Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing: postfix ######################### [1/1] Installed: postfix.i386 2:2.2.10-1.RHEL4.2 Complete!
配置Postfix及相關(guān)組件[ ]
[1] 對Postfix進行配置。
[root@sample ~]# vi /etc/postfix/main.cf ← 編輯Postfix的配置文件 #myhostname = host.domain.tld ← 找到此行,將等號后面的部分改寫為主機名 ↓ myhostname = sample.centospub.com ← 變?yōu)榇藸顟B(tài),設(shè)置系統(tǒng)的主機名 #mydomain = domain.tld ← 找到此行,將等號后面的部分改寫為域名 ↓ 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)主機名) inet_interfaces = localhost ← 找到此行,將“l(fā)ocalhost”改為“all” ↓ inet_interfaces = all ← 變?yōu)榇藸顟B(tài),接受來自所有網(wǎng)絡(luò)的請求 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),指定用戶郵箱目錄 # 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認證 smtpd_sasl_local_domain = $myhostname ← 指定SMTP認證的本地域名(主機名) smtpd_sasl_security_options = noanonymous ← 不允許匿名的方式認證 smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination message_size_limit = 15728640 ← 規(guī)定郵件最大尺寸為15MB
[2] 配置SMTP認證的相關(guān)選項,為了提高安全性,我們不將系統(tǒng)用戶的密碼作為相應(yīng)用戶SMTP認證的密碼, 而將在后面為用戶建立SMTP認證專用的密碼。
[root@sample ~]# vi /usr/lib/sasl2/smtpd.conf ← 編輯SMTP認證的配置文件 pwcheck_method: saslauthd ← 找到此行,將“saslauthd”改為“auxprop” ↓ pwcheck_method: auxprop ← 不使用系統(tǒng)用戶密碼作為用戶的SMTP認證密碼 [root@sample ~]# vi /etc/sysconfig/saslauthd MECH=shadow ← 找到這一行,在前面加# ↓ #MECH=shadow ← 不使用shadow機制 FLAGS= ← 找到此行,在等號后面添加“sasldb” ↓ FLAGS=sasldb ← 定義認證方式為sasldb2
[3] 建立用戶的郵箱目錄,首先建立用戶模板下的郵箱目錄,以便于建立新用戶時,相應(yīng)用戶的郵箱目錄自動被建立。
[root@sample ~]# mkdir /etc/skel/Maildir ← 在用戶模板下建立用戶郵箱目錄 [root@sample ~]# chmod 700 /etc/skel/Maildir ← 設(shè)置用戶郵箱目錄屬性為700
然后再為已經(jīng)存在的用戶建立相應(yīng)郵箱目錄。
[root@sample ~]# mkdir /home/centospub/Maildir ← 為用戶(這里以centospub用戶為例)建立郵箱目錄 [root@sample ~]# chmod 700 /home/centospub/Maildir ← 設(shè)置該用戶郵箱目錄屬性為700 [root@sample ~]# chown centospub. /home/centospub/Maildir ← 設(shè)置該用戶郵箱目錄為該用戶所有
[4] 為用戶設(shè)置SMTP認證密碼
root@sample ~]# saslpasswd2 -u sample.centospub.com -c centospub ← 為centospub用戶設(shè)置SMTP認證密碼 Password: ← 在這里輸入密碼(不會顯示) Again (for verification): ← 再次輸入密碼
[5] 改變SALS的屬性及歸屬
[root@sample ~]# chgrp postfix /etc/sasldb2 ← 將數(shù)據(jù)庫歸屬改為postfix, [root@sample ~]# chmod 640 /etc/sasldb2 ← 將數(shù)據(jù)庫屬性改為640
[6] 關(guān)閉sendmail服務(wù)及設(shè)置默認MTA,因為在用Postfix作為SMTP服務(wù)器的前提下,我們不準備再用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自啟動 [root@sample ~]# chkconfig --list sendmail ← 確認sendmail自啟動已被關(guān)閉(都為off就OK) sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
然后再將默認的MTA設(shè)置為Postfix。
[root@sample ~]# alternatives --config mta ← 設(shè)置默認MTA There are 2 programs which provide 'mta'. Selection Command ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail ← 當(dāng)前狀態(tài):sendmail為默認MTA 2 /usr/sbin/sendmail.postfix Enter to keep the current selection[+], or type selection number: 2 ← 在這里輸入2, 使Postfix成為默認MTA
啟動相應(yīng)服務(wù)[ ]
最后,啟動SMTP認證及Postfix服務(wù),并設(shè)置相應(yīng)服務(wù)為自啟動。
[root@sample ~]# chkconfig saslauthd on ← 將SMTP-Auth設(shè)置為自啟動 [root@sample ~]# chkconfig --list saslauthd ← 確認SMTP-Auth服務(wù)狀態(tài) saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 確認2~5為on的狀態(tài)就OK [root@sample ~]# /etc/rc.d/init.d/saslauthd start ← 啟動SMTP-Auth Starting saslauthd: [ OK ] [root@sample ~]# chkconfig postfix on ← 將Postfix設(shè)置為自啟動 [root@sample ~]# chkconfig --list postfix ← 確認Postfix服務(wù)狀態(tài) postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 確認2~5為on的狀態(tài)就OK [root@sample ~]# /etc/rc.d/init.d/postfix start ← 啟動Postfix Starting postfix: [ OK ]
至此,就完成了SMTP服務(wù)器方面的配置,但目前只具從備客戶端通過服務(wù)器發(fā)送郵件的功能。
參考來源[ ]
http://www.centospub.com/make/postfix_smtp.html