1. gzyueqian
      18529173453
      首頁 > 新聞中心 > > 正文

      在RHEL 4上配置全功能的Postfix服務器

      更新時間: 2007-06-02 10:18:51來源: 粵嵌教育瀏覽量:801


        簡介

        本文講述在安裝了Redhat Enterprice AS 4 U2的PC上,配置一臺Postfix郵件服務器的過程。實現(xiàn)虛擬域、虛擬用戶、POP3、POP3S、SMTP、SMTPS、IMAP、IMAPS、防毒、防SPAM、網(wǎng)頁郵件功能。

      涉及的軟件
      1. Redhat Enterprice AS 4 U2
      2. Mysql
      系統(tǒng)自帶
      用于存儲虛擬域、虛擬用戶等信息。
      3. Apache
      系統(tǒng)自帶
      運行網(wǎng)頁郵件SquirrelMail和PostfixAdmin時使用。
      4. PHP
      系統(tǒng)自帶
      運行網(wǎng)頁郵件SquirrelMail和PostfixAdmin時使用。
      5. Cyrus-sasl
      系統(tǒng)自帶
      實現(xiàn)帶驗證的SMTP時使用。
      6. Courier authentication library
      從http://www.courier-mta.org/ 下載
      實現(xiàn)帶驗證的SMTP時使用。
      7. Postfix
      從http://postfix.org 下載
      一個MTA,雖然RHEL 4 自帶Postfix,但因為其不支持SSL及Mysql,所以我們需要自行編譯。
      8. PostfixAdmin
      從http://postfixadmin.com/ 下載
      虛擬域、虛擬用戶等信息是放在Mysql內(nèi)的,安裝PostfixAdmin后,就可以用瀏覽器管理這些信息。
      9. SquirrelMail
      系統(tǒng)自帶
      一個基于IMAP的Webmail客戶端。
      10. Dovecot
      系統(tǒng)自帶
      提供POP3,POP3S,IMAP,IMAPS功能。
      11. F-prot
      從http://www.f-prot.com 下載,Linux workstation 版?zhèn)€人使用是免費的
      提供殺毒功能,據(jù)聞速度和病毒庫比開源的Clamav好。
      12. SpamAssassin
      系統(tǒng)自帶
      提供過濾垃圾郵件功能。
      13. MailScanner
      從http://www.sng.ecs.soton.ac.uk/mailscanner/ 下載
      Postfix 是使用MailScanner 調(diào)用f-prot 與SpamAssassin,或者其它調(diào)用方法效率更好,但MailScanner配置比較直觀,且近拿了一個大獎 http://www.linuxawards.co.uk/content/view/26/42/ 。

      配置過程
      1. 基本軟件安裝
      安裝RHEL 4 U2,使用默認安裝,語系為簡體中文。關閉SE Linux,配置網(wǎng)卡,使其能訪問Internet。進入X window,開始->系統(tǒng)設置->添加/刪除應用程序,安裝上文中提及“系統(tǒng)自帶”的軟件,包括:
      萬維網(wǎng)服務器:mysql & php 相關的
      郵件服務器:SquirrelMail perl-cyrus
      SQL 數(shù)據(jù)庫:全部。
      下載其它需要的軟件。

      2. 配置PostfixAdmin、Mysql、Apache
      [root@localhost tmp]# tar xzf postfixadmin-2.1.0.tgz
      [root@localhost tmp]# mv postfixadmin-2.1.0 /var/www/html/pa
      [root@localhost tmp]# service mysqld start
      [root@localhost tmp]# mysql -uroot http://localhost/pa,然后按提示增加兩個虛擬域名d1.com 和 d2.com,增加兩個虛擬用戶a@d1.com,b@d2.com。

      設置Mysql和Apache自動啟動
      [root@localhost tmp]# chkconfig --level 35 mysqld on
      [root@localhost tmp]# chkconfig --level 35 httpd on

      3. 編譯、配置Postfix
      先刪除sendmail
      [root@localhost tmp]# rpm –e sendmail –nodeps
      [root@localhost tmp]# groupadd postfix
      [root@localhost tmp]# groupadd postdrop
      [root@localhost tmp]#useradd postfix -g postfix -c "Postfix user" -d /dev/null -s /sbin/nologin
      [root@localhost tmp]# tar xzf postfix-2.2.7.tar.gz
      [root@localhost tmp]# cd postfix-2.2.7
      [root@localhost 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'
      [root@localhost postfix-2.2.7]# make
      [root@localhost postfix-2.2.7]# make install
      注:“make install”命令后的所有問題都直接敲回車鍵即可。

      編輯/etc/postfix/main.cf 為以下內(nèi)容
      #=====================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 為以下內(nèi)容
      user = postfix
      password = postfix
      hosts = localhost
      dbname = postfix
      table = alias
      select_field = goto
      where_field = address

      編輯/etc/postfix/ mysql_virtual_domains_maps.cf 為以下內(nèi)容
      user = postfix
      password = postfix
      hosts = localhost
      dbname = postfix
      table = domain
      select_field = description
      where_field = domain

      編輯/etc/postfix/ mysql_virtual_mailbox_limit_maps.cf 為以下內(nèi)容
      user = postfix
      password = postfix
      hosts = localhost
      dbname = postfix
      table = mailbox
      select_field = quota
      where_field = username

      編輯/etc/postfix/ mysql_virtual_mailbox_maps.cf 為以下內(nèi)容
      user = postfix
      password = postfix
      hosts = localhost
      dbname = postfix
      table = mailbox
      select_field = maildir
      where_field = username

      4. 配置SMTP 認證
      編輯 /usr/lib/sasl2/smtpd.conf 為以下內(nèi)容
      pwcheck_method: authdaemond
      log_level: 3
      mech_list: plain login
      authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

      安裝Courier authentication library
      [root@localhost tmp]# tar jxf courier-authlib-0.58.tar.bz2
      [root@localhost tmp]# cd courier-authlib-0.58
      [root@localhost 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"
      [root@localhost courier-authlib-0.58]# make
      [root@localhost courier-authlib-0.58]# make install
      [root@localhost courier-authlib-0.58]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
      [root@localhost courier-authlib-0.58]# 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 為以下內(nèi)容,其中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

      此時你已經(jīng)擁有一臺帶驗證的SMTP 服務器,用Outlook 、Foxmail測試一下吧,用戶名采用usename@domainName.com 形式。

      5. 增加SSL功能,配置SMTPS服務
      在/etc/postfix/main.cf 增加以下內(nèi)容
      smtp_use_tls = yes
      smtpd_use_tls = yes
      smtp_tls_note_starttls_offer = yes
      smtpd_tls_key_file = /etc/ssl/smtpd.pem
      smtpd_tls_cert_file = /etc/ssl/smtpd.pem
      smtpd_tls_CAfile = /etc/ssl/smtpd.pem
      smtpd_tls_loglevel = 1
      smtpd_tls_received_header = yes
      smtpd_tls_session_cache_timeout = 3600s
      tls_random_source = dev:/dev/urandom

      生成證書
      # mkdir /etc/ssl
      # cd /etc/ssl
      # openssl req -new -x509 -nodes -out smtpd.pem -keyout smtpd.pem -days 3650

      重新啟動postfix
      # postfix reload

      這時SMTPS功能應該能正常工作了。有能力測試的網(wǎng)友們請驗證一下這功能,因為使用SMTPS + Outlook 時有一錯誤提示。

      6. 配置Dovecot,增加IMAP,IMAPS,POP3,POP3S功能
      由于Dovecot 是系統(tǒng)自帶的,配置兩個文件,再生成證書就可以了。

      編輯 /etc/dovecot.conf 為以下內(nèi)容
      base_dir = /var/run/dovecot/
      protocols = imap imaps pop3 pop3s
      imap_listen = [::]
      pop3_listen = [::]
      ssl_disable = no
      ssl_cert_file = /etc/ssl/certs/imapd.pem
      ssl_key_file = /etc/ssl/private/imapd.pem
      ssl_parameters_file = /var/run/dovecot/ssl-parameters.dat
      login_dir = /var/run/dovecot-login
      login = imap
      login = pop3
      mbox_locks = fcntl
      auth = default
      auth_mechanisms = plain
      auth_userdb = passwd
      auth_user = root
      default_mail_env = maildir:/var/spool/mail/%u/
      auth_userdb = mysql /etc/dovecot-mysql.conf
      auth_passdb = mysql /etc/dovecot-mysql.conf
      first_valid_uid = 501

      編輯 /etc/dovecot-mysql.conf 為以下內(nèi)容
      db_host = localhost
      db_port = 3306
      db_unix_socket = /var/lib/mysql/mysql.sock
      db = postfix
      db_user = postfix
      db_passwd = postfix
      db_client_flags = 0
      default_pass_scheme = PLAIN-MD5
      password_query = SELECT password FROM mailbox WHERE username = '%u'
      user_query = SELECT maildir, 501 AS uid, 502 AS gid FROM mailbox WHERE username = '%u'

      生成證書
      # mkdir /etc/ssl/certs
      # mkdir /etc/ssl private
      # cd /usr/share/doc/dovecot-0.99.11/
      # sh mkcert.sh

      啟動Dovecot 服務
      # service dovecot start
      # chkconfig --level 35 dovecot on

      順利的話,此時SMTP、SMTPS、POP3、POP3S已經(jīng)配置完成。

      7. 配置SquirrelMail網(wǎng)頁郵件
      很簡單,用瀏覽器訪問 http://localhost/webmail

      8. 配置殺毒、過濾SPAM功能
      如果你打算將殺毒、過濾SPAM功能安排在各個客戶端,以下是不必要操作的。

      安裝f-prot
      從http://files.f-prot.com/files/linux-x86/fp-linux-ws.rpm 下載
      # rpm -ivh fp-linux-ws.rpm

      啟動SpamAssassin
      # service spamassassin start
      # chkconfig --level 35 spamassassin on

      安裝、配置MailScanner
      # tar xzf MailScanner-4.48.4-2.rpm.tar.gz
      # cd MailScanner-4.48.4-2
      # ./install.sh

      修改 /etc/MailScanner/MailScanner.conf
      Run As User = postfix
      Run As Group = postfix
      Incoming Queue Dir = /var/spool/postfix/hold
      Outgoing Queue Dir = /var/spool/postfix/incoming
      MTA = postfix
      Virus Scanners = f-prot
      Always Include SpamAssassin Report = yes
      Use SpamAssassin = yes
      Required SpamAssassin Score = 4
      SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin
      SpamAssassin Install Prefix = /usr/bin
      SpamAssassin Local Rules Dir = /etc/MailScanner

      讓Postfix 調(diào)用MailScanner,在/etc/postfix/main.cf 加入以下一行
      header_checks = regexp:/etc/postfix/header_checks

      編輯/etc/postfix/header_checks 為以下內(nèi)容
      /^Received:/ HOLD

      修正權限
      # chown postfix.postfix /var/spool/MailScanner/incoming
      # chown postfix.postfix /var/spool/MailScanner/quarantine

      啟用
      # postfix stop
      # service MailScanner start
      # chkconfig --level 35 MailScanner on

      注:MailScanner 會自動啟動Postfix。

      測試SpamAssassin
      發(fā)一封郵件帶如下內(nèi)容,接收后,標題應該帶有標記:
      XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

      測試f-prot
      升級病毒庫:
      # /usr/local/f-prot/tools/check-updates.pl
      訪問http://www.webmail.us/testvirus,申請寄一封帶virus 的郵件寄到自己的郵箱

      9. 如果上面的操作順利,整個配置完成

      免費預約試聽課

      亚洲另类欧美综合久久图片区_亚洲中文字幕日产无码2020_欧美日本一区二区三区桃色视频_亚洲AⅤ天堂一区二区三区

      
      

      1. 亚洲日本另类欧美一区二区 | 日本一本香蕉大道高清视频 | 无遮挡很黄很爽免费国产 | 亚洲国产精品综合久久网各 | 欧美国产激情一区二区 | 亚洲欧美高清一区二区三区 |