LAMP框架编译安装请见http://5142926.blog.51cto.com/5132926/921873

一、安装postfix 
使用源码编译安装。 
1.建立postfix所需的用户和组 
建立postfix、postdrop组和postfix用户: 
 
groupadd -g 2001 postfix
useradd -g postfix -u 2001 -s /sbin/nologin -M postfix
groupadd -g 2002 postdrop
useradd -g postdrop -u 2002 -s /sbin/nologin -M postfix
 
2.安装必备软件包 
 
yum install db*-devel
 
到官网http://www.postfix.org/ 找一个下载点下载postfix,目前稳定版为Postfix 2.9 
 
cd /tmp
wget ftp://ftp.reverse.net/pub/postfix/official/postfix-2.9.3.tar.gz
tar -zxvf postfix-2.9.3.tar.gz
cd postfix-2.9.3
 
更新makefile文件,添加mysql、sasl认证支持: 
 
make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2  -lssl -lcrypto'
 
备注:-DUSE_SASL_AUTH表示启用SASL认证,-DDEF_SERVER_SASL_TYPE=\"dovecot\"表示使用dovecot做SASL模块。
 
继续安装: 
 
make
make install
 
3.make install执行后会调用postfix-install脚本 
这里设置如下,空白为直接按回车。

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX

 
 
install_root: [/]
tempdir: [/tmp/postfix-2.9.3] /tmp/postfix
config_directory: [/etc/postfix]
command_directory: [/usr/sbin]
daemon_directory: [/usr/libexec/postfix]
data_directory: [/var/lib/postfix]
html_directory: [no] /web/vhosts/postfix
mail_owner: [postfix]
mailq_path: [/usr/bin/mailq]
manpage_directory: [/usr/local/man]
newaliases_path: [/usr/bin/newaliases]
queue_directory: [/var/spool/postfix]
readme_directory: [no]
sendmail_path: [/usr/sbin/sendmail]
setgid_group: [postdrop]
 
postfix安装在/usr/sbin/postfix,随后可以访问http://IP/postfix,查看Postfix Documentation。
4.进行一些基本配置,测试启动postfix并进行发信
# vim /etc/postfix/main.cf
修改以下几项为您需要的配置
myhostname = mail.magedu.com
myorigin = magedu.com
mydomain = magedu.com
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.1.0/24, 127.0.0.0/8
说明:
myorigin参数用来指明发件人所在的域名,即做发件地址伪装;
mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
mydomain 参数指定您的域名,默认情况下,postfix将myhostname的第一部分删除而作为mydomain的值;
mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
inet_interfaces 参数指定postfix系统监听的网络接口;
注意:
(1)、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
(2)、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;
(3)、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;
(4)、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
5.为postfix提供SysV服务脚本/etc/rc.d/init.d/postfix
这里我们用了原来的老版的rpm包的启动文件postfix-2.3.3-2.3.el5_6.i386.rpm
rpm2cpio postfix-2.3.3-2.3.el5_6.i386.rpm | cpio -id将其解压
然后cp etc/rc.d/init.d/postfix ~/为配置使用
将实现准备好的postfix 拷贝到/etc/rc.d/init.d/postfix
然后chkconfig --add postfix
    chkconfig postfix on
在启动之前请确定本机是否安装sendmail如果有请关闭并卸载
然后启动服务
service postfix start
6.检验postfix是否支持Dovecot SASL 
 
postconf -a

 

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_02

结果显示dovecot,说明支持。
 
其它postconf命令: 
postconf -n 
postconf -m 
postconf -d
 
7.测试,在测试之前,修改下配置文件
修改/etc/postfix/main.cf一下内容
mydomain =magedu.com
myhostname = mail.magedu.com
inet_interfaces =$myhostname, localhost
mynetworks =172.16.0.0/16 , 127.0.0.0/8
myorigin =$mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,mail.$mydomain, www.$mydomain
然后确定你是否安装dns服务器,对域名进行解析,详情请见http://5142926.blog.51cto.com/5132926/910402
8.测试
添加用户suse,redhat,gentoo用于测试
在此之前,不要忘记,生成/etc/aliases的db文件
postalias  /etc/aliases
(1).普通测试

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_03

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_04

(2).别名测试
在上面的/etc/aliases中最后一行添加
然后重新声称以下aliases的db文件

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_05

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_06

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_07

重启服务
(3).限制测试
postfix内置了多种反垃圾邮件的机制,其中就包括“客户端”发送邮件限制。
postfix的默认配置如下:
smtpd_client_restrictions =
smtpd_data_restrictions =
smtpd_end_of_data_restrictions =
smtpd_etrn_restrictions =
smtpd_helo_restrictions =
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination
smtpd_sender_restrictions =
这里以禁止172.16.132.1(本机windows通过cmd访问)这台主机通过工作在172.16.131.1上的postfix服务发送邮件为例演示说明其实现过程。访问表使用hash的格式。
编辑文件/etc/postfix/access作为访问控制文件,在其后追加一行172.16.131.1 REJECT
然后生成/etc/postfix/access的db文件postmap /etc/postfix/access,而后修改主配置文件中的smtpd_client_restrictions选项
加上smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
 

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_08

二、安装dovecot 
官网:http://dovecot.org,目前稳定版为dovecot 2.1.8。
tar -zxvf dovecot-2.1.8.tar.gz
cd dovecot-2.1.8
./configure --with-sql --with-mysql --with-ssl=openssl --with-pam
make
make install
由于mysql是编译安装,所以dovecot这里我门也采取编译安装,dovecot依赖两个包,一个是mysql另一个是perl-DBD-MySQL,这里我们安装的是perl-DBD-MySQL-4.014-1.el5.rfx.i386.rpm(切记安装covecot时,系统时间要与物理时间一致,否则configure的时候会出错)
配置服务文件,其服务文件在加压后目录中的doc目录中
cp dovecot-initd.sh /etc/rc.d/init.d/dovecot
chkconfig --add dovecot
chkconfig dovecot on
其配置文件样本在dovecot-2.1.8/doc/example-config/dovecot.conf同理其他dovecot配置文件
cp dovecot.conf /usr/local/etc/dovecot/dovecot.conf
cp -R conf.d/ /usr/local/etc/dovecot/
三、为postfix开启基于cyrus-sasl的认证功能
由上面的postconf -a中我们可以看到postfix支持cyrus
#vim /etc/postfix/main.cf
添加以下内容:
############################CYRUS-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
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner = Welcome to our $myhostname ESMTP,maked by qinqin(欢迎语,可自定义)
然后vim /usr/lib/sasl2/smtpd.conf添加以下内容:
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
重载文件,重启服务,然后出现一下界面即表示成功

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_09

四、安装Courier authentication library
1、courier简介
courier-authlib是Courier组件中的认证库,它是courier组件中一个独立的子项目,用于为Courier的其它组件提供认证服务。其认证功能通常包括验正登录时的帐号和密码、获取一个帐号相关的家目录或邮件目录等信息、改变帐号的密码等。而其认证的实现方式也包括基于PAM通过/etc/passwd和/etc/shadow进行认证,基于GDBM或DB进行认证,基于LDAP/MySQL/PostgreSQL进行认证等。因此,courier-authlib也常用来与courier之外的其它邮件组件(如postfix)整合为其提供认证服务。
这里我们用的是courier-authlib-0.63.1版本
2、编译安装
tar jxvf courier-authlib-0.63.1.20111230
然后cd到courier-authlib-0.63.1.20111230
./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc --without-authpam --without-authshadow --without-authvchkpw --without-authpgsql --with-authmysql --with-mysql-libs=/usr/local/mysql/lib --with-mysql-includes=/usr/local/mysql/include --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc --with-mailuser=postfix --with-mailgroup=postfix --with-ltdl-lib=/usr/lib --with-ltdl-include=/usr/include
然后make
最后make install
3、安装完成后修改/usr/local/courier-authlib/var/spool/authdaemon权限,使其能够正常运行
chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
将官方提供给我们的样板authdaemonrc和authmysqlrc拷贝一下
cp /etc/authdaemonrc.dist  /etc/authdaemonr
cp /etc/authmysqlrc.dist  /etc/authmysqlrc
然后修改/etc/authdaemonrc 文件
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
修改authmysqlrc配置mysql
 
编辑/etc/authmysqlrc 为以下内容,其中2001,2001 为postfix 用户的UID和GID。
MYSQL_SERVER localhost
MYSQL_PORT 3306                   (指定你的mysql监听的端口,这里使用默认的3306)
MYSQL_USERNAME  extmail      (这时为后文要用的数据库的所有者的用户名)
MYSQL_PASSWORD extmail        (密码)
MYSQL_SOCKET  /tmp/mysql.sock
MYSQL_DATABASE  extmail
MYSQL_USER_TABLE  mailbox
MYSQL_CRYPT_PWFIELD  password
MYSQL_UID_FIELD  '2001'
MYSQL_GID_FIELD  '2001'
MYSQL_LOGIN_FIELD  username
MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)
MYSQL_NAME_FIELD  name
MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)
4、提供服务脚本
将官方提供给我门的样板脚本,拷贝到/etc/rc.d/init.d/中
cd
cd courier-authlib-0.63.1.20111230
cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib
chmod 755 /etc/init.d/courier-authlib
chkconfig --add courier-authlib
chkconfig courier-authlib on
5、最后配置postfix和courier-authlib
 
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
mkdir –pv /var/mailbox(即上面配置文件中的MYSQL_HOME_FIELD)
chown –R postfix /var/mailbox
然后修改/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
五、让postfix支持虚拟域和虚拟用户
这里需要用到extman-1.1
Extman是Extmail项目组在推出Extmail WebMail之后,推出的一个用来管理Extmail虚拟账号的管理软件
1.编辑postfix主配置文件
########################Virtual Mailbox Settings########################
virtual_mailbox_base = /var/mailbox
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:2525
virtual_gid_maps = static:2525
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
##########################QUOTA Settings########################
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 Tidy your mailbox and try again later.
virtual_overquota_bounce = yes
2.在这里数据库就不用我们创建了,官方为我们提供的有
2、使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库:
tar zxvf  extman-1.1.tar.gz
cd extman-1.1/docs
mysql -u root -p < extmail.sql(这里会报错,因为mysql5.5之后就不支持TYPE了,改为ENGINE,用sed命令sed -i 's/TYPE=MyISAM/ENGINE=MyISAM/g' extmail.sql)
mysql -u root -p <init.sql

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_10

cp mysql*  /etc/postfix/
为extmail用户授权
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO extmail@127.0.0.1 IDENTIFIED BY 'extmail';(以防万一,这两个都要授权)
另:启用虚拟域以后,需要取消中心域,即在主配置文件中注释掉myhostname, mydestination, mydomain, myorigin几个指令;当然,你也可以把mydestionation的值改为你自己需要的。

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_11

六、配置dovecot
由于最新版的dovecot的配置文件跟以往有很大的不同,所以这里我们需要查看很多
首先是conf.d/10-mail.conf
设置其mail_location = maildir:/var/mailbox/%d/%n/Maildir
其次是conf.d/10-auth.conf
设置其aauth_mechanisms = plain(默认好像就是这个)
最后是conf.d/auth-sql.conf.ext
先cp auth-sql.conf.ext auth-sql.conf
设置其auth default {
    passdb sql {
        args = /usr/local/etc/dovecot/dovecot-mysql.conf
    }
    userdb sql {
        args = /usr/local/etc/dovecot/dovecot-mysql.conf
    }
将官方提供的dovecot-mysql.conf.ext拷贝到上面所填目录下
然后对其进行修改
driver = mysql
connect = host=localhost dbname=extmail user=extmail password=extmail
default_pass_scheme = CRYPT
password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'                            
user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'
另:如果mysql服务器是本地主机,即host=localhost时,如果mysql.sock文件不是默认的/var/lib/mysql/mysql.sock,可以使用host=“sock文件的路径”来指定新位置;
然后启动服务,若提示ssl错误,则修改conf.d/10-ssl.conf中的路径,并为其创建个私钥认证即可,详情
若提示这个错误则说明是因为你的电脑不支持ipv6,所以在主配置文件中将其改为listen = *,就是将代表ipv6的::去掉

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_12

七、安装Extmail-1.2
1、安装
tar zxvf extmail-1.2.tar.gz
mkdir -pv /web/vhosts/extsuite
mv extmail-1.2 /web/vhosts/extsuite/extmail
cp /web/vhosts/extsuite/extmail/webmail.cf.default  /web/vhosts/extsuite/extmail/webmail.cf
2、修改主配置文件
vim /web/vhosts/extsuite/extmail/webmail.cf
另:如果extmail的放置路径做了修改,那么配置文件webmail.cf中的/var/www路径必须修改为你所需要的位置。本文使用了默认的/web/vhosts,所以,以下示例中并没有包含路径修改的相关内容。
部分修改选项的说明:
SYS_USER_LANG = en_US
语言选项,可改作:
SYS_USER_LANG = zh_CN
SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox
SYS_MYSQL_USER = db_user
SYS_MYSQL_PASS = db_pass
以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为:
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
此句用来指明authdaemo socket文件的位置,这里修改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket(这里大家应该还记得上面我们改过权限的)
3.apache相关配置
由于extmail要进行本地邮件的投递操作,故必须将运行apache服务器用户的身份修改为您的邮件投递代理的用户;本例中打开了apache服务器的suexec功能,故使用以下方法来实现虚拟主机运行身份的指定。此例中的MDA为postfix自带,因此将指定为postfix用户:
<VirtualHost *:80>
     ServerName mail.magedu.com
     DocumentRoot /web/vhost/extsuite/extmail/html/
     ScriptAlias /extmail/cgi /web/vhosts/extsuite/extmail/cgi
     Alias /extmail /web/vhosts/extsuite/extmail/html
     <Directory "/web/vhosts/extsuite/extmail/html">
     Options Indexes
     AllowOverride none
     Require all granted
     </Directory>
     ErrorLog "/var/log/httpd/error_log"
     CustomLog "/var/log/httpd/access_log" combined
</VirtualHost>
修改 cgi执行文件属主为postfix
chown -R postfix.postfix /web/vhosts/extsuite/extmail/cgi/
4、依赖关系的解决
extmail将会用到perl的Unix::syslogd功能,可以去http://search.cpan.org搜索下载原码包进行安装。
tar zxvf Unix-Syslog-1.1.tar.gz
cd Unix-Syslog-1.1
perl Makefile.PL
make
make install
service httpd start
chkconfig httpd on
八、安装Extman-1.1
1.安装及基本配置
tar zxvf  extman-1.1.tar.gz
mkdir /web/vhosts/extsuite/extman
mv extman-1.1 /web/vhosts/extsuite/extman
修改配置文件以符合本例的需要:
cp /web/vhosts/extsuite/extman/webman.cf.default  /web/vhosts/extsuite/extman/webman.cf
vim /web/vhosts/extsuite/extman/webman.cf
另:其中配置文件中的路径/var/www改为/web/vhosts
SYS_MAILDIR_BASE = /home/domains
此处即为之前文所设置的用户邮件的存放目录,将其改为:
SYS_MAILDIR_BASE = /var/mailbox
 
SYS_DEFAULT_UID = 1000
SYS_DEFAULT_GID = 1000
此两处后面设定的ID号需更改为前而创建的postfix用户和postfix组的id号,本文使用的是2001,所以将其修改为:
SYS_DEFAULT_UID = 2001
SYS_DEFAULT_GID = 2001
 
SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman
修改为:
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
 
SYS_CAPTCHA_ON = 1
修改为
SYS_CAPTCHA_ON = 0
 
而后修改cgi目录的属主:
chown -R postfix.postfix /web/vhosts/extsuite/extman/cgi/
创建其运行时所需的临时目录,并修改其相应的权限:
mkdir  -pv  /tmp/extman
chown postfix.postfix  /tmp/extman
好了,重新启动apache服务器,Webmail和Extman已经可以使用了,可以在浏览器中输入指定的虚拟主机的名称进行访问http://mail.magedu.com
选择管理即可登入extman进行后台管理了。默认管理帐号为:root@extmail.org  密码为:extmail*123*
 
另:
(1) 如果您安装后无法正常显示校验码,安装perl-GD模块会解决这个问题。如果想简单,您可以到以下地址下载适合您的平台的rpm包,安装即可:  http://dries.ulyssis.org/rpm/packages/perl-GD/info.html
(2) extman-1.1自带了图形化显示日志的功能;此功能需要rrdtool的支持,您需要安装此些模块才可能正常显示图形日志。

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_13

http2.4.2+mysql5.5.24+postfix2.9.3_POSTFIX_14