最新版本 postfix+mysql+courier-authlib+extmail+extman源码搭建邮件服务器
2012-07-13 21:24
771 查看
本文将给大家演示最新源码编译搭建邮件服务器,需要用到的包组如下,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的简单配置,配置邮件服务器才是重点。
除了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.编译安装mysql-5.5.24-linux2.6-i686
1.1提供数据存放位置/mydata/data 新建用户以安全方式运行进程.建议把mysql安装在一个逻辑卷上,对数据的管理更加的方便。
1.2,编译安装并初始化mysql-5.5.24
1.3 为mysql提供主配置文件,和sysv服务脚本,方便mysql的管理。
1.4 此时只是启动了mysql服务。但是mysql命令还不能正常使用,下面为系统增加mysql的相关命令。
mysql配置完毕,下面安装配置postfix-2.9.3。
2.编译安装postfix-2.9.3。
2.1创建postfix用户和组,且指定GID最好为大于1000的数值。
2.2 编译安装postfix
此处配置相关含义不一一解释,其含义也不难理解,路径可以自己指定,也可以选择默认。下面一定要生成二进制文件,对服务器的性能有大大的提高,不要忽略这步骤
2.3 为postfix提供SysV服务脚本/etc/rc.d/init.d/postfix
查看开放端口
服务脚本代码如下
postfix文件配置规则给顺便提一提,1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
在postfix的配置文件main.cf中做如上的改动,就可以发送和接收邮件,先来测试一下收发信件,再介绍一下各自的含义。
查看一下日志,,要有查看日志的好习惯哦
myorigin参数用来指明发件人所在的域名,即做发件地址伪装;
mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
mydomain 参数指定您的域名,默认情况下,postfix将
myhostname的第一部分删除而作为mydomain的值;
mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
inet_interfaces 参数指定postfix系统监听的网络接口;
2.4 为postfix开启基于cyrus-sasl的认证功能
验正postfix是否支持cyrus风格的sasl认证,如果您的输出为以上结果,则是支持的,其实很简单,在main.cf中添加如下内容。
postfix也已经搭建完毕,并且可以基于sasl来进行验证。为了实现基于courier-authlib来进行认证登录时的用户名和密码,我们就来编译安装一下courier-authlib
3.编译安装courier-authlib
安装之前确保libtool-ltdl, libtool-ltdl-devel,已安装上。
3.1 解压并编译安装courier-authlib
其中有两行务必要解释一下,因为咱们是编译安装的mysql,编译安装的mysql和rpm包安装路径不一样,所以 --with-mysql-libs=/usr/local/mysql/lib \ 和 --with-mysql-includes=/usr/local/mysql/include \ 这两行一点要跟现在mysql安装路径相对应,否则编译时将会出错。
3.2 修改配置文件
3.2基于mysql来认证用户的账号和密码
请参照下边内容进行修改
3.4 提供sysv服务脚本,方便courier-authlib服务的管理,
3.5配置postfix和courier-authlib
3.6 让postfix支持虚拟域和虚拟用户
此处只需要把相关的内容增加到/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中的数据文件导入数据库
此时就可以给予虚拟域发送邮件了,所以还要编辑main.cf注释掉myhostname, mydestination, mydomain, myorigin几个以前的配置。
4.dovecot的安装与配置
4.1安装配置dovecot
dovecot也可以源码安装,但是新版的功能并没有多大改进,所以,此处就使用rpm包来安装,但是,dovecot是有依赖关系的,建议使用yum源来进行安装。
5.安装Extmail-1.2
5.1 解压并提供配置文件
5.2 修改配置文件,根据提供的内容做相应的修改,因为内容比较多,将内容提供如下,
此时要提供web环境就需要安装apache此处也不使用源码编译安装最新版了,内容太多了,并建立虚拟主机,详细虚拟主机的搭建您也很熟练了,如果你还不太了解请参看我的推荐博文《教您玩转apache和虚拟主机》。
6.编译安装Unix-Syslog-1.1.tar.gz 解决依赖关系
依赖关系解决了此时就可以访问extmail页面了。
7.安装配置Extman-1.1
7.1解压,并移动文件夹到/var/www/extsuite/下
7.2 修改配置文件
修改cgi目录的属组为postfix,并脚本别名添加至虚拟主机以便能正常访问extman
7.3创建其运行时所需的临时目录,并修改其相应的权限
重新启动apache服务器,就可以访问extmail了,
但是进去之后会要求输入验证码,因为此处没有安装配置php,所以就不支持动态网页,无法显示验证码,此处就只简单配置了apache,在lnmp的环境下可以支持验证码显示,去除验证码可以编辑webman.cf 修改SYS_CAPTCHA_ON = 1为SYS_CAPTCHA_ON = 0 就可以去除验证码了。如果没有安装perl-DBD-MySQL rpm包的话,缺少支持的模块也不能顺利的进入管理界面,如下
此包需要依赖mysql,所以也使用yum源来安装,此时执行
可以使用默认的用户名和密码进入extman后台管理页面 ,可以对虚拟域和用户账号的管理,默认管理帐号为:root@extmail.org 密码为:extmail*123*
此时可以试着使用extman的管理界面增加虚拟域,申请用户,以及发送邮件了
此处我注册了两个账号,zhangsan@zzu.com 和lisi@zzu.com 分别登陆邮箱,给对方发送邮件
使用lisi的账号给zhansan@zzu.com发送邮件
zhangsan@zzu.com 收到李四发来的邮件,图片就不多放,extman图形界面的管理模式大家很快就会掌握配置。
还是那句话,要学会多观察日志,看一下日志。
此时postfix就算是大功告成了,用了一天半夜的时间完成了实验和博客,一个人在错误与摸索中前进,终于还是完成了postfix邮件服务器的搭建,但在实际运用中还要做相应的改进与优化。步骤之繁杂,代码之繁多,加上知识有限,未免会有什么错误之处,你发现之后请您留言,我会及时更正,不断完善,从一无所知到满腹经纶,不断学习,不断完善才是学习之道。希望对您有帮助,精彩博文继续推出,希望大家继续关注。。。。
附件:http://down.51cto.com/data/2361006
工欲善其事,必先利其器。准备工作一定要做充分,为后边的搭建成功做好保证,邮件服务器严重依赖DNS服务器,搭建好DNS服务器是必须的,这里就给出DNS的简单配置,配置邮件服务器才是重点。
[root@mail ~]# vim /var/named/zzu.com.db #正向区域及内容配置 $TTL 600 @ IN SOA ns.zzu.com. admin.zzu.com. ( 2012071201 15M 5M 1W 1D) @ IN NS ns.zzu.com. IN MX 10 mail.zzu.com. mail IN A 192.168.0.100 ns IN A 192.168.0.100 www IN A 192.168.0.100 pop3 IN CNAME mail smtp IN CNAME mail [root@mail ~]# vim /var/named/192.168.0.db #反向区域及内容 $TTL 600 @ IN SOA ns.zzu.com. admin.zzu.com. ( 2012071201 30M 15M 1W 1D) IN NS ns.zzu.com. 100 IN PTR mail.zzu.com. 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。
[root@mail ~]# service sendmail stop [root@mail ~]# chkconfig sendmail off [root@mail ~]# service saslauthd start [root@mail ~]# chkconfig saslauthd on
1.编译安装mysql-5.5.24-linux2.6-i686
1.1提供数据存放位置/mydata/data 新建用户以安全方式运行进程.建议把mysql安装在一个逻辑卷上,对数据的管理更加的方便。
[root@localhost ~]# mkdir -pv /mydata/data mkdir: created directory `/mydata' mkdir: created directory `/mydata/data' [root@localhost ~]# groupadd -r mysql #创建mysql组合用户并修改/mydata/data/所有者为mysql [root@localhost ~]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql [root@localhost ~]# chown -R mysql:mysql /mydata/data,
1.2,编译安装并初始化mysql-5.5.24
[root@localhost ~]# tar xf mysql-5.5.24-linux2.6-i686.tar.gz -C /usr/local [root@localhost ~]# cd /usr/local [root@localhost local]# ln -sv mysql-5.5.24-linux2.6-i686/ mysql create symbolic link `mysql' to `mysql-5.5.24-linux2.6-i686/' [root@localhost local]# cd mysql [root@localhost mysql]# ls COPYING README data include man scripts sql-bench INSTALL-BINARY bin docs lib mysql-test share support- files [root@localhost mysql]# chown -R mysql:mysql . [root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data [root@localhost mysql]# chown -R root .
1.3 为mysql提供主配置文件,和sysv服务脚本,方便mysql的管理。
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf [root@localhost mysql]# vim /etc/my.cnf [root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [root@localhost mysql]# chkconfig --add mysqld #添加服务之服务列表 [root@localhost mysql]# chkconfig mysqld on #设置开机自动启动 [root@localhost mysql]# service mysqld start Starting MySQL...... [ OK ]
1.4 此时只是启动了mysql服务。但是mysql命令还不能正常使用,下面为系统增加mysql的相关命令。
[root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql create symbolic link `/usr/include/mysql' to `/usr/local/mysql/include/' [root@localhost mysql]# echo '/usr/local/mysql/lib/' > /etc/ld.so.conf.d/mysql.conf #输出mysql的库文件给系统库查找路径 [root@localhost mysql]# cat etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib/ [root@localhost mysql]# ldconfig #重新载入系统库 [root@localhost ~]# vim /etc/profile #修改PATH变量,使mysql命令生效 [root@localhost ~]# export PATH=$PATH:/usr/local/mysql/bin #使PATH立即生效,最好不要使用source [root@localhost ~]# mysql #mysql 命令可以 正常使用 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.24-log MySQL Community Server (GPL) Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
mysql配置完毕,下面安装配置postfix-2.9.3。
2.编译安装postfix-2.9.3。
2.1创建postfix用户和组,且指定GID最好为大于1000的数值。
# groupadd -g 2525 postfix # useradd -g postfix -u 2525 -s /sbin/nologin -M postfix # groupadd -g 2526 postdrop # useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop
2.2 编译安装postfix
[root@localhost ~]# tar xf postfix-2.9.3.tar.gz [root@localhost ~]# cd postfix-2.9.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' [root@localhost postfix-2.9.3]# make [root@localhost postfix-2.9.3]# make install Please specify the prefix for installed file names. Specify this ONLY if you are building ready-to-install packages for distribution to OTHER machines. See PACKAGE_README for instructions. install_root: [/] Please specify a directory for scratch files while installing Postfix. You must have write permission in this directory. tempdir: [/root/postfix-2.9.3] Please specify the final destination directory for installed Postfix configuration files. config_directory: [/etc/postfix] Please specify the final destination directory for installed Postfix administrative commands. This directory should be in the command search path of adminstrative users. command_directory: [/usr/sbin] Please specify the final destination directory for installed Postfix daemon programs. This directory should not be in the command search pathof any users. daemon_directory: [/usr/libexec/postfix] Please specify the final destination directory for Postfix-writable data files such as caches or random numbers. This directory should not be shared with non-Postfix software. data_directory: [/var/lib/postfix] Please specify the destination directory for the Postfix HTML files. Specify "no" if you do not want to install these files. html_directory: [no] Please specify the owner of the Postfix queue. Specify an account with numerical user ID and group ID values that are not used by any other accounts on the system. mail_owner: [postfix] Please specify the final destination pathname for the installed Postfix mailq command. This is the Sendmail-compatible mail queue listing command. mailq_path: [/usr/bin/mailq] Please specify the destination directory for the Postfix on-line manual pages. You can no longer specify "no" here. manpage_directory: [/usr/local/man] Please specify the final destination pathname for the installed Postfix newaliases command. This is the Sendmail-compatible command to build alias databases for the Postfix local delivery agent. newaliases_path: [/usr/bin/newaliases] Please specify the final destination directory for Postfix queues. queue_directory: [/var/spool/postfix] Please specify the destination directory for the Postfix README files. Specify "no" if you do not want to install these files. readme_directory: [no] Please specify the final destination pathname for the installed Postfix sendmail command. This is the Sendmail-compatible mail posting interface. sendmail_path: [/usr/sbin/sendmail] Please specify the group for mail submission and for queue management commands. Specify a group name with a numerical group ID that is not shared with other accounts, not even with the Postfix mail_owner account. You can no longer specify "no" here. setgid_group: [postdrop]
此处配置相关含义不一一解释,其含义也不难理解,路径可以自己指定,也可以选择默认。下面一定要生成二进制文件,对服务器的性能有大大的提高,不要忽略这步骤
[root@localhost postfix-2.9.3]# newaliases
2.3 为postfix提供SysV服务脚本/etc/rc.d/init.d/postfix
[root@localhost postfix-2.9.3]# vim /etc/rc.d/init.d/postfix [root@localhost postfix-2.9.3]# chmod +x /etc/rc.d/init.d/postfix [root@localhost postfix-2.9.3]# chkconfig --add postfix [root@localhost postfix-2.9.3]# chkconfig postfix on [root@localhost postfix-2.9.3]# service postfix start Starting postfix: [ OK ] [root@localhost postfix-2.9.3]# 查看日志和开放端口 [root@localhost postfix-2.9.3]# tail /var/log/maillog Jul 13 07:30:55 localhost postfix/postfix-script[4231]: starting the Postfix mail system Jul 13 07:30:55 localhost postfix/master[4232]: daemon started -- version 2.9.3, configuration /etc/postfix
查看开放端口
服务脚本代码如下
#!/bin/bash ## postfix Postfix Mail Transfer Agent ## chkconfig: 2345 80 30 # description: Postfix is a Mail Transport Agent, which is the program \ # that moves mail from one machine to another. # processname: master # pidfile: /var/spool/postfix/pid/master.pid # config: /etc/postfix/main.cf # config: /etc/postfix/master.cf # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network #Check that networking is up. [ $NETWORKING = "no" ] && exit 3 [ -x /usr/sbin/postfix ] || exit 4 [ -d /etc/postfix ] || exit 5 [ -d /var/spool/postfix ] || exit 6 RETVAL=0 prog="postfix" start() { # Start daemons. echo -n $"Starting postfix: " /usr/bin/newaliases >/dev/null 2>&1 /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start" RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix echo return $RETVAL } stop() { # Stop daemons. echo -n $"Shutting down postfix: " /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop" RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix echo return $RETVAL } reload() { echo -n $"Reloading postfix: " /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload" RETVAL=$? echo return $RETVAL } abort() { /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort" return $? } flush() { /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush" return $? } check() { /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check" return $? } restart() { stop start } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) stop start ;; reload) reload ;; abort) abort ;; flush) flush ;; check) check ;; status) status master ;; condrestart) [ -f /var/lock/subsys/postfix ] && restart || : ;; *) echo $"Usage: $0 {start|stop|restart|reload| abort|flush|check|status|condrestart}" exit 1 esac exit $? # END
postfix文件配置规则给顺便提一提,1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
[root@localhos~]# vim /etc/postfix/main.cf myhostname = mail.zzu.com myorigin = zzu.com mydomain = zzu.com mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mynetworks = 192.168.0.0/24, 127.0.0.0/8 inet_interfaces = all
在postfix的配置文件main.cf中做如上的改动,就可以发送和接收邮件,先来测试一下收发信件,再介绍一下各自的含义。
#先添加两个用户 [root@localhost ~]# useradd user1 [root@localhost ~]# useradd user2 [root@localhost ~]# echo "redhat" |passwd --stdin user1 [root@localhost ~]# echo "redhat" |passwd --stdin user2 #收发信件 [root@localhost ~]# telnet mail.zzu.com 25 Trying 192.168.0.100... Connected to mail.zzu.com (192.168.0.100). Escape character is '^]'. 220 mail.zzu.com ESMTP Postfix helo mail.zzu.com 250 mail.zzu.com mail from:user1@zzu.com 250 2.1.0 Ok rcpt to:user2@zzu.com 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> Subject hello . 250 2.0.0 Ok: queued as E0B2113DAD6 quit 221 2.0.0 Bye Connection closed by foreign host. #user2 接受成功 [root@mail ~]# su - user2 [user2@mail ~]$ mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/user2": 1 message 1 new >N 1 user1@zzu.com Fri Jul 13 08:12 13/435 & 1 Message 1: From user1@zzu.com Fri Jul 13 08:12:17 2012 X-Original-To: user2@zzu.com Delivered-To: user2@zzu.com Date: Fri, 13 Jul 2012 08:10:37 +0800 (CST) From: user1@zzu.com Subject hello
查看一下日志,,要有查看日志的好习惯哦
myorigin参数用来指明发件人所在的域名,即做发件地址伪装;
mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
mydomain 参数指定您的域名,默认情况下,postfix将
myhostname的第一部分删除而作为mydomain的值;
mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
inet_interfaces 参数指定postfix系统监听的网络接口;
2.4 为postfix开启基于cyrus-sasl的认证功能
[root@mail ~]# postconf -a cyrus dovecot
验正postfix是否支持cyrus风格的sasl认证,如果您的输出为以上结果,则是支持的,其实很简单,在main.cf中添加如下内容。
[root@mail ~]# vim /etc/postfix/main.cf #增加如下内容 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 smtpdsmtpdsmtpd_sasl_application_name = smtpd smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available! [root@mail ~]# vim /usr/lib/sasl2/smtpd.conf #添加下边两行 pwcheck_method: saslauthd mech_list: PLAIN LOGIN [root@mail ~]# /usr/sbin/postfix reload /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpdsmtpdsmtpd_sasl_application_name=smtpd postfix/postfix-script: refreshing the Postfix mail system [root@mail ~]# vim /etc/postfix/main.cf #去掉network指定的内容,现在就基于用户认证了 [root@mail ~]# telnet mail.zzu.com 25 Trying 192.168.0.100... Connected to mail.zzu.com (192.168.0.100). Escape character is '^]'. 220 Welcome to our mail.zzu.com ESMTP,Warning: Version not Available! ehlo mail.zzu.com 250-mail.zzu.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN quit 221 2.0.0 Bye Connection closed by foreign host. 发邮件测试 [root@mail ~]# telnet mail.zzu.com 25 Trying 192.168.0.100... Connected to mail.zzu.com (192.168.0.100). Escape character is '^]'. 220 Welcome to our mail.zzu.com ESMTP,Warning: Version not Available! AUTH LOGIN 334 VXNlcm5hbWU6 cmVkaGF0 #使用base64编码 echo -n "redhat" | openssl base64 334 UGFzc3dvcmQ6 cmVkaGF0 235 2.7.0 Authentication successful mail from:redhat@zzu.com 250 2.1.0 Ok rcpt to:user1@zzu.com 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> hello . 250 2.0.0 Ok: queued as 7B98E13DADA #基于验证,并能发信成功 quit 221 2.0.0 Bye Connection closed by foreign host.
postfix也已经搭建完毕,并且可以基于sasl来进行验证。为了实现基于courier-authlib来进行认证登录时的用户名和密码,我们就来编译安装一下courier-authlib
3.编译安装courier-authlib
安装之前确保libtool-ltdl, libtool-ltdl-devel,已安装上。
3.1 解压并编译安装courier-authlib
[root@mail ~]# tar jxvf courier-authlib-0.64.0.tar.bz2 [root@mail ~]# cd courier-authlib-0.64.0 [root@mail courier-authlib-0.64.0]# ./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 [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 修改配置文件
[root@mail ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/ [root@mail ~]# cp /etc/authdaemonrc.dist /etc/authdaemonrc [root@mail ~]# cp /etc/authmysqlrc.dist /etc/authmysqlrc [root@mail ~]# vim /etc/authdaemonrc authmodulelist="authmysql" #认证机制为mysql authmodulelistorig="authmysql" daemons=10
3.2基于mysql来认证用户的账号和密码
请参照下边内容进行修改
[root@mail ~]# vim /etc/authmysqlrc MYSQL_SERVER localhost MYSQL_PORT 3306 # 指定你的mysql监听的端口,这里使用默认的3306 MYSQL_USERNAME extmail #这时为后文要用的数据库的所有者的用户名 MYSQL_PASSWORD extmail # 密码 MYSQL_SOCKET /tmp/mysql.sock #套接字文件,编译安装的mysql默认在/tmp下 MYSQL_DATABASE extmail MYSQL_USER_TABLE mailbox MYSQL_CRYPT_PWFIELD password MYSQL_UID_FIELD '2525' #GID 一定要与前边的组ID相一致 MYSQL_GID_FIELD '2525' MYSQL_LOGIN_FIELD username MYSQL_HOME_FIELD concat('/var/mailbox/',homedir) MYSQL_NAME_FIELD name MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir)# 路径可以相应的修改
3.4 提供sysv服务脚本,方便courier-authlib服务的管理,
[root@mail ~]# cd courier-authlib-0.64.0 [root@mail courier-authlib-0.64.0]# cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib [root@mail courier-authlib-0.64.0]# chmod +x /etc/rc.d/init.d/courier-authlib [root@mail courier-authlib-0.64.0]# chkconfig --add courier-authlib [root@mail courier-authlib-0.64.0]# chkconfig courier-authlib on [root@mail courier-authlib-0.64.0]# service courier-authlib start Starting Courier authentication services: authdaemond #进程已启动,服务开启
3.5配置postfix和courier-authlib
[root@mail ~]# mkdir -pv /var/mailbox [root@mail ~]# chown -R postfix /var/mailbox [root@mail ~]# vim /usr/lib/sasl2/smtpd.conf pwcheck_method: authdaemond log_level: 3 #日志级别,先调试为3,方便查看调试信息,成功后设为1 mech_list:PLAIN LOGIN authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
3.6 让postfix支持虚拟域和虚拟用户
1、编辑/etc/postfix/main.cf,添加如下内容: ##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 virtualvirtual_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
此处只需要把相关的内容增加到/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中的数据文件导入数据库
[root@mail ~]# tar xf extman-1.1.tar.gz [root@mail ~]# cd extman-1.1/docs [root@mail docs]# mysql -u root -p < extmail.sql #会遇到错误,编辑extmail.sql 执行:%s@TYPE=MyISM@ENGINE=MyISAM@g 就可以导入了。 #这是因为现在我们编译mysql版本较高的原因,语法格式有所改进,执行上边的命令之后就可以了 [root@mail docs]# mysql -u root -p < init.sql [root@mail docs]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 16 Server version: 5.5.24-log MySQL Community Server (GPL) Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use extmail; Database changed mysql> show tables; +-------------------+ | Tables_in_extmail | +-------------------+ | alias | | domain | | domain_manager | | mailbox | | manager | +-------------------+ 5 rows in set (0.00 sec) mysql> 3、授予用户extmail访问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'; [root@mail ~]# vim /etc/postfix/main.cf [root@mail ~]# service postfix restart Shutting down postfix: [ OK ] Starting postfix: [ OK ] #此时不要忘记执行FLUSH PRIVILEGES ;来时用户和密码立即生效
此时就可以给予虚拟域发送邮件了,所以还要编辑main.cf注释掉myhostname, mydestination, mydomain, myorigin几个以前的配置。
4.dovecot的安装与配置
4.1安装配置dovecot
dovecot也可以源码安装,但是新版的功能并没有多大改进,所以,此处就使用rpm包来安装,但是,dovecot是有依赖关系的,建议使用yum源来进行安装。
[root@mail ~]# yum install dovecot -y
# vi /etc/dovecot.conf mail_location = maildir:/var/mailbox/%d/%n/Maildir # 宏 %d 代表域名 %n 代表用户名 auth default { mechanisms = plain passdb sql { args = /etc/dovecot-mysql.conf } userdb sql { args = /etc/dovecot-mysql.conf } #启用mysql认证,但关闭passwd pam { } 段
# vim /etc/dovecot-mysql.conf driver = mysql # 数据库驱动为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' 接下来启动dovecot服务: # service dovecot start # chkconfig dovecot on #如果不成功,我们可以启动日志,通过日志来排除错误原因,以后的工作中也要建立这样的思想哦。 #启用日志很简单,只要启用log_path= ;即可
5.安装Extmail-1.2
5.1 解压并提供配置文件
# tar zxvf extmail-1.2.tar.gz # mkdir -pv /var/www/extsuite # mv extmail-1.2 /var/www/extsuite/extmail # cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf
5.2 修改配置文件,根据提供的内容做相应的修改,因为内容比较多,将内容提供如下,
#vi /var/www/extsuite/extmail/webmail.cf 部分修改选项的说明: SYS_MESSAGE_SIZE_LIMIT = 5242880 用户可以发送的最大邮件 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_MYSQL_SOCKET = /var/lib/mysql/mysql.sock 修改为: SYS_MYSQL_SOCKET = /tmp/mysql.sock SYS_MYSQL_HOST = localhost 指明数据库服务器主机名,这里默认即可 SYS_MYSQL_TABLE = mailbox SYS_MYSQL_ATTR_USERNAME = username SYS_MYSQL_ATTR_DOMAIN = domain SYS_MYSQL_ATTR_PASSWD = password 以上用来指定验正用户登录里所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称;这里默认即可 SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket 此句用来指明authdaemo socket文件的位置,这里修改为: SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
此时要提供web环境就需要安装apache此处也不使用源码编译安装最新版了,内容太多了,并建立虚拟主机,详细虚拟主机的搭建您也很熟练了,如果你还不太了解请参看我的推荐博文《教您玩转apache和虚拟主机》。
[root@mail conf]# vim /etc/httpd/conf/httpd.conf <VirtualHost *:80> ServerName mail.zzu.com DocumentRoot /var/www/extsuite/extmail/html/ ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi Alias /extmail /var/www/extsuite/extmail/html SuexecUserGroup postfix postfix </VirtualHost> #修改 cgi执行文件属主为apache运行身份用户 [root@mail conf]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/ 如果您没有打开apache服务器的suexec功能,也可以使用以下方法解决: # vi /etc/httpd/httpd.conf User postfix Group postfix <VirtualHost *:80> ServerName mail.zzu.com DocumentRoot /var/www/extsuite/extmail/html/ ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi Alias /extmail /var/www/extsuite/extmail/html </VirtualHost>
6.编译安装Unix-Syslog-1.1.tar.gz 解决依赖关系
[root@mail ~]# tar zxvf Unix-Syslog-1.1.tar.gz [root@mail ~]# cd Unix-Syslog-1.1 [root@mail Unix-Syslog-1.1]# ls Artistic MANIFEST Makefile.PL Syslog.pm test.pl Changes META.yml README Syslog.xs [root@mail Unix-Syslog-1.1]# perl Makefile.PL
[root@mail Unix-Syslog-1.1]#make &&make install [root@mail Unix-Syslog-1.1]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [root@mail Unix-Syslog-1.1]# chkconfig httpd on
依赖关系解决了此时就可以访问extmail页面了。
7.安装配置Extman-1.1
7.1解压,并移动文件夹到/var/www/extsuite/下
# tar zxvf extman-1.1.tar.gz # mv extman-1.1 /var/www/extsuite/extman
7.2 修改配置文件
# cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf # vim /var/www/extsuite/extman/webman.cf SYS_MAILDIR_BASE = /home/domains 此处即为您在前文所设置的用户邮件的存放目录,可改作: SYS_MAILDIR_BASE = /var/mailbox SYS_DEFAULT_UID = 1000 SYS_DEFAULT_GID = 1000 此两处后面设定的ID号需更改为前而创建的postfix用户和postfix组的id号,本文使用的是2525,因此,上述两项需要修改为: SYS_DEFAULT_UID = 2525 SYS_DEFAULT_GID = 2525 SYS_MYSQL_USER = webman SYS_MYSQL_PASS = webman 修改为: SYS_MYSQL_USER = extmail SYS_MYSQL_PASS = extmail
修改cgi目录的属组为postfix,并脚本别名添加至虚拟主机以便能正常访问extman
# chown -R postfix.postfix /var/www/extsuite/extman/cgi/ 在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行 ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi Alias /extman /var/www/extsuite/extman/html
7.3创建其运行时所需的临时目录,并修改其相应的权限
[root@mail ~]# mkdir -pv /tmp/extman [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源来安装,此时执行
[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邮件服务器的搭建,但在实际运用中还要做相应的改进与优化。步骤之繁杂,代码之繁多,加上知识有限,未免会有什么错误之处,你发现之后请您留言,我会及时更正,不断完善,从一无所知到满腹经纶,不断学习,不断完善才是学习之道。希望对您有帮助,精彩博文继续推出,希望大家继续关注。。。。
附件:http://down.51cto.com/data/2361006
相关文章推荐
- 虚拟用户、域的postfix+courier-authlib+mysql+extman+extmail+apache邮件系统
- postmail+mysql+courier-authlib+extmail+extman实现虚拟帐号的邮件系统
- postfix+courier-imap+maildrop+courier-authlib+extmail+extman
- postfix+mysql+courier-authlib+extmail+extman搭建企业邮箱
- 邮件系统服务器搭建记录(三)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- 邮件系统服务器搭建记录(五)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- postfix+mysql+courier-authlib+extmail+extman搭建企业邮箱
- 邮件系统服务器搭建记录(二)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- 邮件系统服务器搭建记录(四)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- 在Lamp平台上基于postfix+mysql+dovecot+sasl+courier-authlib+extmail+extman搭建企业级邮件系统
- 邮件系统服务器搭建记录(一)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- RHEL 4.1+courier-imap+postfix+mysql+extmail+extman
- linux Postfix + dovecot + extmail + extman + mysql
- postfix courier-imap maildrop cyrus-sasl extman搭建mail服务器
- 邮件服务器(postfix + dovecot + extmail + extman + MailScanner + spamassassin + ClamAV )
- 搭建Linux下邮件服务器(extmail+postfix+clamav)
- 搭建Linux下邮件服务器(extmail+postfix+clamav)
- postfix+mysql+extmail+dovecot虚拟域名邮件服务器搭建
- RHEL4上搭建基于postfix的全功能邮件服务器(全目前最新源码)
- linux+postfix+extmail+dovecot搭建邮件服务器 推荐