WIKI使用導航
站長百科導航
站長專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機
- cPanel
- 網(wǎng)址導航專題
- 云計算
- 微博營銷
- 虛擬主機管理系統(tǒng)
- 開放平臺
- WIKI程序與應用
- 美國十大主機
CentOS/SMTP服務器的構(gòu)建
CentOS | CentOS安裝 | CentOS使用手冊 |
在CentOS中,默認的郵件服務器(SMTP方面)是sendmail,但sendmail有若干的缺點,比如,配置復雜、安全漏洞曾被多次發(fā)現(xiàn)--并且依然存在隱患、郵件發(fā)送速度慢等等,這里就不再一一敘述。
而另一個被廣泛應用于郵件服務方面的“Postfix”的缺點就少得多,或者說它就是針對于sendmail的缺點,而被設計的。對應sendmail的短處,它在各方面也比較成熟。所以,無特殊要求,這里不推薦用sendmail來構(gòu)建郵件服務器。本條目介紹的郵件服務器配置方法,也將基于Postfix。
添加MX記錄[ ]
這里假設使用動態(tài)域名。
由于MX記錄添加后,可能生效要等待一段時間(通常為數(shù)分鐘或數(shù)十分鐘,也可能馬上生效),所以在安裝配置前,我們首先為動態(tài)域名添加MX記錄。添加方法也會因域名ISP的不同而不同,但大致信息如下: mx mail.centospub.com. 10 a mail 服務器的IP地址 mail為別名,10為優(yōu)先度。這個別名指向服務器的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及相關組件[ ]
[1] 對Postfix進行配置。
[root@sample ~]# vi /etc/postfix/main.cf ← 編輯Postfix的配置文件 #myhostname = host.domain.tld ← 找到此行,將等號后面的部分改寫為主機名 ↓ myhostname = sample.centospub.com ← 變?yōu)榇藸顟B(tài),設置系統(tǒng)的主機名 #mydomain = domain.tld ← 找到此行,將等號后面的部分改寫為域名 ↓ mydomain = centospub.com ← 變?yōu)榇藸顟B(tài),設置域名(我們將讓此處設置將成為E-mail地址“@”后面的部分) #myorigin = $mydomain ← 找到此行,將行首的#去掉 ↓ myorigin = $mydomain ← 變?yōu)榇藸顟B(tài),將發(fā)信地址“@”后面的部分設置為域名(非系統(tǒng)主機名) inet_interfaces = localhost ← 找到此行,將“l(fā)ocalhost”改為“all” ↓ inet_interfaces = all ← 變?yōu)榇藸顟B(tài),接受來自所有網(wǎ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),指定用戶郵箱目錄 # 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服務器的相關信息 在配置文件的文尾,添加如下行: smtpd_sasl_auth_enable = yes ← 服務器使用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認證的相關選項,為了提高安全性,我們不將系統(tǒ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] 建立用戶的郵箱目錄,首先建立用戶模板下的郵箱目錄,以便于建立新用戶時,相應用戶的郵箱目錄自動被建立。
[root@sample ~]# mkdir /etc/skel/Maildir ← 在用戶模板下建立用戶郵箱目錄 [root@sample ~]# chmod 700 /etc/skel/Maildir ← 設置用戶郵箱目錄屬性為700
然后再為已經(jīng)存在的用戶建立相應郵箱目錄。
[root@sample ~]# mkdir /home/centospub/Maildir ← 為用戶(這里以centospub用戶為例)建立郵箱目錄 [root@sample ~]# chmod 700 /home/centospub/Maildir ← 設置該用戶郵箱目錄屬性為700 [root@sample ~]# chown centospub. /home/centospub/Maildir ← 設置該用戶郵箱目錄為該用戶所有
[4] 為用戶設置SMTP認證密碼
root@sample ~]# saslpasswd2 -u sample.centospub.com -c centospub ← 為centospub用戶設置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] 關閉sendmail服務及設置默認MTA,因為在用Postfix作為SMTP服務器的前提下,我們不準備再用sendmail,所以將sendmail服務關掉,以確保安全及節(jié)省系統(tǒng)資源。
[root@sample ~]# /etc/rc.d/init.d/sendmail stop ← 關閉sendmail服務 Shutting down sendmail: [ OK ] Shutting down sm-client: [ OK ] [root@sample ~]# chkconfig sendmail off ← 關閉sendmail自啟動 [root@sample ~]# chkconfig --list sendmail ← 確認sendmail自啟動已被關閉(都為off就OK) sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
然后再將默認的MTA設置為Postfix。
[root@sample ~]# alternatives --config mta ← 設置默認MTA There are 2 programs which provide 'mta'. Selection Command ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail ← 當前狀態(tài):sendmail為默認MTA 2 /usr/sbin/sendmail.postfix Enter to keep the current selection[+], or type selection number: 2 ← 在這里輸入2, 使Postfix成為默認MTA
啟動相應服務[ ]
最后,啟動SMTP認證及Postfix服務,并設置相應服務為自啟動。
[root@sample ~]# chkconfig saslauthd on ← 將SMTP-Auth設置為自啟動 [root@sample ~]# chkconfig --list saslauthd ← 確認SMTP-Auth服務狀態(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設置為自啟動 [root@sample ~]# chkconfig --list postfix ← 確認Postfix服務狀態(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服務器方面的配置,但目前只具從備客戶端通過服務器發(fā)送郵件的功能。
參考來源[ ]
http://www.centospub.com/make/postfix_smtp.html