歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> Linux系統郵件服務器的搭建過程解析

Linux系統郵件服務器的搭建過程解析

日期:2017/3/2 16:52:35   编辑:Linux服務器

1. 用以下命令查看系統是否安裝了sendmail:
 
  [root@mail /root]# rpm –qa |grep sendmail
 
  sendmail-8.11.0-8
 
  2. 卸載sendmail:
 
  [root@mail /root]# rpm -e sendmail –nodeps
 
  3. 用以下命令殺死運行中的sendmail進程:
 
  [root@mail /root]# killall sendmail
 
  如果系統提示:
 
  sendmail: no process killed
 
  則說明當前系統中沒有sendmail進程。
 
  4. 安裝postfix:
 
  [root@mail /root]# rpm -ivh postfix-20010228release-2.i386.rpm
 
  若已經安裝,則此步可以省略。(注:安裝時最好用rpm包,會自動創建postfix用戶和postfix組)
 
  5. 安裝imap
 
  rpm –ivh /mnt/cdrom/RedHat/RPMS/ imap-4.7c2-12.rpm
 
  imap使pop3有效,即打開110端口。(注:安裝時最好用rpm包)
 
  若已經安裝,則此步可以省略。
 
  6. 檢查系統中是否安裝了cyrus-sasl
 
  執行以下命令查看系統中是否安裝了cyrus-sasl:
 
  rpm –qa |grep cyurs
 
  如果您看到以下提示,則說明已經安裝了cyrus-sasl
 
  [root@test bye2000]# rpm -qa |grep sasl
 
  cyrus-sasl-devel-1.5.24-17
 
  cyrus-sasl-1.5.24-17
 
  否則,請用rpm –ivh 命令先安裝所需sasl-cyrus包。
 
  7.修改postfix用戶
 
  同時應該讓該用戶不能登錄到系統,也即不為該用戶指定可執行的登錄外殼程序和可用
 
  的用戶宿主目錄。
 
  編輯/etc/passwd文件中的相關條目如下所示:
 
  postfix:x:89:89::/no/where:/no/shell [編輯後,只修改藍色部分就可以了]
 
  即:修改用戶的Home directory和Shell 參照 /etc/passwd文件
 
  8.編輯postfix的主要配置文件/etc/postfix/main.cf,根據需求只需修改以下幾個參數:
 
  1)mydomain
 
  指明你的域名,在這裡我們指定:
 
  mydomain = xx.com
 
  2)myorigin
 
  myorigin參數指明發件人所在的域名。如果你的用戶的郵件地址為[email protected],則該參數指定@後面的域名。在這裡我們指定:
 
  myorigin = $mydomain
 
  3)inet_interfaces
 
  inet_interfaces = all 監聽所有端口
 
  4)mydestination
 
  mydestination參數指定postfix接收郵件時收件人的域名,換句話說,也就是你的postfix
 
  系統要接收什麼樣的郵件。通常與myorigin一樣:
 
  mydestination = $mydomain
 
  5)mynetworks_style
 
  設置網絡類型,我們指定:
 
  mynetworks_style = subnet
 
  6)ynetworks
 
  定義可以使用的此smtp服務器發信的客戶ip地址,因為公司的ip范圍已知,所以我們
 
  指定:
 
  mynetworks = 192.168.1.0/24
 
  注:此項可根據情況而定,主要是指定ip范圍,假如公司的ip劃分是按照網段來的,例如:10.10.1.0~10.10.1.9,10.10.3.0~10.10.3.9等等更細。根據需要,該項可以不設置。
 
  7)SMTP的配置
 
  為了告訴postfix采用sasl來進行SMTP的用戶認證,我們必須在/etc/postfix/main.cf文件的最後添加以下幾行:
 
  smtpd_sasl_auth_enable = yes
 
  smtpd_recipient_restrictions = permit_sasl_authenticated
 
  permit_auth_destination reject
 
  broken_sasl_auth_clients = yes
 
  smtpd_sasl_security_options = noanonymous
 
  說明如下:
 
  smtpd_sasl_auth_enable:告訴SMTP客戶,該SMTP服務器需要進行用戶認證。
 
  smtpd_recipient_restrictions = permit_sasl_authenticated
 
  permit_auth_destination reject
 
  僅僅中繼通過SMTP認證的客戶端郵件,以及接收本postfix為最後一站的郵件。
 
  broken_sasl_auth_clients = yes
 
  有一些Microsoft 的SMTP客戶端,比如Outlook Express 4.X采用的是非標准的SMTP認證協議,將該選項設置為yes可以解決這類不兼容問題。
 
  smtpd_sasl_security_options = noanonymous
 
  控制本地SMTP認證所采用的機制,這裡是允許任何非匿名認證方法。
 
  9.配置SASL
 
  進入/usr/lib/sasl/目錄,用touch新建這樣一個文件:
 
  [root@test sasl]# touch smtpd.conf
 
  在該文件中加入以下內容:
 
  [root@test sasl]# more smtpd.conf
 
  pwcheck_method:pam
 
  也就是指定通過PAM來進行用戶認證。
 
  10.配置PAM
 
  進入/etc/pam.d/目錄,用touch新建這樣一個文件:
 
  [root@test pam.d]# touch smtp
 
  在該文件中加入如下內容:
 
  [root@test pam.d]# more smtp
 
  #%PAM-1.0
 
  auth required /lib/security/pam_stack.so service=system-auth
 
  account required /lib/security/pam_stack.so service=system-auth
 
  也即和/etc/pam.d/pop文件的內容是一致的。
 
  11.修改/etc/shadow文件權限
 
  因為PAM最終要去讀取/etc/shadow文件的內容來進行用戶認證,但是/etc/shadow文件
 
  權限是設置為只有root用戶可以讀寫,而我們的postfix是運行在postfix用戶權限之下,所以我們要合理的設置/etc/shadow文件權限,以便讓pam可以讀取其內容。
 
  執行以下命令,讓root組也可以讀取shadow:
 
  [root@test /etc]# chmod 640 /etc/shadow
 
  然後再將postfix用戶加入root組,采用以下命令:
 
  [root@test /etc]# usermod -G root postfix
 
  12.編輯postfix的主要配置文件/etc/postfix/master.cf
 
   # ========================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ========================================
smtp inet n - n - - smtpd

 
  這裡開始
 
   #smtps inet n - n - - smtpd
# -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes
#submission inet n - n - - smtpd
# -o smtpd_enforce_tls=yes -o smtpd_sasl_auth_enable=yes

 
  這裡結束
 
  #628 inet n - n - - qmqpd
 
  把我標的注釋部分去掉即可。
 
  13.配置pop3
 
  RedHat7.0已經使用xinetd代替了以前的inetd,為了使pop3服務啟動,我們編輯
 
  /etc/xinetd.d/ipop3文件,將其中的disable = yes改為disable = no 以便啟動pop3
 
  服務。
 
  為了使改動生效,執行以下命令:
 
  /etc/rc.d/init.d/xinetd reload
 
  14.啟動postfix
 
  執行以下命令啟動postfix:
 
  /etc/rc.d/init.d/postfix start
 
  這樣,一個支持SMTP認證的postfix郵件服務器就配好了

Copyright © Linux教程網 All Rights Reserved