星期三, 9月 14, 2011

Postfix + MySQL + ExtMail郵件伺服器

[轉載] http://www.bsdlover.cn/html/51/n-2951.html

一、安装

先把相应的软件安装上,最后再来分别配置。安装之前最好先用“portsnap fetch update”更新ports
[1]. 安装cyrus-sasl2
cyrus-sasl2是为标准的SASL实现库,可以支持Courier authlib。
[root@bsd01 ~]#cd /usr/ports/security/cyrus-sasl2
[root@bsd01 cyrus-sasl2]#make install clean

然后会出现“make config”的界面,选择需要的支持即可,但是我现在是以mysql做数据库支持,所以一定要需mysql:
Options for cyrus-sasl 2.1.22_2
----------------------------------------------------------------------------
[ ] BDB Use Berkeley DB
[X] MYSQL Use MySQL
[ ] PGSQL Use PostgreSQL
[ ] SQLITE Use SQLite
[ ] DEV_URANDOM Use /dev/urandom
[ ] ALWAYSTRUE Enable the alwaystrue password verifier
[ ] KEEP_DB_OPEN Keep handle to Berkeley DB open
[X] AUTHDAEMOND Enable use of authdaemon
[X] LOGIN Enable LOGIN authentication
[X] PLAIN Enable PLAIN authentication
[X] CRAM Enable CRAM-MD5 authentication
[X] DIGEST Enable DIGEST-MD5 authentication
[X] OTP Enable OTP authentication
[X] NTLM Enable NTLM authentication


[2]. 安装courier-imap
Courier-IMAP是一个提供POP3、IMAP服务的程序,能够很方便的配置使其支持加密协议POP3s、IMAPs。并良好的支持Maildir。
[root@bsd01 cyrus-sasl2]#cd /usr/ports/mail/courier-imap
[root@bsd01 courier-imap]#make install clean

然后会出现“make config”的界面,选择需要的支持即可:
Options for courier-imap 4.4.1,2
-------------------------------------------------------------------------------
[ ] FAM Build in fam support for IDLE command
[ ] TRASHQUOTA Include deleted mails in the quota
[ ] GDBM Use gdbm db instead of system bdb
[ ] IPV6 Build with IPv6 support
[ ] AUTH_LDAP LDAP support
[X] AUTH_MYSQL MySQL support
[ ] AUTH_PGSQL PostgreSQL support
[ ] AUTH_USERDB Userdb support
[ ] AUTH_VCHKPW Vpopmail/vchkpw support


[3]. 安装postfix
postfix是一个优秀的MTA(mail transfer agent,邮件传输代理),相比sendmail在性能还是配置简便都好一些,它本身就是用来替代sendmail的,所以兼容性也很不错,大部分的sendmail的脚本都可以使用在postfix上。
[root@bsd01 courier-imap]#cd /usr/ports/mail/postfix
[root@bsd01 postfix]#make install clean

然后会出现“make config”的界面,选择我们需要的组件就可以了:
Options for postfix 2.5.5,1
--------------------------------------------------------------------------------------
[X] PCRE Perl Compatible Regular Expressions
[X] SASL2 Cyrus SASLv2 (Simple Auth. and Sec. Layer)
[ ] DOVECOT Dovecot SASL authentication method
[ ] SASLKRB If your SASL req. Kerberos select this option
[ ] SASLKRB5 If your SASL req. Kerberos5 select this option
[ ] SASLKMIT If your SASL req. MIT Kerberos5 select this option
[X] TLS Enable SSL and TLS support
[ ] BDB Berkeley DB (choose version with WITH_BDB_VER)
[X] MYSQL MySQL maps (choose version with WITH_MYSQL_VER)
[ ] PGSQL PostgreSQL maps (choose with DEFAULT_PGSQL_VER)
[ ] OPENLDAP OpenLDAP maps (choose ver. with WITH_OPENLDAP_VER)
[ ] CDB CDB maps lookups
[ ] NIS NIS maps lookups
[X] VDA VDA (Virtual Delivery Agent)
[X] TEST SMTP/LMTP test server and generator

安装过程会出现1个问题,一般默认就可以了:
Would you like me to add it [y]?y
Would you like to activate Postfix in /etc/mail/mailer.conf [n]?n

安装完之后,会提示你把启动下下面文字加入/etc/rc.conf文件
postfix_enable="YES"
#If you not need sendmail anymore, please add in your rc.conf:
sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

然后把下面的加入到/etc/periodic.conf,但是我服务器上根本没有/etc/periodic.conf文件,所以就不用管它:
#And you can disable some sendmail specific daily maintenance routines in your /etc/periodic.conf file:
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"

[4]. 安装extman和extmail
其实这个去http://www.extmail.org/cgi-bin/download.cgi下载也可以。
1). 安装extman 0.2.5
[root@bsd01 postfix]#cd /usr/ports/mail/extman
[root@bsd01 extman]#make install clean

然后会弹出“make config”的选项,选择我们需要的mysql就可以了:
Options for extman 0.2.5
------------------------------------------------------------
[X] MySQL Use MySQL support
[ ] LDAP Use LDAP support

extman安装好之后,网页及配置文件位于/usr/local/www/extman目录。它还会编译其他比如p5-MIME,p5-GD,p5-DBD-mysql,gd,p5-DBI,p5-Storable这些支持组件。这就是ports的强大之处。

2). 安装extmail 1.0.5
[root@bsd01 extman]#cd ../extmail
[root@bsd01 extmail]#make install clean

这里也会弹出“make config”的选项,跟extman的一样,但是由于前面extman已经选择了支持,所以这里可以把mysql和ldap的支持去掉了。
extmail安装好之后,网页及配置文件位于/usr/local/www/extmail,另外他还会把p5-Unix-Syslog这个组件安装上。

现在我们就可以来配置了。

二、配置篇
[1]. 先来做几个基本的动作
[root@bsd02 ~]#mv /usr/sbin/sendmail /usr/sbin/sendmail.old
[root@bsd01 ~]#ln -s /usr/local/sbin/sendmail /usr/sbin
[root@bsd01 ~]#echo 'postfix: root' >> /etc/aliases
[root@bsd01 ~]#/usr/local/bin/newaliases
[root@bsd01 ~]#chown postfix:postfix /etc/opiekeys

[2]. 现在来配置courier-imap
▼先复制下配置文件:
[root@bsd01 ~]#cd /usr/local/etc/courier-imap
[root@bsd01 courier-imap]#cp imapd.cnf.dist imapd.cnf
[root@bsd01 courier-imap]#cp pop3d.cnf.dist pop3d.cnf
[root@bsd01 courier-imap]#chmod a+x /var/run/authdaemond

▼然后把courier-imap的启动加到/etc/rc.conf文件:
courier_authdaemond_enable="YES"
courier_imap_pop3d_enable="YES"
courier_imap_imapd_enable="YES"

▼启动认证服务:
[root@bsd01 courier-imap]#/usr/local/etc/rc.d/courier-authdaemond start