最新版本 postfix+mysql+courier-authlib+extmail+extman源码搭建邮件服务器

本文将给大家演示最新源码编译搭建邮件服务器,需要用到的包组如下,postfix-2.9.3.tar.gz,mysql-5.5.24-linux2.6-i686.tar.gz,courier-authlib.0.64.0.tar.bz2,dovecot-2.1.3.tar.gz ,extmail-1.2.tar.gz,extman-1.1.tar.gz,Unix-Syslog-1.1.tar.gz,  Time-HiRes-1.9721.tar.gz。

 
工欲善其事,必先利其器。准备工作一定要做充分,为后边的搭建成功做好保证,邮件服务器严重依赖DNS服务器,搭建好DNS服务器是必须的,这里就给出DNS的简单配置,配置邮件服务器才是重点。
 
 
  1. [root@mail ~]# vim /var/named/zzu.com.db   #正向区域及内容配置  
  2.  $TTL 600   
  3. @    IN   SOA   ns.zzu.com.    admin.zzu.com. (  
  4.                  2012071201  
  5.                  15M  
  6.                  5M  
  7.                  1W  
  8.                  1D)  
  9. @       IN NS  ns.zzu.com.  
  10.         IN MX 10 mail.zzu.com.  
  11. mail    IN A     192.168.0.100  
  12. ns      IN A  192.168.0.100  
  13. www     IN A  192.168.0.100  
  14. pop3    IN CNAME mail  
  15. smtp    IN CNAME  mail  
  16.   
  17. [root@mail ~]# vim /var/named/192.168.0.db     #反向区域及内容  
  18.  $TTL 600  
  19.  @       IN SOA    ns.zzu.com.  admin.zzu.com. (  
  20.             2012071201  
  21.             30M  
  22.             15M  
  23.             1W  
  24.             1D)  
  25.            IN   NS  ns.zzu.com.  
  26.  100       IN   PTR mail.zzu.com.  
  27.  100       IN   PTR www.zzu.com.  
除了DNS服务器,还依赖于一些rpm包,也先列举如下,用到的时候直接装上,httpd, mysql, dovecot, perl-DBD-MySQL, libtool-ltdl, libtool-ltdl-devel, expect和开发环境的rpm包组的准备 Development Libraries,Development Tools,Legacy Software Development,X Software Development。
务必修改一下主机名,邮件服务主机名很重要,到/etc/sysconfig/network下修改主机名,最好与mail服务器同名。ok!准备完成。

因为一个操作系统上不能同时有两个进程提供邮件服务,此处就关闭sendmail,使用postfix。
 
 
  1. [root@mail ~]# service sendmail stop  
  2. [root@mail ~]# chkconfig sendmail off  
  3. [root@mail ~]# service saslauthd start  
  4. [root@mail ~]# chkconfig saslauthd on  

1.编译安装mysql-5.5.24-linux2.6-i686
 
 1.1提供数据存放位置/mydata/data 新建用户以安全方式运行进程.建议把mysql安装在一个逻辑卷上,对数据的管理更加的方便。 
 
 
 
  1. [root@localhost ~]# mkdir -pv /mydata/data  
  2. mkdir: created directory `/mydata'  
  3. mkdir: created directory `/mydata/data'  
  4. [root@localhost ~]# groupadd -r mysql    #创建mysql组合用户并修改/mydata/data/所有者为mysql 
  5. [root@localhost ~]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql  
  6. [root@localhost ~]# chown -R mysql:mysql /mydata/data, 
 1.2,编译安装并初始化mysql-5.5.24
 
 
  1. [root@localhost ~]# tar xf mysql-5.5.24-linux2.6-i686.tar.gz -C   
  2. /usr/local  
  3. [root@localhost ~]# cd /usr/local  
  4. [root@localhost local]# ln -sv mysql-5.5.24-linux2.6-i686/ mysql  
  5. create symbolic link `mysql' to `mysql-5.5.24-linux2.6-i686/'  
  6. [root@localhost local]# cd mysql  
  7. [root@localhost mysql]# ls  
  8. COPYING         README  data  include  man          
  9. scripts  sql-bench  INSTALL-BINARY  bin     docs  lib      mysql-test  share   support- files  
  10. [root@localhost mysql]# chown -R mysql:mysql .  
  11. [root@localhost mysql]# scripts/mysql_install_db  --user=mysql --datadir=/mydata/data  
  12. [root@localhost mysql]# chown -R root  .  
1.3 为mysql提供主配置文件,和sysv服务脚本,方便mysql的管理。
 
 
 
  1. [root@localhost mysql]# cp support-files/my-large.cnf  /etc/my.cnf  
  2. [root@localhost mysql]# vim /etc/my.cnf   
  3. [root@localhost mysql]# cp support-files/mysql.server  /etc/rc.d/init.d/mysqld  
  4. [root@localhost mysql]# chkconfig --add mysqld  #添加服务之服务列表 
  5. [root@localhost mysql]# chkconfig mysqld on     #设置开机自动启动 
  6. [root@localhost mysql]# service mysqld start  
  7. Starting MySQL......                                    [  OK  ]  
1.4 此时只是启动了mysql服务。但是mysql命令还不能正常使用,下面为系统增加mysql的相关命令。
 
 
 
  1. [root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql  
  2. create symbolic link `/usr/include/mysql' to `/usr/local/mysql/include/'  
  3. [root@localhost mysql]# echo '/usr/local/mysql/lib/' >  /etc/ld.so.conf.d/mysql.conf  
  4. #输出mysql的库文件给系统库查找路径 
  5. [root@localhost mysql]# cat etc/ld.so.conf.d/mysql.conf  
  6. /usr/local/mysql/lib/  
  7. [root@localhost mysql]# ldconfig       #重新载入系统库 
  8. [root@localhost ~]# vim /etc/profile   #修改PATH变量,使mysql命令生效 
  9. [root@localhost ~]# export PATH=$PATH:/usr/local/mysql/bin #使PATH立即生效,最好不要使用source 
  10. [root@localhost ~]# mysql              #mysql 命令可以 正常使用 
  11. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  12. Your MySQL connection id is 1  
  13. Server version: 5.5.24-log MySQL Community Server (GPL)  
  14. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights   
  15. reserved.  
  16. Oracle is a registered trademark of Oracle Corporation and/or its  
  17. affiliates. Other names may be trademarks of their respective owners.  
  18. Type 'help;' or '\h' for help. Type '\c' to clear the  
  19. current input   
  20. statement.  
  21. mysql>   
mysql配置完毕,下面安装配置postfix-2.9.3。

 
2.编译安装postfix-2.9.3。
 
 2.1创建postfix用户和组,且指定GID最好为大于1000的数值。
 
 
  1. # groupadd -g 2525 postfix  
  2. # useradd -g postfix -u 2525 -s /sbin/nologin -M postfix  
  3. # groupadd -g 2526 postdrop  
  4. # useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop  
2.2 编译安装postfix
 
 
  1. [root@localhost ~]# tar xf postfix-2.9.3.tar.gz   
  2. [root@localhost ~]# cd postfix-2.9.3  
  3. [root@localhost postfix-2.9.3]#  make makefiles 'CCARGS=-DHAS_MYSQL - I/usr/local/mysql/include -DUSE_SASL_AUTH - DUSE_CYRUS_SASL - I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/local/mysql/lib - lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2  -lssl -lcrypto'  
  4. [root@localhost postfix-2.9.3]# make  
  5. [root@localhost postfix-2.9.3]# make  install   
  6. Please specify the prefix for installed file names. Specify this ONLY 
  7. if you are building ready-to-install packages for distribution to  
  8. OTHER 
  9. machines. See PACKAGE_README for instructions. 
  10. install_root: [/]  
  11. Please specify a directory for scratch files while installing Postfix.  
  12. You 
  13. must have write permission in this directory. 
  14. tempdir: [/root/postfix-2.9.3]  
  15. Please specify the final destination directory for installed Postfix 
  16. configuration files. 
  17. config_directory: [/etc/postfix]  
  18. Please specify the final destination directory for installed Postfix 
  19. administrative commands. This directory should be in the command  
  20. search 
  21. path of adminstrative users. 
  22. command_directory: [/usr/sbin]  
  23. Please specify the final destination directory for installed Postfix 
  24. daemon programs. This directory should not be in the command search  
  25. pathof any users. 
  26. daemon_directory: [/usr/libexec/postfix]  
  27. Please specify the final destination directory for Postfix-writable 
  28. data files such as caches or random numbers. This directory should not 
  29. be shared with non-Postfix software. 
  30. data_directory: [/var/lib/postfix]  
  31. Please specify the destination directory for the Postfix HTML 
  32. files. Specify "no" if you do not want to install these files. 
  33. html_directory: [no]  
  34. Please specify the owner of the Postfix queue. Specify an account with 
  35. numerical user ID and group ID values that are not used by any other 
  36. accounts on the system. 
  37. mail_owner: [postfix]  
  38. Please specify the final destination pathname for the installed  
  39. Postfix 
  40. mailq command. This is the Sendmail-compatible mail queue listing  
  41. command. 
  42. mailq_path: [/usr/bin/mailq]  
  43. Please specify the destination directory for the Postfix on-line  
  44. manual 
  45. pages. You can no longer specify "no" here. 
  46. manpage_directory: [/usr/local/man]  
  47. Please specify the final destination pathname for the installed  
  48. Postfix 
  49. newaliases command. This is the Sendmail-compatible command to build 
  50. alias databases for the Postfix local delivery agent. 
  51. newaliases_path: [/usr/bin/newaliases]  
  52. Please specify the final destination directory for Postfix queues. 
  53. queue_directory: [/var/spool/postfix]  
  54. Please specify the destination directory for the Postfix README 
  55. files. Specify "no" if you do not want to install these files. 
  56. readme_directory: [no]  
  57. Please specify the final destination pathname for the installed  
  58. Postfix 
  59. sendmail command. This is the Sendmail-compatible mail posting  
  60. interface. 
  61. sendmail_path: [/usr/sbin/sendmail]  
  62. Please specify the group for mail submission and for queue management 
  63. commands. Specify a group name with a numerical group ID that is 
  64. not shared with other accounts, not even with the Postfix mail_owner 
  65. account. You can no longer specify "no" here. 
  66. setgid_group: [postdrop]  
此处配置相关含义不一一解释,其含义也不难理解,路径可以自己指定,也可以选择默认。下面一定要生成二进制文件,对服务器的性能有大大的提高,不要忽略这步骤
 
 
  1. [root@localhost postfix-2.9.3]# newaliases 
 2.3 为postfix提供SysV服务脚本/etc/rc.d/init.d/postfix
 
 
  1. [root@localhost postfix-2.9.3]# vim /etc/rc.d/init.d/postfix 
  2. [root@localhost postfix-2.9.3]# chmod +x /etc/rc.d/init.d/postfix 
  3. [root@localhost postfix-2.9.3]# chkconfig  --add postfix 
  4. [root@localhost postfix-2.9.3]# chkconfig  postfix on 
  5. [root@localhost postfix-2.9.3]# service postfix start 
  6. Starting postfix:                                          [  OK  ] 
  7. [root@localhost postfix-2.9.3]#  
  8. 查看日志和开放端口 
  9. [root@localhost postfix-2.9.3]# tail /var/log/maillog 
  10. Jul 13 07:30:55 localhost postfix/postfix-script[4231]: starting the Postfix mail system 
  11. Jul 13 07:30:55 localhost postfix/master[4232]: daemon started --  
  12. version 2.9.3, configuration /etc/postfix 
查看开放端口

服务脚本代码如下
 
 
  1. #!/bin/bash  
  2. ## postfix      Postfix Mail Transfer Agent  
  3. ## chkconfig: 2345 80 30  
  4. # description: Postfix is a Mail Transport Agent, which is the program \  
  5. #  that moves mail from one machine to  
  6. another.  
  7. # processname: master  
  8. # pidfile: /var/spool/postfix/pid/master.pid  
  9. # config: /etc/postfix/main.cf  
  10. # config: /etc/postfix/master.cf  
  11.   
  12. # Source function library.  
  13. . /etc/rc.d/init.d/functions  
  14. # Source networking configuration.  
  15. . /etc/sysconfig/network  
  16. #Check that networking is up.  
  17. [ $NETWORKING = "no" ] && exit 3  
  18.   
  19. [ -x /usr/sbin/postfix ] || exit 4  
  20. [ -d /etc/postfix ] || exit 5  
  21. [ -d /var/spool/postfix ] || exit 6  
  22.  RETVAL=0  
  23. prog="postfix"  
  24.   
  25. start() {  
  26.     # Start daemons.  
  27.     echo -n $"Starting postfix: "  
  28.         /usr/bin/newaliases >/dev/null 2>&1  
  29.     /usr/sbin/postfix start 2>/dev/null 1>&2 &&  
  30.  
  31. success || failure $"$prog start"  
  32.     RETVAL=$?  
  33.     [ $RETVAL -eq 0 ] && touch  
  34.  
  35. /var/lock/subsys/postfix  
  36.         echo  
  37.     return $RETVAL  
  38. }  
  39.  stop() {  
  40.   # Stop daemons.  
  41.     echo -n $"Shutting down postfix: "  
  42.     /usr/sbin/postfix stop 2>/dev/null 1>&2 && success  
  43.  
  44. || failure $"$prog stop"  
  45.     RETVAL=$?  
  46.     [ $RETVAL -eq 0 ] && rm -f  
  47.  
  48. /var/lock/subsys/postfix  
  49.     echo  
  50.     return $RETVAL  
  51. }  
  52.  reload() {  
  53.     echo -n $"Reloading postfix: "  
  54.     /usr/sbin/postfix reload 2>/dev/null 1>&2 &&  
  55.  
  56. success || failure $"$prog reload"  
  57.     RETVAL=$?  
  58.     echo  
  59.     return $RETVAL  
  60. }  
  61.  abort() {  
  62.     /usr/sbin/postfix abort 2>/dev/null 1>&2 &&  
  63. success || failure $"$prog abort"  
  64.     return $?  
  65. }  
  66.  flush() {  
  67.     /usr/sbin/postfix flush 2>/dev/null 1>&2 &&  
  68. success || failure $"$prog flush"  
  69.     return $?  
  70. }  
  71.  check() {  
  72.     /usr/sbin/postfix check 2>/dev/null 1>&2 &&  
  73.  
  74. success || failure $"$prog check"  
  75.     return $?  
  76. }  
  77.  restart() {  
  78.     stop  
  79.     start  
  80. }  
  81.  # See how we were called.  
  82. case "$1" in  
  83.   start)  
  84.     start  
  85.     ;;  
  86.   stop)  
  87.     stop  
  88.     ;;  
  89.   restart)  
  90.     stop  
  91.     start  
  92.     ;;  
  93.   reload)  
  94.     reload  
  95.     ;;  
  96.   abort)  
  97.     abort  
  98.     ;;  
  99.   flush)  
  100.     flush  
  101.     ;;  
  102.   check)  
  103.     check  
  104.     ;;  
  105.   status)  
  106.     status master  
  107.     ;;  
  108.   condrestart)  
  109.     [ -f /var/lock/subsys/postfix ] && restart || :  
  110.     ;;  
  111.   *)  
  112.     echo $"Usage: $0 {start|stop|restart|reload| 
  113. abort|flush|check|status|condrestart}"  
  114.     exit 1  
  115. esac  
  116.  exit $?  
  117.  # END  
 
postfix文件配置规则给顺便提一提,1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
 
 
  1. [root@localhos~]# vim /etc/postfix/main.cf  
  2. myhostname = mail.zzu.com  
  3. myorigin = zzu.com  
  4. mydomain = zzu.com  
  5. mydestination = $myhostname, localhost.$mydomain,  localhost, $mydomain  
  6. mynetworks = 192.168.0.0/24, 127.0.0.0/8  
  7. inet_interfaces = all  
在postfix的配置文件main.cf中做如上的改动,就可以发送和接收邮件,先来测试一下收发信件,再介绍一下各自的含义。
 
 
  1. #先添加两个用户  
  2. [root@localhost ~]# useradd user1  
  3. [root@localhost ~]# useradd user2  
  4. [root@localhost ~]# echo "redhat" |passwd --stdin user1  
  5. [root@localhost ~]# echo "redhat" |passwd --stdin user2  
  6. #收发信件  
  7. [root@localhost ~]# telnet mail.zzu.com 25  
  8. Trying 192.168.0.100...  
  9. Connected to mail.zzu.com (192.168.0.100).  
  10. Escape character is '^]'.  
  11. 220 mail.zzu.com ESMTP Postfix  
  12. helo mail.zzu.com  
  13. 250 mail.zzu.com  
  14. mail from:user1@zzu.com  
  15. 250 2.1.0 Ok  
  16. rcpt to:user2@zzu.com  
  17. 250 2.1.5 Ok  
  18. data  
  19. 354 End data with <CR><LF>.<CR><LF>  
  20. Subject hello  
  21. . 250 2.0.0 Ok: queued as E0B2113DAD6  
  22. quit  
  23. 221 2.0.0 Bye  
  24. Connection closed by foreign host.  
  25.  #user2 接受成功  
  26. [root@mail ~]# su - user2  
  27. [user2@mail ~]$ mail  
  28. Mail version 8.1 6/6/93.  Type ? for help.  
  29. "/var/spool/mail/user2": 1 message 1 new  
  30. >N  1 user1@zzu.com         Fri Jul 13 08:12  13/435    
  31. & 1  
  32. Message 1:  
  33. From user1@zzu.com  Fri Jul 13 08:12:17 2012  
  34. X-Original-To: user2@zzu.com  
  35. Delivered-To: user2@zzu.com  
  36. Date: Fri, 13 Jul 2012 08:10:37 +0800 (CST)  
  37. From: user1@zzu.com  
  38. Subject hello  

查看一下日志,,要有查看日志的好习惯哦

  • myorigin参数用来指明发件人所在的域名,即做发件地址伪装;
  • mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
  • myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
  • mydomain 参数指定您的域名,默认情况下,postfix将
  • myhostname的第一部分删除而作为mydomain的值;
  • mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
  • inet_interfaces 参数指定postfix系统监听的网络接口;

2.4 为postfix开启基于cyrus-sasl的认证功能

 
 
  1. [root@mail ~]# postconf  -a  
  2. cyrus  
  3. dovecot  
验正postfix是否支持cyrus风格的sasl认证,如果您的输出为以上结果,则是支持的,其实很简单,在main.cf中添加如下内容。
 
 
  1. [root@mail ~]# vim /etc/postfix/main.cf #增加如下内容  
  2. broken_sasl_auth_clients = yes  
  3. 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  
  4. smtpd_sasl_auth_enable = yes  
  5. smtpd_sasl_local_domain = $myhostname  
  6. smtpd_sasl_security_options = noanonymous  
  7. smtpdsmtpdsmtpd_sasl_application_name = smtpd  
  8. smtpd_banner = Welcome to our $myhostname  
  9. ESMTP,Warning: Version not Available!  
  10. [root@mail ~]# vim /usr/lib/sasl2/smtpd.conf  #添加下边两行 
  11.    pwcheck_method: saslauthd  
  12.    mech_list: PLAIN LOGIN  
  13. [root@mail ~]# /usr/sbin/postfix reload  
  14. /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter:   
  15. smtpdsmtpdsmtpd_sasl_application_name=smtpd  
  16. postfix/postfix-script: refreshing the Postfix mail system  
  17. [root@mail ~]# vim /etc/postfix/main.cf  
  18. #去掉network指定的内容,现在就基于用户认证了  
  19. [root@mail ~]# telnet mail.zzu.com 25  
  20. Trying 192.168.0.100...  
  21. Connected to mail.zzu.com (192.168.0.100).  
  22. Escape character is '^]'.  
  23. 220 Welcome to our mail.zzu.com ESMTP,Warning: Version not Available!  
  24. ehlo mail.zzu.com  
  25. 250-mail.zzu.com  
  26. 250-PIPELINING  
  27. 250-SIZE 10240000  
  28. 250-VRFY  
  29. 250-ETRN  
  30. 250-AUTH LOGIN PLAIN  
  31. 250-AUTH=LOGIN PLAIN  
  32. 250-ENHANCEDSTATUSCODES  
  33. 250-8BITMIME  
  34. 250 DSN  
  35. quit  
  36. 221 2.0.0 Bye  
  37. Connection closed by foreign host.  
  38. 发邮件测试  
  39. [root@mail ~]# telnet mail.zzu.com 25  
  40. Trying 192.168.0.100...  
  41. Connected to mail.zzu.com (192.168.0.100).  
  42. Escape character is '^]'.  
  43. 220 Welcome to our mail.zzu.com ESMTP,Warning: Version not Available!  
  44. AUTH LOGIN  
  45. 334 VXNlcm5hbWU6  
  46. cmVkaGF0            #使用base64编码 echo -n "redhat" | openssl base64  
  47. 334 UGFzc3dvcmQ6  
  48. cmVkaGF0  
  49. 235 2.7.0 Authentication successful  
  50. mail from:redhat@zzu.com  
  51. 250 2.1.0 Ok  
  52. rcpt to:user1@zzu.com  
  53. 250 2.1.5 Ok  
  54. data  
  55. 354 End data with <CR><LF>.<CR><LF>  
  56. hello  
  57. 250 2.0.0 Ok: queued as 7B98E13DADA  #基于验证,并能发信成功 
  58. quit  
  59. 221 2.0.0 Bye  
  60. Connection closed by foreign host.  
postfix也已经搭建完毕,并且可以基于sasl来进行验证。为了实现基于courier-authlib来进行认证登录时的用户名和密码,我们就来编译安装一下courier-authlib

3.编译安装courier-authlib
 安装之前确保libtool-ltdl, libtool-ltdl-devel,已安装上。
 3.1 解压并编译安装courier-authlib
 
 
  1. [root@mail ~]# tar jxvf 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 \ 
  10. >     --with-authmysql \ 
  11. >     --with-mysql-libs=/usr/local/mysql/lib \ 
  12. >     --with-mysql-includes=/usr/local/mysql/include \ 
  13. >     --with-redhat \ 
  14. >     --with-authmysqlrc=/etc/authmysqlrc \ 
  15. >     --with-authdaemonrc=/etc/authdaemonrc \ 
  16. >     --with-mailuser=postfix \ 
  17. >     --with-mailgroup=postfix \ 
  18. >     --with-ltdl-lib=/usr/lib \ 
  19. >     --with-ltdl-include=/usr/include 
  20. [root@mail courier-authlib-0.64.0]# make &&make install 
其中有两行务必要解释一下,因为咱们是编译安装的mysql,编译安装的mysql和rpm包安装路径不一样,所以  --with-mysql-libs=/usr/local/mysql/lib \    和  --with-mysql-includes=/usr/local/mysql/include \ 这两行一点要跟现在mysql安装路径相对应,否则编译时将会出错。
3.2 修改配置文件
 
 
  1. [root@mail ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/ 
  2. [root@mail ~]# cp /etc/authdaemonrc.dist  /etc/authdaemonrc 
  3. [root@mail ~]# cp /etc/authmysqlrc.dist  /etc/authmysqlrc 
  4. [root@mail ~]# vim /etc/authdaemonrc  
  5.    authmodulelist="authmysql"  #认证机制为mysql
  6.    authmodulelistorig="authmysql" 
  7.    daemons=10 
3.2基于mysql来认证用户的账号和密码
请参照下边内容进行修改
 
 
  1. [root@mail ~]# vim /etc/authmysqlrc 
  2. MYSQL_SERVER localhost 
  3. MYSQL_PORT 3306      #  指定你的mysql监听的端口,这里使用默认的3306 
  4. MYSQL_USERNAME  extmail      #这时为后文要用的数据库的所有者的用户名 
  5. MYSQL_PASSWORD extmail        # 密码 
  6. MYSQL_SOCKET  /tmp/mysql.sock #套接字文件,编译安装的mysql默认在/tmp下 
  7. MYSQL_DATABASE  extmail 
  8. MYSQL_USER_TABLE  mailbox 
  9. MYSQL_CRYPT_PWFIELD  password 
  10. MYSQL_UID_FIELD  '2525'  #GID 一定要与前边的组ID相一致  
  11. MYSQL_GID_FIELD  '2525' 
  12. MYSQL_LOGIN_FIELD  username 
  13. MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir) 
  14. MYSQL_NAME_FIELD  name 
  15. MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)# 路径可以相应的修改 
3.4 提供sysv服务脚本,方便courier-authlib服务的管理,
 
 
  1. [root@mail ~]# cd courier-authlib-0.64.0 
  2. [root@mail courier-authlib-0.64.0]# cp courier-authlib.sysvinit  /etc/rc.d/init.d/courier-authlib 
  3. [root@mail courier-authlib-0.64.0]#  chmod +x   /etc/rc.d/init.d/courier-authlib 
  4. [root@mail courier-authlib-0.64.0]# chkconfig  --add courier-authlib 
  5. [root@mail courier-authlib-0.64.0]# chkconfig  courier-authlib on 
  6. [root@mail courier-authlib-0.64.0]# service courier-authlib start 
  7. Starting Courier authentication services: authdaemond 
  8. #进程已启动,服务开启
3.5配置postfix和courier-authlib
 
 
  1. [root@mail ~]# mkdir -pv /var/mailbox 
  2. [root@mail ~]# chown -R postfix /var/mailbox 
  3. [root@mail ~]# vim /usr/lib/sasl2/smtpd.conf  
  4.   pwcheck_method: authdaemond 
  5.   log_level: 3 #日志级别,先调试为3,方便查看调试信息,成功后设为1
  6.  mech_list:PLAIN LOGIN 
  7.   authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket 
  8.   
3.6 让postfix支持虚拟域和虚拟用户
 
 
  1. 1、编辑/etc/postfix/main.cf,添加如下内容: 
  2. ##Virtual Mailbox Settings### 
  3. virtual_mailbox_base = /var/mailbox 
  4. virtual_mailbox_maps =  mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf 
  5. virtual_mailbox_domains =  mysql:/etc/postfix/mysql_virtual_domains_maps.cf 
  6. virtual_alias_domains = 
  7. virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf 
  8. virtual_uid_maps = static:2525 
  9. virtual_gid_maps = static:2525 
  10. virtualvirtual_transport = virtual 
  11. maildrop_destination_recipient_limit = 1 
  12. maildrop_destination_concurrency_limit = 1 
  13. ###QUOTA Settings### 
  14. message_size_limit = 14336000 
  15. virtual_mailbox_limit = 20971520 
  16. virtual_create_maildirsize = yes 
  17. virtual_mailbox_extended = yes 
  18. virtual_mailbox_limit_maps =  
  19. 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  
  22. overdrawn his diskspace quota, please Tidy your mailbox and try again  
  23. later. 
  24. virtual_overquota_bounce = yes 
此处只需要把相关的内容增加到/etc/postfix/main.cf即可但是一定要检查/etc/postfix/mysql_virtual_mailbox_maps.cf,etc/postfix/mysql_virtual_domains_maps.cf,/etc/postfix/mysql_virtual_alias_maps.cf三个文件是否存在,如果不存在,请手动将三个文件cp到/etc/postfix下。我就是在配置中遇到这样的问题,结果不能正常发送邮件。
 3.7利用extman中的数据文件导入数据库
 
 
  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. #会遇到错误,编辑extmail.sql 执行:%s@TYPE=MyISM@ENGINE=MyISAM@g 就可以导入了。 
  5. #这是因为现在我们编译mysql版本较高的原因,语法格式有所改进,执行上边的命令之后就可以了
  6. [root@mail docs]# mysql -u root -p < init.sql 
    [root@mail docs]# mysql 
  7. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  8. Your MySQL connection id is 16 
  9. Server version: 5.5.24-log MySQL Community Server (GPL) 
  10. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights  
  11. reserved. 
  12. Oracle is a registered trademark of Oracle Corporation and/or its 
  13. affiliates. Other names may be trademarks of their respective 
  14. owners. 
  15. Type 'help;' or '\h' for help. Type '\c' to clear the current input  
  16.  
  17. statement. 
  18.  
  19. mysql> use extmail; 
  20. Database changed 
  21. mysql> show tables; 
  22. +-------------------+ 
  23. | Tables_in_extmail | 
  24. +-------------------+ 
  25. | alias             | 
  26. | domain            | 
  27. | domain_manager    | 
  28. | mailbox           | 
  29. | manager           | 
  30. +-------------------+ 
  31. 5 rows in set (0.00 sec) 
  32.  
  33. mysql>  
  34. 3、授予用户extmail访问extmail数据库的权限 
  35. mysql> GRANT all privileges on extmail.* TO extmail@localhost  IDENTIFIED BY 'extmail'; 
  36. mysql> GRANT all privileges on extmail.* TO extmail@127.0.0.1 IDENTIFIED BY 'extmail'; 
  37. [root@mail ~]# vim /etc/postfix/main.cf 
  38. [root@mail ~]# service postfix restart 
  39. Shutting down postfix:                                    [  OK  ] 
  40. Starting postfix:                                         [  OK  ] 
  41. #此时不要忘记执行FLUSH PRIVILEGES ;来时用户和密码立即生效
此时就可以给予虚拟域发送邮件了,所以还要编辑main.cf注释掉myhostname, mydestination, mydomain, myorigin几个以前的配置。

4.dovecot的安装与配置
 4.1安装配置dovecot
 dovecot也可以源码安装,但是新版的功能并没有多大改进,所以,此处就使用rpm包来安装,但是,dovecot是有依赖关系的,建议使用yum源来进行安装。
 
 
  1. [root@mail ~]# yum install dovecot -y 
 
 
  1. # vi /etc/dovecot.conf 
  2. mail_location = maildir:/var/mailbox/%d/%n/Maildir # 宏 %d 代表域名  %n 代表用户名   
  3. auth default { 
  4.     mechanisms = plain 
  5.     passdb sql { 
  6.         args = /etc/dovecot-mysql.conf 
  7.     } 
  8.     userdb sql { 
  9.         args = /etc/dovecot-mysql.conf 
  10.     } 
  11. #启用mysql认证,但关闭passwd pam { } 段 
 
 
  1. # vim /etc/dovecot-mysql.conf                  
  2. driver = mysql  # 数据库驱动为mysql
  3. connect = host=localhost dbname=extmail user=extmail password=extmail 
  4. default_pass_scheme = CRYPT 
  5. password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'                             
  6. user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u' 
  7.  
  8. 接下来启动dovecot服务: 
  9. # service dovecot start 
  10. # chkconfig dovecot on 
  11. #如果不成功,我们可以启动日志,通过日志来排除错误原因,以后的工作中也要建立这样的思想哦。
  12. #启用日志很简单,只要启用log_path= ;即可 

5.安装Extmail-1.2
5.1 解压并提供配置文件
 
 
  1. # tar zxvf extmail-1.2.tar.gz 
  2. # mkdir -pv /var/www/extsuite 
  3. # mv extmail-1.2 /var/www/extsuite/extmail 
  4. # cp /var/www/extsuite/extmail/webmail.cf.default   /var/www/extsuite/extmail/webmail.cf 
5.2 修改配置文件,根据提供的内容做相应的修改,因为内容比较多,将内容提供如下,
 
 
  1. #vi /var/www/extsuite/extmail/webmail.cf 
  2.  
  3. 部分修改选项的说明: 
  4. SYS_MESSAGE_SIZE_LIMIT = 5242880 
  5. 用户可以发送的最大邮件 
  6. SYS_USER_LANG = en_US 
  7. 语言选项,可改作: 
  8. SYS_USER_LANG = zh_CN 
  9. SYS_MAILDIR_BASE = /home/domains 
  10. 此处即为您在前文所设置的用户邮件的存放目录,可改作: 
  11. SYS_MAILDIR_BASE = /var/mailbox 
  12. SYS_MYSQL_USER = db_user 
  13. SYS_MYSQL_PASS = db_pass 
  14. 以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为: 
  15. SYS_MYSQL_USER = extmail 
  16. SYS_MYSQL_PASS = extmail 
  17. SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock 
  18. 修改为: 
  19. SYS_MYSQL_SOCKET = /tmp/mysql.sock 
  20. SYS_MYSQL_HOST = localhost 
  21. 指明数据库服务器主机名,这里默认即可 
  22. SYS_MYSQL_TABLE = mailbox 
  23. SYS_MYSQL_ATTR_USERNAME = username 
  24. SYS_MYSQL_ATTR_DOMAIN = domain 
  25. SYS_MYSQL_ATTR_PASSWD = password 
  26. 以上用来指定验正用户登录里所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称;这里默认即可 
  27. SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket 
  28. 此句用来指明authdaemo socket文件的位置,这里修改为: 
  29. SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket 
此时要提供web环境就需要安装apache此处也不使用源码编译安装最新版了,内容太多了,并建立虚拟主机,详细虚拟主机的搭建您也很熟练了,如果你还不太了解请参看我的推荐博文《教您玩转apache和虚拟主机》。
 
 
  1. [root@mail conf]# vim /etc/httpd/conf/httpd.conf 
  2. <VirtualHost *:80> 
  3. ServerName mail.zzu.com 
  4. DocumentRoot /var/www/extsuite/extmail/html/ 
  5. ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi 
  6. Alias /extmail /var/www/extsuite/extmail/html 
  7. SuexecUserGroup postfix postfix 
  8. </VirtualHost> 
  9. #修改 cgi执行文件属主为apache运行身份用户
  10. [root@mail conf]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/ 
  11. 如果您没有打开apache服务器的suexec功能,也可以使用以下方法解决: 
  12. # vi /etc/httpd/httpd.conf 
  13. User postfix 
  14. Group postfix 
  15.  
  16. <VirtualHost *:80> 
  17. ServerName mail.zzu.com 
  18. DocumentRoot /var/www/extsuite/extmail/html/ 
  19. ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi 
  20. Alias /extmail /var/www/extsuite/extmail/html 
  21. </VirtualHost> 

6.编译安装Unix-Syslog-1.1.tar.gz 解决依赖关系
 
 
 
  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]# ls 
  4. Artistic  MANIFEST  Makefile.PL  Syslog.pm  test.pl 
  5. Changes   META.yml  README       Syslog.xs 
  6. [root@mail Unix-Syslog-1.1]# perl Makefile.PL  
 
 
 
  1. [root@mail Unix-Syslog-1.1]#make &&make install 
  2. [root@mail Unix-Syslog-1.1]# service httpd restart 
  3. Stopping httpd:                                            [  OK  ] 
  4. Starting httpd:                                            [  OK  ] 
  5. [root@mail Unix-Syslog-1.1]# chkconfig httpd on  
依赖关系解决了此时就可以访问extmail页面了。

7.安装配置Extman-1.1
 7.1解压,并移动文件夹到/var/www/extsuite/下
 
 
  1. # tar zxvf  extman-1.1.tar.gz 
  2. # mv extman-1.1 /var/www/extsuite/extman 
7.2 修改配置文件
 
 
  1. # cp /var/www/extsuite/extman/webman.cf.default  /var/www/extsuite/extman/webman.cf 
  2. # vim /var/www/extsuite/extman/webman.cf 
  3. SYS_MAILDIR_BASE = /home/domains 
  4. 此处即为您在前文所设置的用户邮件的存放目录,可改作: 
  5. SYS_MAILDIR_BASE = /var/mailbox 
  6. SYS_DEFAULT_UID = 1000 
  7. SYS_DEFAULT_GID = 1000 
  8. 此两处后面设定的ID号需更改为前而创建的postfix用户和postfix组的id号,本文使用的是2525,因此,上述两项需要修改为: 
  9. SYS_DEFAULT_UID = 2525 
  10. SYS_DEFAULT_GID = 2525 
  11. SYS_MYSQL_USER = webman 
  12. SYS_MYSQL_PASS = webman 
  13. 修改为: 
  14. SYS_MYSQL_USER = extmail 
  15. SYS_MYSQL_PASS = extmail 
修改cgi目录的属组为postfix,并脚本别名添加至虚拟主机以便能正常访问extman
 
 
  1. # chown -R postfix.postfix /var/www/extsuite/extman/cgi/ 
  2. 在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行 
  3. ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi 
  4. Alias /extman /var/www/extsuite/extman/html 
7.3创建其运行时所需的临时目录,并修改其相应的权限
 
 
  1. [root@mail ~]# mkdir  -pv  /tmp/extman 
  2. [root@mail ~]# chown postfix.postfix  /tmp/extman 
重新启动apache服务器,就可以访问extmail了,

但是进去之后会要求输入验证码,因为此处没有安装配置php,所以就不支持动态网页,无法显示验证码,此处就只简单配置了apache,在lnmp的环境下可以支持验证码显示,去除验证码可以编辑webman.cf 修改SYS_CAPTCHA_ON = 1为SYS_CAPTCHA_ON = 0 就可以去除验证码了。如果没有安装perl-DBD-MySQL rpm包的话,缺少支持的模块也不能顺利的进入管理界面,如下

此包需要依赖mysql,所以也使用yum源来安装,此时执行
 
 
  1. [root@mail www]# yum install perl-DBD-mysql -y 就可以了 

可以使用默认的用户名和密码进入extman后台管理页面 ,可以对虚拟域和用户账号的管理,默认管理帐号为:root@extmail.org  密码为:extmail*123*

此时可以试着使用extman的管理界面增加虚拟域,申请用户,以及发送邮件了

 

此处我注册了两个账号,zhangsan@zzu.com 和lisi@zzu.com 分别登陆邮箱,给对方发送邮件

使用lisi的账号给zhansan@zzu.com发送邮件

zhangsan@zzu.com 收到李四发来的邮件,图片就不多放,extman图形界面的管理模式大家很快就会掌握配置。

还是那句话,要学会多观察日志,看一下日志。

 
此时postfix就算是大功告成了,用了一天半夜的时间完成了实验和博客,一个人在错误与摸索中前进,终于还是完成了postfix邮件服务器的搭建,但在实际运用中还要做相应的改进与优化。步骤之繁杂,代码之繁多,加上知识有限,未免会有什么错误之处,你发现之后请您留言,我会及时更正,不断完善,从一无所知到满腹经纶,不断学习,不断完善才是学习之道。希望对您有帮助,精彩博文继续推出,希望大家继续关注。。。。
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值