邮件服务系列-- postifx+sasl+dovecot+webmail+webmain架构

 
文章内容:介绍的是邮件服务系列配置中 postifx+sasl+dovecot+虚拟域+虚拟用户+webmail+webman综合实现
首先来解释下邮件服务大概流程,如图:

 具体的示意图(权威版的)

 
首先先来扫下盲,介绍下图中字母的意思:
1. SMTP:Simple Mail Tansfer Protocol 邮件传输协议 
2. SMTPD: 邮件传输服务器端 
3. MUA:邮件用户代理 mail user agent  
4.               传送给SMTPD(MTA:transfer agent)如果是本地调用lmtp localmail tp协议 
5.                                                  如果不是调用SMTP,然后~  
6. MDA:mail delivery agent邮件投递代理 
7.                             当邮件到达本地*D的时候,则调用自己的MDA传送给用户邮筒中 
8. SASL: Simple Authinitication Secure Layer, 简单认证安全层 
9. DOVECOT:中文成为鸽子笼,也就是邮箱的意思 
 
 

实验过程简介图: 

 
安装前的准备工作
配置yum库后安装开发工具与开发库

[root@localhost ~]# yum groupinstall "Development Tools" "Development Libraries" –y

安装实验中所有依赖的软件包(这些都是在编译的时候报错时报告所依赖的;所以这里就直接安装了,这些包在红帽系统自身带的就有)

#yum install httpd openssl-devel perl-DBD-MySQL, tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect(主机间通信)

这些安装包是在后面进行相关软件中需要依赖的,这里就直接安装了(怕遇到问题的提前安装,到具体过程笔者再讲述他们的依赖关系)
 
 

DNS配置
前提:要提前安装httpd,后边要用到,并且这个步骤要用到测试:

1.     [root@localhost ~]# yum install httpd -y  

2. ##红帽5.8上面有新版本bind97,但是已经安装了bind93,所以这里先卸载bind93  

3. [root@localhost ~]# rpm -e bind-utils bind-libs  

4. [root@localhost ~]# yum install bind97 bind97-libs bind97-utils –y  

5.    
6. 修改named.conf配置文件 
7. 修改options中定义的初始的几个片段,保留以下内容 
8. options {  

9.         directory       "/var/named";  

10.        dump-file       "/var/named/data/cache_dump.db";  

11.        statistics-file "/var/named/data/named_stats.txt";  

12.        memstatistics-file "/var/named/data/named_mem_stats.txt";  

13.        recursion yes;  

14.   
15.   

16.        /* Path to ISC DLV key */  

17.        bindkeys-file "/etc/named.iscdlv.key";  

18.};  
19.##然后在下面添加zone  
20.   

21.zone "doubao.com"       {  

22.        type master;  

23.        file "doubao.com.zone";  

24.        };  

25.zone "111.16.172.in-addr.arpa" {  

26.        type master;  

27.        file "172.16.111.zone";  

28.        };  

29.:wq 保存退出 
 
然后去编辑正向、反向区域配置文件
 
1.  

2. [root@localhost ~]# vim /var/named/doubao.com.zone  

3. ##//添加内容: 
4. $TTL 86400  

5. @       IN      SOA     ns.doubao.com. admin.doubao.com. (  

6.                         2013042801  

7.                         2H  

8.                         5M  

9.                         3D  

10.                        7D )  

11.        IN      NS      ns  

12.        IN      MX 10   mail  

13.ns      IN      A       172.16.111.3  

14.mail    IN      A       172.16.111.3  

15.www     IN      A       172.16.111.3  

16.:wq  
17.   
18.   

19.[root@localhost ~]# vim /var/named/172.16.111.zone  

20.##//添加内容: 
21.   
22.$TTL 86400  

23.        IN      SOA     ns.doubao.com. admin.doubao.com. (  

24.                        2013042801  

25.                        2H  

26.                        5M  

27.                        3D  

28.                        7D )  

29.        IN      NS      ns.doubao.com.  

30.3       IN      PTR     ns.doubao.com.  

31.3       IN      PTR     mail.doubao.com.  

32.3       IN      PTR     www.doubao.com.  

 
修改权限、添加开机启动服务

1. [root@localhost named]# chgrp named doubao.com.zone  

2. [root@localhost named]# chgrp named 172.16.111.zone  

3. [root@localhost named]# chmod 640 doubao.com.zone   

4. [root@localhost named]# chmod 640 172.16.111.zone  

5. [root@localhost named]# chkconfig --add named  

6. [root@localhost named]# chkconfig named on  

7.  [root@localhost named]# chkconfig --list named  

8. named           0:off   1:off   2:on    3:on    4:on    5:on    6:off  

 
修改resolv.conf配置文件中默认DNS

1. [root@localhost named]# vim /etc/resolv.conf   

2. ##//修改成如下所示 
3. nameserver 172.16.111.3  
4. search localdomain  
 
更改主机名(与mail服务器域名保持一致)

1. [root@localhost named]# vim /etc/sysconfig/network  

2.    
3. NETWORKING=yes 
4. NETWORKING_IPV6=yes 
5. HOSTNAME=mail.doubao.com  
6. GATEWAY=172.16.0.1  
7. :wq 保存退出 

8. [root@localhost named]# vim /etc/hosts  

9. [root@localhost named]# hostname mail.doubao.com  

10.[root@localhost named]# hostname  

11.mail.doubao.com  
12.##//编辑Hosts文件。去增加主机名: 

13.[root@mail httpd]# vim /etc/hosts  

14.172.16.111.3    mail.doubao.com  

15.然后启动DNS服务器 

16.[root@mail httpd]# service httpd start  

17.Starting httpd:                                            [ OK ]  

18.[root@mail httpd]# service named restart  

19.Starting named:                                            [ OK ]   

20.   
21.然后到物理机的hosts文件修改,增加解析路径能打开网页测试  

22.    文件路径:C盘àWindowsàSystem32àdriversàetcàhosts  

23.    172.16.111.3    mail.doubao.com  

 
然后打开IE,输入172.16.111.3或者mail.doubao.com来测试下网页
 

 


安装mysql
前提:需要安装perl-DBD-MySQL

1. [root@mail httpd]# yum install perl-DBD-MySQL  

2. ##使用的是系统自带rpm包 

3. [root@mail httpd]# yum install mysql-server mysql-devel –y  

4.    
5. ##启动mysql数据库 

6. [root@mail httpd]# service mysqld start  

连接测试
 

 


编译安装postfix
关闭sedmail
红帽5.8系统上sendmail服务默认是开启的需要手动关闭它,它会影响postfix的服务的运行

1. [root@mail httpd]# service sendmail stop  

2. Shutting down sm-client:                                   [ OK ]  

3. Shutting down sendmail:                                    [ OK ]  

4. [root@mail httpd]# chkconfig sendmail off  

创建postfix用户postfix组以及postdrop用户postdrop组

1. [root@mail httpd]# groupadd -g 2525 postfix  

2. [root@mail httpd]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix  

3. [root@mail httpd]# groupadd -g 2526 postdrop  

4. [root@mail httpd]# useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop  

使用的源码包版本是postfix-2.9.6,在编译安装的之前要使用date命令查看一下自己系统的的时间;因为在虚拟机中的linux系统很多都是挂起的,会导致时间错误;如果软件包的开发时间在系统时间的后面,这会让我们的系统变得凌乱的
1. [root@mail httpd]# hwclock –s ##//将硬件时间同步到系统时间 
2. ##开始编译(事先将postfix-2.9.6.tar.gz放入linux中)  

3. [root@mail ~]# cd /usr/local/src  

4. [root@mail src]# tar xf postfix-2.9.6.tar.gz  

5. [root@mail src]# 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'  

6. [root@mail src]# make && make install  

7. ##在执行make install命令后,会让选择一些默认的路径的安装位置:(下面跟实验过程中的顺序也许会有点不一样) 
8.   install_root: [/] /  ------postfix安装路径 
9.   tempdir: [/root/postfix-2.9.3] /tmp/postfix   ------临时文件的生成目录 
10.  config_directory: [/etc/postfix] /etc/postfix -------配置文件目录 
11.  daemon_directory: [/usr/libexec/postfix]    -------服务进程目录 
12.  command_directory: [/usr/sbin]   ------bash命令目录 
13.  queue_directory: [/var/spool/postfix] ---邮件队列 
14.  sendmail_path: [/usr/sbin/sendmail] ---smtp的客户端,用于实现与sendmail客户端兼容的 
15.  newaliases_path: [/usr/bin/newaliases] ---生成新别名 
16.  mailq_path: [/usr/bin/mailq] ---邮件队列程序 
17.  mail_owner: [postfix] ---邮件服务器的运行者 
18.  setgid_group: [postdrop]   ---用于实现将用户的邮件投递到它的邮箱中去的 
19.    html_directory: [no]/var/www/html/postfix  ---当web服务器没有配置好就使用no选项 
20.manpages: [/usr/local/man] ---man文档的安装路径 
21.readme_directory: [no] ---帮助文档 
22.    data_directory:[/var/lib/postfix]                 ---可读写文件的存放路径 
23.生成别名二进制文件: 

24.[root@mail src]# newaliases  

25.##newaliases 的功能传是将 /etc/aliases 转换成其所能理解、处理的数据库 
准备postfix服务脚本
为postfix提供SysV服务脚本/etc/rc.d/init.d/postfix,内容如下(#END 之前):

1. [root@mail src]# vim /etc/rc.d/init.d/postfix  

2. ##//内容 
3. #!/bin/bash  
4. #  

5. # postfix      Postfix Mail Transfer Agent  

6. #  

7. # chkconfig: 2345 80 30  

8. # description: Postfix is a Mail Transport Agent, which is the program \  

9. #              that moves mail from one machine to another.  

10.# processname: master  

11.# pidfile: /var/spool/postfix/pid/master.pid  

12.# config: /etc/postfix/main.cf  

13.# config: /etc/postfix/master.cf  

14.   

15.# Source function library.  

16.. /etc/rc.d/init.d/functions  
17.   

18.# Source networking configuration.  

19.. /etc/sysconfig/network  
20.   

21.# Check that networking is up.  

22.[ $NETWORKING = "no" ] && exit 3  

23.   

24.[ -x /usr/sbin/postfix ] || exit 4  

25.[ -d /etc/postfix ] || exit 5  

26.[ -d /var/spool/postfix ] || exit 6  

27.   
28.RETVAL=0 
29.prog="postfix" 
30.   
31.start() {  

32.       # Start daemons.  

33.       echo -n $"Starting postfix: "  

34.        /usr/bin/newaliases  >/dev/null 2 >&1  

35.       /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog   

36.start"  
37.       RETVAL=$?  

38.       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix  

39.        echo  

40.       return $RETVAL  

41.}  
42.   
43.stop() {  
44. # Stop daemons.  

45.       echo -n $"Shutting down postfix: "  

46.       /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog   

47.stop"  
48.       RETVAL=$?  

49.       [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix  

50.       echo  

51.       return $RETVAL  

52.}  
53.   
54.reload() {  

55.       echo -n $"Reloading postfix: "  

56.       /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog   

57.reload"  
58.       RETVAL=$?  

59.       echo  

60.       return $RETVAL  

61.}  
62.   
63.abort() {  

64.       /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog   

65.abort"  

66.       return $?  

67.}  
68.   
69.flush() {  

70.       /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog   

71.flush"  

72.       return $?  

73.}  
74.   
75.check() {  

76.       /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog   

77.check"  

78.       return $?  

79.}  
80.   
81.restart() {  

82.       stop  

83.       start  

84.}  
85.   

86.# See how we were called.  

87.case "$1" in  
88. start)  

89.       start  

90.       ;;  

91. stop)  

92.       stop  

93.       ;;  

94. restart)  

95.       stop  

96.       start  

97.       ;;  

98. reload)  

99.       reload  

100.               ;;  

101.         abort)  

102.               abort  

103.               ;;  

104.         flush)  

105.               flush  

106.               ;;  

107.         check)  

108.               check  

109.               ;;  

110.         status)  

111.             status master  

112.               ;;  

113.         condrestart)  

114.               [ -f /var/lock/subsys/postfix ] && restart || :  

115.               ;;  

116.         *)  

117.               echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|  

118.        condrestart}"  

119.               exit 1  

120.        esac  

121.           

122.        exit $?  

123.           

124.        # END  

为此脚本赋予执行权限、将postfix服务添加至服务列表、开机自动启动

1. [root@mail src]# chmod +x /etc/rc.d/init.d/postfix  

2. [root@mail src]# chkconfig --add postfix  

3. [root@mail src]# chkconfig postfix on  

 
编辑postfix的配置文件main.cf,修改以下几项为您需要的配置
1. myhostname = mail.doubao.com ##------指定自己的邮件服务器 
2. myorigin = doubao.com ##------自己创建的域名 
3. mydomain = doubao.com ##-----定义出站邮件使用的域名 
4. mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ##定义哪些域接收邮件 
5. mynetworks = 192.168.1.0/24, 127.0.0.0/8   ##--------定义允许中继的网络 
 
启动postfix、进行测试

1. [root@mail src]# service postfix start  

2. Starting postfix:                                          [ OK ]  

创建一个用户用于测试邮件的收发

1. [root@mail src]# useradd hadoop && echo "hadoop" |passwd --stdin hadoop  

连接到邮件服务器进行测试发送

1. [root@mail src]# telnet mail.doubao.com 25  

 

查看邮件是否接收
 

 


配置dovecot
安装dovecot软件包

1. [root@mail ~]# yum install dovecot -y  

2. ##更改protocols保留需要的协议 

3. [root@mail ~]# vim /etc/dovecot.conf  

4. ##添加dovecot到服务列表并启动dovecot服务 

5. [root@mail ~]# chkconfig --add dovecot  

6. [root@mail ~]# chkconfig dovecot on  

7. [root@mail ~]# chkconfig --list dovecot  

8. dovecot           0:off       1:off       2:on 3:on 4:on 5:on 6:off  

9. [root@mail ~]# service dovecot start  

10.测试邮件的是否可以成功接受 

11.[root@mail ~]# telnet mail.doubao.com 25  

 

到这里 就要开启虚拟机window 2003 登录上去设置好IP地址(172.16网段的)
然后进行收邮件的实验:
 

 

 

 

 

 
 
然后完成查看收件箱

这样。就完成了邮件的收发
 


为postfix开启基于cyrus-sasl的认证功能
编辑saslauthd配置文件,用来使用sasl认证

1. [root@mail ~]# vim /etc/sysconfig/saslauthd  

2. ##//将内容做一下修改 
3. MECH=shadow ##//把原来的pam改成shadow,让其从/etc/shadow中检索账号 
4.    
5. 将其添加到服务列表中,并启动测试 

6. [root@mail ~]# chkconfig --add saslauthd  

7. [root@mail ~]# chkconfig saslauthd on  

8. [root@mail ~]# chkconfig --list saslauthd  

9. saslauthd          0:off    1:off    2:on 3:on 4:on 5:on 6:off  

10.[root@mail ~]# service saslauthd start  

11.Starting saslauthd:                                        [ OK ]  

12.##//做一下检索账号的测试 

13.[root@mail ~]# testsaslauthd -uhadoop -phadoop  

14.0: OK "Success."  

 
编辑sasl配置文件smtpd.conf
注:这里Postfix是借助SASL来提供认证功能,SASL为其提供一个smtpd.conf配置文件。这里要进行配置。

1. [root@mail ~]# vim /usr/lib/sasl2/smtpd.conf  

2. ##//添加如下内容 
3. pwcheck_method: saslauthd    ##让postfix知道要通过saslauthd来实现用户认证 
4. mech_list: PLAIN LOGIN ##真正要完成认证的功能是谁 
5. 保存退出。 
6. ##//这个时候需要重启下让其生效 
编辑postfix配置文件

1. [root@mail ~]# vim /etc/postfix/main.cf  

2. ##//添加如下内容 

3. ############################CYRUS-SASL############################  

4. broken_sasl_auth_clients = yes 

5. 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  

6. smtpd_sasl_auth_enable = yes 
7. smtpd_sasl_local_domain = $myhostname  
8. smtpd_sasl_security_options = noanonymous 
9. smtpdsmtpd_sasl_path = smtpd  

10.smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!  

11.保存退出 
 
让postfix重新加载配置文件

1. [root@mail ~]# /usr/sbin/postfix reload  

2. postfix/postfix-script: refreshing the Postfix mail system  

然后进行测试:
 

 


邮件服务系列之虚拟域、虚拟用户和webmail与webman的实现
编译安装courier-authlib
PS:这里使用的是courier-authlib-0.64.0.tar,请事先下载好放入linux中

1. [root@mail ~]# tar xf courier-authlib-0.64.0.tar.bz2  

2. [root@mail ~]# cd courier-authlib-0.64.0  

3. [root@mail courier-authlib-0.64.0]# ./configure \  

4.     --prefix=/usr/local/courier-authlib \   -----文件的安装路径 
5.     --sysconfdir=/etc \   -----配置文件的安装位置 

6.     --without-authpam \  

7.     --without-authshadow \  

8.     --without-authvchkpw \  

9.     --without-authpgsql \   -----不支持pam/shadow/vchkpw/pgsql认证,这些选项不添加也可以 
10.    --with-authmysql \   ----支持mysql认证(重要就是支持者一项) 
11.    --with-mysql-libs=/usr/lib/mysql \   ------指明mysql的库文件路径的安装位置 
12.    --with-mysql-includes=/usr/include/mysql \ -------指明mysql的头文件的安装路径 
13.    --with-redhat \ ------说明系统类型 
14.    --with-authmysqlrc=/etc/authmysqlrc \ -----指定courier-authlib服务进程配置文件路径 
15.    --with-authdaemonrc=/etc/authdaemonrc \ -----守护进程,courier-authlib服务进程的配置文件 
16.    --with-mailuser=postfix \ ----邮件收发管理的用户 
17.    --with-mailgroup=postfix \ -----邮件收发管理的组 
18.    --with-ltdl-lib=/usr/lib \ -----ltdl动态模块加载器,提供一个运行环境(对应了刚开始安装的yum包) 
19.    --with-ltdl-include=/usr/include ----ltdl文件的头文件路径 

20.[root@mail courier-authlib-0.64.0]# make && make install  

 
改socket文件的权限

1. [root@mail ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon  

把生成的配置文件重新命名

1. [root@mail ~]# cp /etc/authdaemonrc.dist /etc/authdaemonrc  

2. [root@mail ~]# cp /etc/authmysqlrc.dist /etc/authmysqlrc  

修改/etc/authdaemonrc配置文件

1. [root@mail ~]# vim /etc/authdaemonrc  

2. authmodulelist="authmysql" -----指明认证的模块 
3. authmodulelistorig="authmysql" ------保留的原始模块 
4. daemons=10 ------默认启动启动的进程个数(根据需要修改) 
5. DEBUG_LOGIN=2 
编辑/etc/authmysqlrc配置文件
1.    
2. ##配置其通过mysql进行邮件帐号认证 
3. MYSQL_SERVER localhost   
4. MYSQL_PORT 3306                   -----(指定你的mysql监听的端口,这里使用默认的3306)  
5. MYSQL_USERNAME extmail     ----- (这时为后文要用的数据库的所有者的用户名)  
6. MYSQL_PASSWORD extmail       ----- (密码)  

7. MYSQL_SOCKET /var/lib/mysql/mysql.sock  

8. MYSQL_DATABASE extmail  
9. MYSQL_USER_TABLE mailbox  
10.MYSQL_CRYPT_PWFIELD password -----mysql中哪个字段是用户密码 
11.MYSQL_UID_FIELD '2525'  
12.MYSQL_GID_FIELD '2525'  
13.MYSQL_LOGIN_FIELD username  
14.MYSQL_HOME_FIELD concat('/var/mailbox/',homedir) -----用户账号的家目录所在位置,虚拟用户没有家目录,homedir是变量,等同于用户名称;concat是mysql内置的函数用于将两个字符串连接起来 
15.MYSQL_NAME_FIELD name  

16.MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir)  

 
提供SysV服务脚本,为服务脚本添加执行权限并且添加到服务列表,设置开机启动并启动
1.    

2. [root@mail ~]# cd courier-authlib-0.64.0  

3. [root@mail courier-authlib-0.64.0]# cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib  

4. [root@mail courier-authlib-0.64.0]# chmod 755 /etc/init.d/courier-authlib  

5. [root@mail courier-authlib-0.64.0]# chkconfig --add courier-authlib  

6. [root@mail courier-authlib-0.64.0]# chkconfig --level 2345 courier-authlib on  

7. [root@mail courier-authlib-0.64.0]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf  

8. [root@mail courier-authlib-0.64.0]# service courier-authlib start  

9. Starting Courier authentication services: authdaemond  

 
配置postfix和courier-authlib
 
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户

1. [root@mail ~]# mkdir –pv /var/mailbox  

2. [root@mail ~]# chown -R postfix /var/mailbox  

 

接下来重新配置SMTP 认证,编辑 /usr/lib/sasl2/smtpd.conf ,

1. [root@mail ~]# vim /usr/lib/sasl2/smtpd.conf   

2. ##确保其为以下内容 
3. pwcheck_method: authdaemond  
4. log_level: 3  
5. mech_list: PLAIN LOGIN  

6. authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket  

 
 
让postfix支持虚拟域和虚拟用户
编辑/etc/postfix/main.cf,

1. [root@mail ~]# vim /etc/postfix/main.cf  

2. ##//添加如下内容: 

3. ########################Virtual Mailbox Settings########################  

4. virtual_mailbox_base = /var/mailbox  

5. virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf  

6. virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf  

7. virtual_alias_domains =  

8. virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf  

9. virtual_uid_maps = static:2525  
10.virtual_gid_maps = static:2525  
11.virtualvirtual_transport = virtual  
12.maildrop_destination_recipient_limit = 1 
13.maildrop_destination_concurrency_limit = 1 

14.##########################QUOTA Settings########################  

15.message_size_limit = 14336000 
16.virtual_mailbox_limit = 20971520 
17.virtual_create_maildirsize = yes 
18.virtual_mailbox_extended = yes 

19.virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf  

20.virtual_mailbox_limit_override = yes 

21.virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later.  

22.virtual_overquota_bounce = yes 
23.##保存退出 
 
使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库
 
1. [root@mail ~]# tar xf extman-1.1.tar.gz ------事先准备~  

2. [root@mail ~]# cd extman-1.1/docs/  

3. [root@mail docs]# mysql -u root -p  <  extmail.sql -----密码为空 
4. Enter password:   
5. [root@mail docs]# mysql -u root -p  <init.sql 
6. Enter password:   

7. [root@mail docs]# cp mysql* /etc/postfix/  

8. ##//启动mysql对用户进行授权 
9. [root@mail docs]# mysql  

10.Welcome to the MySQL monitor. Commands end with ; or \g.  

11.Your MySQL connection id is 5  

12.Server version: 5.0.77 Source distribution  

13.   

14.Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  

15.   

16.mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';  

17.Query OK, 0 rows affected (0.00 sec)  

18.   

19.mysql> GRANT all privileges on extmail.* TO extmail@127.0.0.1 IDENTIFIED BY 'extmail';  

20.Query OK, 0 rows affected (0.00 sec)  

 
说明:

1、启用虚拟域以后,需要取消中心域,即注释掉myhostname, mydestination, mydomain, myorigin几个指令;当然,你也可以把mydestionation的值改为你自己需要的。

2、对于MySQL-5.1以后版本,其中的服务脚本extmail.sql执行会有语法错误;可先使用如下命令修改extmail.sql配置文件,而后再执行。修改方法如下:

# sed -i 's@TYPE=MyISAM@ENGINE=InnoDB@g' extmail.sql



 
配置dovecot
 

1. [root@mail ~]# vim /etc/dovecot.conf  

2. ##需要逐个查找修改 
3. mail_location = maildir:/var/mailbox/%d/%n/Maildir  
4. auth default {  
5.     mechanisms = plain 

6.     passdb sql {  

7.         args = /etc/dovecot-mysql.conf  
8.     }  

9.     userdb sql {  

10.        args = /etc/dovecot-mysql.conf  
11.    }  
12.   
13.   

14.[root@mail ~]# vim /etc/dovecot-mysql.conf  

15.##添加如下内容                 

16.driver = mysql 
17.connect = host=localhost dbname=extmail user=extmail password=extmail 
18.default_pass_scheme = CRYPT 
19.password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'   
20.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文件的路径”来指定新位置;例如,使用通用二进制格式安装的MySQL,其soc文件位置为/tmp/mysql.sock,相应地,connect应按如下方式定义。

connect = host=/tmp/mysql.sock dbname=extmail user=extmail password=extmail

 
接下来启动dovecot服务:

1. [root@mail ~]# service dovecot restart  

2. Stopping Dovecot Imap:                                     [ OK ]  

3. Starting Dovecot Imap:                                     [ OK ]  

 


安装配置Extmail-1.2
说明:如果extmail的放置路径做了修改,那么配置文件webmail.cf中的/var/www路径必须修改为你所需要的位置。本文使用了默认的/var/www,所以,以下示例中并没有包含路径修改的相关内容。
 
1、安装

1. [root@mail ~]# tar xf extmail-1.2.tar.gz   

2. [root@mail ~ ]# mkdir -pv /var/www/extsuite  

3. mkdir: created directory `/var/www/extsuite'   

4. [root@mail ~]# mv extmail-1.2 /var/www/extsuite/extmail   

5. [root@mail ~]# cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf  

 
2、修改主配置文件

1. [root@mail ~]# vim /var/www/extsuite/extmail/webmail.cf  

2.    
3. ##部分修改选项的说明: 
4.    
5. SYS_MESSAGE_SIZE_LIMIT = 5242880 ##用户可以发送的最大邮件 
6.    
7. SYS_USER_LANG = en_US 
8. ##语言选项,可改作: 
9. SYS_USER_LANG = zh_CN 
10.   
11.SYS_MAILDIR_BASE = /home/domains  
12.##此处即为您在前文所设置的用户邮件的存放目录,可改作: 
13.SYS_MAILDIR_BASE = /var/mailbox  
14.   
15.SYS_MYSQL_USER = db_user 
16.SYS_MYSQL_PASS = db_pass 
17.##以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为: 
18.SYS_MYSQL_USER = extmail 
19.SYS_MYSQL_PASS = extmail 
20.   
21.   
22.##以上用来指定验正用户登录里所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称;这里默认即可 
23.   

24.SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket  

25.##此句用来指明authdaemo socket文件的位置,这里修改为: 

26.SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket  

 
 
3、apache相关配置
 
由于extmail要进行本地邮件的投递操作,故必须将运行apache服务器用户的身份修改为您的邮件投递代理的用户;本例中打开了apache服务器的suexec功能,故使用以下方法来实现虚拟主机运行身份的指定。此例中的MDA为postfix自带,因此将指定为postfix用户:
1. ##首先在/etc/httpd/conf/httpd.conf配置文件中注释中心主机 

2. #DocumentRoot "/var/www/html"  

3. ##然后添加以下内容 
4.  <VirtualHost *:80 > 
5. ServerName mail.magedu.com  

6. DocumentRoot /var/www/extsuite/extmail/html/  

7. ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi  

8. Alias /extmail /var/www/extsuite/extmail/html  

9.  </VirtualHost> 
10.##保存退出。 
11.   
12.修改 cgi执行文件属主为apache运行身份用户: 

13.[root@mail ~]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/  

14.   

15.[root@mail ~]# vim /etc/httpd/httpd.conf  

16.##//添加如下内容 
17.User postfix  
18.Group postfix  

19.[root@mail ~]# vim /etc/httpd/conf/httpd.conf  

20.##//添加如下内容 
21. <VirtualHost *:80 > 
22.ServerName mail.magedu.com  

23.DocumentRoot /var/www/extsuite/extmail/html/  

24.ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi  

25.Alias /extmail /var/www/extsuite/extmail/html  

26. </VirtualHost> 
 
4、依赖关系的解决
 
extmail将会用到perl的Unix::syslogd功能,您可以去http://search.cpan.org搜索下载原码包进行安装。

1. [root@mail ~]# tar zxvf Unix-Syslog-1.1.tar.gz  

2. [root@mail ~]# cd Unix-Syslog-1.1  

3. [root@mail Unix-Syslog-1.1]# perl Makefile.PL  

4. [root@mail Unix-Syslog-1.1]# make && make install  

 
5、启动apache服务

1. [root@mail Unix-Syslog-1.1]# service httpd restart  

2. Stopping httpd:                                            [ OK ]  

3. Starting httpd:                                            [ OK ]  

这时候打开IE来测试下

 


现在的邮箱还不能登录没有虚拟用户,需要再次配置exman,使其能够在apache服务器访问;配置流程与extmail相似
首先创建webman用户(在webman.cf配置文件指定的默认用户)
连接mysql创建webman
1. [root@mail ~]# mysql  

2. mysql> GRANT ALL PRIVILEGES ON extmail.* TO webman@localhost IDENTIFIED BY 'webman';  

3. mysql> GRANT ALL PRIVILEGES ON extmail.* TO webman@127.0.0.1 IDENTIFIED BY 'webman';  

4. mysql > FLUSH PRIVILEGES;  

5. [root@mail ~]# mv extman-1.1 /var/www/extsuite/extman  

6. [root@mail ~]# cd /var/www/extsuite/extman/  

7. [root@mail extman]# cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf  

编辑extman配置文件

1. [root@mail extman]# vim /var/www/extsuite/extman/webman.cf  

2. ##修改内容 
3. SYS_MAILDIR_BASE = /var/mailbox 修改邮箱位置 
4. SYS_CAPTCHA_ON = 0   关闭验证码模块 
5. SYS_DEFAULT_UID = 2525 
6. SYS_DEFAULT_GID = 2525   ##更改UID与GID(是postfixUID与其组的GID  
修改完成,保存退出 创建extman运行时所需的临时目录,并修改属主属组

1. [root@mail extman]# mkdir /tmp/extman  

2. [root@mail extman]# chown postfix.postfix /tmp/extman  

修改apache配置文件,虚拟主机定义的内容最终修改如下

1. ScriptAlias /extmail/cgi /var/www/extsuite/extman/cgi  

2. Alias /extman /var/www/extsuite/extmail/html  

修改cgi目录的属主数组为postfix

1. [root@mail extman]# vim /etc/httpd/conf/httpd.conf   

2. [root@mail extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi  

修改完成后保存退出 重新启动apache服务

1. [root@mail extman]# service httpd restart  

 
 这个时候打开浏览器输入172.16.111.3/extman,就可以进入进去管理了。
PS: root@extmail.org 密码为extmail*123* 创建的过程就不在演示。