使用Postfix構(gòu)建基于FreeBSD的郵件系統(tǒng)(簡(jiǎn)化版)來(lái)源:www.freebsdchina.org 作者: 時(shí)間:2007-12-29 點(diǎn)擊:
74
由于寫上一篇文章的時(shí)候也剛剛接觸postfix,,對(duì)電子郵件系統(tǒng)理解也很膚淺,,雖然勉強(qiáng)建立了可以運(yùn)行的郵件系統(tǒng),但是也暴露了大量的問(wèn)題,。同時(shí)盲目的追求功能,,使得整個(gè)安裝過(guò)程較為漫長(zhǎng),對(duì)于想入門的朋友來(lái)說(shuō)難度較大,。這次我將上一篇文章重新修改,,并去掉查毒和反垃圾郵件的功能,完成安裝后,建立一個(gè)具有完整收發(fā)郵件功能,,但安全性較低的郵件系統(tǒng),,供剛?cè)腴T的朋友借鑒。 基于postfix的郵件系統(tǒng)按照功能劃分可分為3個(gè)部分,,包括smtp,、imap/pop3和身份驗(yàn)證,這3部分功能分別由postfix/courier-imap和courier-authdaemond實(shí)現(xiàn),,其中courier-authdaemond又要調(diào)用cyrus-sasl2進(jìn)行驗(yàn)證,。郵件系統(tǒng)的所有數(shù)據(jù),可以保存在ldap/pgsql或者mysql中,。為了使安裝過(guò)程簡(jiǎn)單易懂,,本文將使用mysql。 0,、 更新ports pkg_add -r cvsup cvsup -gL 2 -h cvsup.freebsdchina.org /usr/share/examples/cvsup/ports-supfile 1,、 安裝sasl2 sasl2是smtp驗(yàn)證所需要的軟件包,由于postfix安裝時(shí)采用默認(rèn)配置,,使得sasl不支持courier-authdaemond,,因此需要首先用指定的選項(xiàng)進(jìn)行安裝。 cd /usr/ports/security/cyrus-sasl2 make WITH_AUTHDAEMON=yes install clean 2,、 安裝postfix cd /usr/ports/mail/postfix make config 選中[PCRE],、[SASL2]、[MySQL],、[VDA],,sasl2用于smtp驗(yàn)證,mysql用于存放數(shù)據(jù)表,,vda用于支持虛擬投遞,。 make WITH_MYSQL_VER=51 install clean 指定安裝5.1版本的mysql,注意這里安裝的是mysql-client,,稍后還需要安裝mysql-server,。在安裝過(guò)程中兩次提示均選y,以激活postfix 3,、 安裝courier-imap cd /usr/ports/mail/courier-imap make config 選中[AUTH_MYSQL] make install clean 4,、 安裝mysql-server cd /usr/ports/databases/mysql51-server make WITH_CHARSET=gb2312 install clean 5、 安裝apache,。安裝完成后編輯httpd.conf將主目錄設(shè)置為/usr/local/www cd /usr/ports/www/apache22 make install clean 6,、 安裝php。更新ports后的php安裝方式有所變化,,首先在make config需要選中[Apache]以編譯apache模塊,,安裝完成后在httpd.conf中修改2處配置: a,、在DirectoryIndex中加入index.php b、加入AddType application/x-httpd-php .php cd /usr/ports/lang/php5 make config make install clean 7,、 安裝php5-extensions,。根據(jù)需要選擇模塊,保證[MYSQL],、[PCRE]、[SESSION]被選中,。 cd /usr/ports/lang/php5-extensions make config make install clean 8,、 安裝postfixadmin。安裝完成后將網(wǎng)頁(yè)移動(dòng)至/usr/www/data/ cd /usr/ports/mail/postfixadmin make install clean mv /usr/local/www/postfixadmin /usr/local/www/data/ 9,、 安裝squirrelmail cd /usr/ports/mail/squirrelmail make install clean 至此,,所需軟件全部安裝完畢,下面將依次進(jìn)行配置,。 注意:下面配置文件的每一行結(jié)尾必須保證沒(méi)有空格,! 1、 配置sasl2 ee /usr/local/lib/sasl2/smtpd.conf pwcheck_method: authdaemond log_level: 3 mech_list: PLAIN LOGIN authdaemond_path: /var/run/authdaemond/socket 2,、 配置mysql數(shù)據(jù)庫(kù) chown -R mysql:mysql /var/db/mysql cd /usr/local/bin/ ./mysql_install_db cd /usr/local/libexec ./mysqld --user=mysql& cd /usr/local/www/data/postfixadmin mysql -uroot -p 3,、 配置postfix 使用和apache一樣的用戶來(lái)讀取郵件目錄,因?yàn)閍pache用戶為www,,id:80,,所以要注意/usr/local/etc/postfix/main.cf中的用戶id。 newaliases mkdir -p /usr/local/virtual chown -R www:www /usr/local/virtual chmod -R 775 /usr/local/virtual ee /usr/local/etc/postfix/main.cf 在最后添加: #======= BASE ============== #myhostname = #mydomain = example.com home_mailbox = maildir/ #mydestination = $myhostname #local_recipient_maps = #======= MYSQL ============= virtual_gid_maps = static:80 virtual_mailbox_base = /usr/local/virtual virtual_uid_maps = static:80 virtual_minimum_uid = 80 virtual_alias_maps = mysql:/usr/local/etc/postfix/mysql/virtual_alias_maps.cf virtual_mailbox_domains = mysql:/usr/local/etc/postfix/mysql/virtual_domains_maps.cf virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql/virtual_mailbox_maps.cf #======= Quota ============ message_size_limit = 5242880 virtual_mailbox_limit_inbox = no virtual_mailbox_limit_override = yes virtual_maildir_extended = yes virtual_create_maildirsize = yes virtual_mailbox_limit_maps = mysql:/usr/local/etc/postfix/mysql/virtual_mailbox_limit_maps.cf virtual_mailbox_limit = 52428800 #======== SASL ================ smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous broken_sasl_auth_clients = yes smtpd_recipient_restrictions = permit_sasl_authenticated permit_auth_destination reject #smtpd_sasl_local_domain = $mydomain smtpd_client_restrictions = permit_sasl_authenticated 從上面的配置可以看出,,有4個(gè)表保存在mysql數(shù)據(jù)庫(kù)中,,分別是virtual_alias(虛擬別名)、virtual_domains(虛擬域),、virtual_mailbox_maps(虛擬郵箱映射),、和virtual_mailbox_limit(虛擬郵箱限額)。Postfix訪問(wèn)mysql的特定表和字段分別由4個(gè)對(duì)應(yīng)的配置文件設(shè)置,。 cd /usr/local/etc/postfix/ mkdir mysql cd mysql 1,、ee virtual_alias_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = alias select_field = goto where_field = address 2、ee virtual_domains_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = domain select_field = description where_field = domain 3,、ee virtual_mailbox_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = mailbox select_field = maildir where_field = username 4,、ee virtual_mailbox_limit_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = mailbox select_field = quota where_field = username 4、 配置courier-authdaemond cd /usr/local/etc/rc.d ./courier-authdaemond start #腳本文件名可能是courier-authdaemond.sh chmod o+x /var/run/authdaemond cd /usr/local/etc/authlib ee authdaemonrc 修改authmodulelist和authmodulelistorig,,指定只使用mysql進(jìn)行驗(yàn)證 authmodulelist="authmysql" authmodulelistorig="authmysql" 設(shè)置authmysqlrc,,使authdaemond能夠查詢mysql,注意刪除每行末尾的空格,。 ee authmysqlrc DEFAULT_DOMAIN example.com MYSQL_CRYPT_PWFIELD password MYSQL_DATABASE postfix MYSQL_GID_FIELD '80' MYSQL_HOME_FIELD '/usr/local/virtual' MYSQL_LOGIN_FIELD username MYSQL_MAILDIR_FIELD maildir MYSQL_NAME_FIELD name MYSQL_OPT 0 MYSQL_PASSWORD postfix #MYSQL_PORT 0 #MYSQL_QUOTA_FIELD quota MYSQL_SERVER localhost MYSQL_UID_FIELD '80' MYSQL_USERNAME postfix MYSQL_USER_TABLE mailbox 5,、 配置啟動(dòng)項(xiàng) ee /etc/rc.conf 添加下列條目: sendmail_enable="NONE" postfix_enable="YES" apache22_enable="YES" mysql_enable="YES" courier_authdaemond_enable="YES" courier_imap_imapd_enable="YES" courier_imap_pop3d_enable="YES" 6、 重起電腦 Reboot 7、 配置postfixadmin cd /usr/local/www/data/postfixadmin ee config.inc.php $CONF['default_language'] = 'cn'; $CONF['admin_email'] = '[email protected]'; $CONF['domain_path'] = 'YES'; $CONF['domain_in_mailbox'] = 'NO'; $CONF['quota'] = 'YES'; 通過(guò)http://localhost/postfixadmin/setup.php查看是否安裝成功,。 進(jìn)入http://localhot/postfixadmin/admin進(jìn)入管理頁(yè)面,,建立虛擬域和用戶。 觀察/usr/local/virtual下是否出現(xiàn)對(duì)應(yīng)的域名目錄和用戶目錄,。 注意:如在postfixadmin中新建與本機(jī)域名相同的虛擬域,,則有可能無(wú)法建立相應(yīng)的域名和用戶的文件夾。這種情況應(yīng)通過(guò)mx記錄解決,。如郵件服務(wù)器位于example.com上,,則應(yīng)指定postfix的域名為mail.example.com,再添加mx記錄指向mail.example.com,,這樣即可建立example.com虛擬域,。 8、 配置squirrelmail cd /usr/local/www/data/squirrelmail ./configure 選擇10. Languages 設(shè)置如下: 1. Default Language : zh_CN 2. Default Charset : gb2312 保存退出 進(jìn)入http://localhost/squirrelmail/測(cè)試郵箱,。 注意:除了在authmysqlrc中DEFAULT_DOMAIN指定的域外,,其他域用戶登陸都需要輸入完整的電子郵件地址。
from site :http://www./server/mail/2007-12/317.html
|
|
來(lái)自: 農(nóng)夫子oice > 《Mail》