在RHEL 4 上配置全功能的Postfix 伺服器
文檔版本:0.2
文檔日誌:
2005-12-17 至 12-20 初稿完成,首次公開
作者:Tony Feng
郵件:[email protected]
簡介
本文講述在安裝了Redhat Enterprice AS 4 U2的PC上,配置一台Postfix郵件伺服器的過程。實現虛擬域、虛擬用戶、POP3、POP3S、SMTP、SMTPS、IMAP、IMAPS、防毒、防SPAM、網頁郵件功能。
涉及的軟體
1. Redhat Enterprice AS 4 U2
2. Mysql
系統自帶
用於存儲虛擬域、虛擬用戶等信息。
3. Apache
系統自帶
運行網頁郵件SquirrelMail和PostfixAdmin時使用。
4. PHP
系統自帶
運行網頁郵件SquirrelMail和PostfixAdmin時使用。
5. Cyrus-sasl
系統自帶
實現帶驗證的SMTP時使用。
6. Courier authentication library
從http://www.courier-mta.org/ 下載
實現帶驗證的SMTP時使用。
7. Postfix
從http://postfix.org 下載
一個MTA,雖然RHEL 4 自帶Postfix,但因為其不支持SSL及Mysql,所以我們需要自行編譯。
8. PostfixAdmin
從http://postfixadmin.com/ 下載
虛擬域、虛擬用戶等信息是放在Mysql內的,安裝PostfixAdmin后,就可以用瀏覽器管理這些信息。
9. SquirrelMail
系統自帶
一個基於IMAP的Webmail客戶端。
10. Dovecot
系統自帶
提供POP3,POP3S,IMAP,IMAPS功能。
11. F-prot
從http://www.f-prot.com 下載,Linux workstation 版個人使用是免費的
提供殺毒功能,據聞速度和病毒庫比開源的Clamav好。
12. SpamAssassin
系統自帶
提供過濾垃圾郵件功能。
13. MailScanner
從http://www.sng.ecs.soton.ac.uk/mailscanner/ 下載
Postfix 是使用MailScanner 調用f-prot 與SpamAssassin,或者其它調用方法效率更好,但MailScanner配置比較直觀,且最近拿了一個大獎 http://www.linuxawards.co.uk/content/view/26/42/ 。
配置過程
1. 基本軟體安裝
安裝RHEL 4 U2,使用默認安裝,語係為簡體中文。關閉SE Linux,配置網卡,使其能訪問Internet。進入X window,開始->系統設置->添加/刪除應用程序,安裝上文中提及「系統自帶」的軟體,包括:
萬維網伺服器:mysql & php 相關的
郵件伺服器:SquirrelMail perl-cyrus
SQL 資料庫:全部。
下載其它需要的軟體。
2. 配置PostfixAdmin、Mysql、Apache
# tar xzf postfixadmin-2.1.0.tgz
# mv postfixadmin-2.1.0 /var/www/html/pa
# service mysqld start
# mysql -uroot < /var/www/html/pa/DATABASE_MYSQL.TXT
# cp /var/www/html/pa/config.inc.php.sample /var/www/html/pa/config.inc.php
# service httpd start
打開瀏覽器訪問 http://localhost/pa,然後按提示增加兩個虛擬域名d1.com 和 d2.com,增加兩個虛擬用戶[email protected],[email protected]。
設置Mysql和Apache自動啟動
# chkconfig --level 35 mysqld on
# chkconfig --level 35 httpd on
3. 編譯、配置Postfix
先刪除sendmail
# rpm –e sendmail –nodeps
# groupadd postfix
# groupadd postdrop
#useradd postfix -g postfix -c "Postfix user" -d /dev/null -s /sbin/nologin
# tar xzf postfix-2.2.7.tar.gz
# cd postfix-2.2.7
# make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_TLS -DUSE_SASL_AUTH -I/usr/include/sasl' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib -lssl -lcrypto -lsasl2'
# make
# make install
註:「make install」命令后的所有問題都直接敲回車鍵即可。
編輯/etc/postfix/main.cf 為以下內容
#=====================BASE=========================
myhostname = mail.d1.com
mydomain = d1.com
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain
mynetworks = 192.168.1.0/24 127.0.0.0/8
inet_interfaces = all
#=====================Vritual Mailbox settings=========================
virtual_mailbox_base = /var/spool/mail
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_domains =
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:501
virtual_gid_maps = static:502
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
#====================QUOTA========================
message_size_limit = 14336000
virtual_mailbox_limit = 20971520
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later.
virtual_overquota_bounce = yes
#====================SASL========================
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination,permit
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner=$myhostname ESMTP "Version not Available"
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/local/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix
編輯/etc/postfix/ mysql_virtual_alias_maps.cf 為以下內容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
編輯/etc/postfix/ mysql_virtual_domains_maps.cf 為以下內容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
編輯/etc/postfix/ mysql_virtual_mailbox_limit_maps.cf 為以下內容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
編輯/etc/postfix/ mysql_virtual_mailbox_maps.cf 為以下內容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
4. 配置SMTP 認證
編輯 /usr/lib/sasl2/smtpd.conf 為以下內容
pwcheck_method: authdaemond
log_level: 3
mech_list: plain login
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
安裝Courier authentication library
# tar jxf courier-authlib-0.58.tar.bz2
# cd courier-authlib-0.58
# ./configure --prefix=/usr/local/courier-authlib --without-authpam --without-authldap --without-authpwd --without-authshadow --without-authvchkpw --without-authpgsql --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat --with-authmysqlrc=/usr/local/courier-authlib/etc/authmysqlrc --with-authdaemonrc=/usr/local/courier-authlib/etc/authdaemonrc CFLAGS="-march=i686 -O2 -fexpensive-optimizations" CXXFLAGS="-march=i686 -O2 -fexpensive-optimizations"
# make
# make install
# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
# cp /usr/local/courier-authlib/etc/authdaemonrc.dist /usr/local/courier-authlib/etc/authdaemonrc
修改/usr/local/courier-authlib/etc/authdaemonrc 文件
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
編輯/usr/local/courier-authlib/etc/authmysqlrc 為以下內容,其中501,502 為postfix 用戶的UID和GID。
MYSQL_SERVER localhost
MYSQL_USERNAME postfix
MYSQL_PASSWORD postfix
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_DATABASE postfix
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD '501'
MYSQL_GID_FIELD '502'
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat('/var/spool/mail/',maildir)
MYSQL_MAILDIR_FIELD concat('/var/spool/mail/',maildir)
MYSQL_NAME_FIELD name
# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
# chmod 755 /etc/init.d/courier-authlib
# chkconfig --add courier-authlib
# chkconfig --level 35 courier-authlib on
手動啟動服務:
# service courier-authlib start
此時你已經擁有一台帶驗證的SMTP 伺服器,用Outlook 、Foxmail測試一下吧,用戶名採用[email protected] 形式。
[火星人 ] 在RHEL 4 上配置全功能的Postfix 伺服器已經有786次圍觀