Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

Postfix 郵件服務的安裝與基本配置實戰

一、安裝 Postfix

Red Hat Enterprise Linux 同時提供 sendmail 與 postfix 兩種 SMTP 服務,預設已安裝 sendmail,若要改用 postfix,須先停掉 sendmail 再安裝 postfix。

1). 檢查 sendmail 是否啟動:[root@mail ~]#netstat -nutlp | grep :25

2). 關閉 sendmail 及開機自啟:/etc/rc.d/init.d/sendmail stop 與 chkconfig sendmail off

3). 安裝 postfix:掛載光碟後於 Server 目錄找到 RPM 包並安裝 rpm -ivh /mnt/Server/postfix-2.3.3-2.i386.rpm。

原始碼安裝則先建立 postfix 與 postdrop 用戶組及用戶,解壓並套用 vda 補丁,再以 make makefiles 帶入 CCARGS 與 AUXLIBS 參數(CCARGS 以 -I 指定額外头文件目錄,AUXLIBS 指定標準位置外的函式庫路徑),接著 make、make install。make install 期間會提示各安裝路徑(install_root、config_directory、daemon_directory、command_directory、queue_directory、mail_owner、setgid_group 等),按 Enter 採用預設即可。

二、Postfix 目錄與設定檔

1. 相關目錄:/etc/postfix(主設定檔、腳本、查詢表)、/usr/libexec/postfix(各服務程式)、/var/spool/postfix(郵件佇列子目錄,如 incoming 傳入、active 活動、deferred 推遲、hold 約束、corrupt 錯誤)、/usr/sbin(以 post 開頭的管理工具,如 postalias、postmap、postfix、postqueue、postsuper)。

2. 設定檔:主要為 /etc/postfix/main.cf 與 master.cf,前者為服務設定、後者為 master 程式設定。可用 postconf 查看目前參數,並用 postconf -n > main.cf 只留下與預設不同的參數以精簡設定。

3. 日誌位於 /var/log/maillog,可用 tail -f 查看、egrep 過濾。

4. 啟動控制:以 /usr/sbin/postfix 搭配 start、stop、check、reload 管理服務。

三、建置簡單電子郵件

1. 配置並測試:編輯 main.cf 調整 inet_interfaces(監聽 IP)、myhostname(主機名)、mydomain(郵件域)、myorigin、mydestination(可收信的域)、home_mailbox = Maildir/(郵件儲存格式)等;新增郵件用戶帳號;用 telnet localhost 25 依序下 helo、mail from、rcpt to、data 完成測試,輸入「.」結束,即可在收件者宿主目錄的 Maildir 中看到郵件。

2. 建置 Dovecot:編譯安裝(./configure --sysconfdir=/etc --with-mysql 後 make、make install);設定 dovecot.conf(ssl_disable、protocols = pop3 imap、disable_plaintext_auth、mail_location = maildir:~/Maildir);建立 PAM 認證檔 /etc/pam.d/dovecot;啟動後以 netstat 確認監聽 110、143 埠。

3. 測試 POP3 收信:telnet localhost 110 後下 user、pass、list、retr 1、quit,即可讀取郵件。

4. 使用 Outlook Express:設定帳號名稱、密碼、SMTP 與 POP3 伺服器位址,即可發收信件。

至此,一套可發信(Postfix)與收信(Dovecot)的郵件伺服器便搭建完成。

Copyright © Linux教程網 All Rights Reserved