系统结构:

Centos5.5搭建postfix邮件服务器:Postfix+extmail_centos

 

第一部分:配置YUM
CentOS5.5――本地CD作为YUM

Cd /etc/yum.repos.d

Mkdir bak

Mv *.repo bal/

Vi EMOS.repo

添加内容为:
       [emos]
       Name=EMOS
         Baseurl=file://
        Enable=1    //启用
       Qpgcheck=0 //不启用验证
CentOS5.3

vim /etc/yum.repos.d/CentOS-Base.repo

清空里面内容,改成如下内容:
[extmail]
name=CentOS-extamil-Base
baseurl=http://mirror.extmail.org/yum/emos/1.5/os/i386
gpgcheck=0
注意备份好以前的,以备后用!
RHEL5.3
在/etc/yum.repos.d/下新建文件update.repo
内容如下:
[Extmail]
name=RHEL-extamil-Base
baseurl=http://mirror.extmail.org/yum/emos/1.5/os/i386/
enabled=1
gpgcheck=0
更改/usr/lib/python2.4/site-packages/yum/yumRepo.py
相应部分改成下面的内容

remote = "http://mirror.extmail.org/yum/emos/1.5/os/i386/" + '/' + relative

注:
这个对应的是CentOS5和RHEL5的源,
如果你是用4版本的,请用下面的。
第二部分:清理系统,安装所需要软件
我们为了方便,实验中所有的软件均用EMOS中的,原本系统中的,全部删除
需要卸载的软件主要有下面一些(如果你安装了的话,先检查一下自己系统中有没有这些软件)

rpm -e httpd mysql mysql-server cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib cyrus-sasl-plain sendmail --nodeps

yum install -y httpd postfix mysql mysql-server php php-mysql php-mbstring php-mcrypt courier-authlib courier-authlib-mysql courier-imap maildrop cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain cyrus-sasl-devel extsuite-webmail extsuite-webman

注:以上安装的全是本次实验的软件,如果你不用PHPMYADIN的话,可以不安装PHP环境支持。
如果想安装个更全能的LAMP环境的话,请安装下面的相应软件

yum -y install httpd mysql mysql-server php php-xml php-cli php-pdo php-mbstring php-mcrypt php-gd php-common php-devel php-mysql

安装phpmyadmin2.11.10注意:可以选择自己需要的版本

[root@localhost~]# wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/2.11.10/phpMyAdmin-2.11.10-all-languages-utf-8-only.tar.gz/download

[root@localhost ~]# tar zxvf phpMyAdmin-2.11.10-all-languages-utf-8-only.tar.gz

[root@localhost ~]# mv phpMyAdmin-2.11.10-all-languages-utf-8-only phpmyadmin

[root@localhost ~]# cd phpmyadmin

[root@localhost phpmyadmin]# cp config.sample.inc.php config.inc.php

[root@localhost ~]# vim config.inc.php

编辑config.inc.php 改下面这一行,字符串是任意的。

$cfg['blowfish_secret'] = 'skssiwksksie'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

注:如果你不喜欢用命令的方式改密码的话,就启动HTTP服务,把phpmyadmin移动到HTTPD的服务目录里面,在浏览器终端修改mysql root 用户的密码。这里我们先不动,因为我们最后将它放到extsuite的目录下,然后在HTTPD的虚拟目录中进行相应的设置。这个大家就看演示吧!
第三部分:配置邮件系统的相关软件

为了方便,下面所有的配置文件命令前的"[root@localhost ~]#"全部省略了

配置PostfixMTA邮件传输代理)

cd /etc/postfix

cp main.cf main.cf.bak

postconf -n > main1.cf

cp main1.cf main.cf

vi /etc/postfix/main.cf

增加如下内容:
# hostname

mynetworks = 127.0.0.1

myhostname = mail.91ops.com

mydestination = $mynetworks $myhostname

# banner

mail_name = Postfix - by extmail.org

smtpd_banner = $myhostname ESMTP $mail_name

# response immediately

smtpd_error_sleep_time = 0s

# Message and return code control

message_size_limit = 5242880

mailbox_size_limit = 5242880

show_user_unknown_table_name = no

# Queue lifetime control

bounce_queue_lifetime = 1d

maximal_queue_lifetime = 1d

配置courier-authlibimapmaildrop的认证)

vi /etc/authlib/authmysqlrc

并将其内容清空,然后增加如下内容:

MYSQL_SERVER localhost

MYSQL_USERNAME extmail

MYSQL_PASSWORD extmail

MYSQL_SOCKET /var/lib/mysql/mysql.sock

MYSQL_PORT 3306

MYSQL_OPT 0

MYSQL_DATABASE extmail

MYSQL_USER_TABLE mailbox

MYSQL_CRYPT_PWFIELD password

MYSQL_UID_FIELD uidnumber

MYSQL_GID_FIELD gidnumber

MYSQL_LOGIN_FIELD username

MYSQL_HOME_FIELD homedir

MYSQL_NAME_FIELD name

MYSQL_MAILDIR_FIELD maildir

MYSQL_QUOTA_FIELD quota

MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber,\

CONCAT('/home/domains/',homedir), \

CONCAT('/home/domains/',maildir), \

quota, \
name \

FROM mailbox \

WHERE username = '$(local_part)@$(domain)'

vi /etc/authlib/authdaemonrc

修改如下内容:
authmodulelist="authmysql"
authmodulelistorig="authmysql"
修改authdaemon socket目录权限. 如果该目录权限不正确修改,maildrop及postfix等将无法正确获取用户的信息及密码认证:

chmod 755 /var/spool/authdaemon/

service courier-authlib start

如一切正常,命令行将返回如下信息:

Starting Courier authentication services: authdaemond

配置maildropMDA邮件投递代理)
注:在安装maildrop的时候,系统会自动创建vuser用户及vgroup用户组,专门用于邮件的存储,vuser:vgroup的uid/gid都是1000,这与一般的邮件文档中提及用postfix用户存邮件不一样。因为postfix用户的uid一般都低于500,而Suexec模块编译时对UID/GID的要求是要大于500,因此使用postfix用户不能满足要求。其次,如果用Maildrop作为投递代理(MDA),以postfix身份投递的话,会导致postfix MTA错误。

vim /etc/postfix/master.cf

注:为了使Postfix支持Maildrop,必须修改/etc/postfix/master.cf文件中的相应部分,改为:

maildrop unix - n n - - pipe

flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}

由于maildrop不支持一次接收多个收件人,因此必须在main.cf里增加如下参数:

vim /etc/postfix/main.cf

maildrop_destination_recipient_limit = 1

测试maildrop对authlib支持
maildrop -v
如果出现下面的,就证明成功了

Centos5.5搭建postfix邮件服务器:Postfix+extmail_职场_02

注:如需重新编译Maildrop软件包,必须先获得其源码rpm包,并且必须先行安装courier-authlib及其devel软件包,否则编译后的maildrop将无法打开authlib支持。
配置Apache(为邮件系统提供网页服务)
把前面的phpmyadmin移动到/var/www/extsuite/下,我们在这里进行相应的配置

mv ~/phpmyadmin /var/www/extsuite/

vi /etc/httpd/conf/httpd.conf

定义虚拟主机的相关内容:
在最后加上:

NameVirtualHost *:80

# VirtualHost for ExtMail Solution

<VirtualHost *:80>

ServerName mail.extmail.org

DocumentRoot /var/www/extsuite/extmail/html/

ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/

Alias /extmail /var/www/extsuite/extmail/html/

ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/

Alias /extman /var/www/extsuite/extman/html/

Alias /phpmyadmin /var/www/extsuite/phpmyadmin/

# Suexec config

SuexecUserGroup vuser vgroup

</VirtualHost>
如果启动HTTPD的时候出现下面的情况,

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using mail.91ops.com for ServerName

请把ServerName这个打开,并配置
配置Extmail(提供网页收发邮件服务)

cd /var/www/extsuite/extmail

cp webmail.cf.default webmail.cf

vi webmail.cf

更改成下面的内容

SYS_MYSQL_USER = extmail

SYS_MYSQL_PASS = extmail

SYS_MYSQL_DB = extmail

更新cgi目录权限由于SuEXEC的需要,必须将extmail的cgi目录修改成vuser:vgroup权限

chown -R vuser:vgroup /var/www/extsuite/extmail/cgi/

配置Extman(提供邮件网页后台管理功能)

chown -R vuser:vgroup /var/www/extsuite/extman/cgi/

链接基本库到Extmail

mkdir /tmp/extman

chown -R vuser:vgroup /tmp/extman

service mysqld start 
导入mysql数据库结构及初始化数据(如果前面没有更改mysql密码的话,root密码默认为空)

mysql -u root -p < /var/www/extsuite/extman/docs/extmail.sql 
mysql -u root -p < /var/www/extsuite/extman/docs/init.sql

注:上述导入初始化SQL时,默认的uidnumber/gidnumber都是1000,这和vuser:vgroup 的uid/gid一致,是因为maildrop投递时会从数据库里取uidnumber/gidnumber,而在master.cf里已经定义好了投递时的运行身份(vuser:vgroup),所以这两个字段的内容必须为1000,否则将出现投递错误,例如报0×06等错误。 

cd /var/www/extsuite/extman/docs 
cp mysql_virtual_alias_maps.cf /etc/postfix/ 
cp mysql_virtual_domains_maps.cf /etc/postfix/ 
cp mysql_virtual_mailbox_maps.cf /etc/postfix/ 
cp mysql_virtual_sender_maps.cf /etc/postfix/

配置main.cf:

vi /etc/postfix/main.cf

增加以下内容:

# extmail config here

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

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

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

virtual_transport = maildrop:

测试authlib

/usr/sbin/authtest -s login postmaster@extmail.org extmail

结果如下:

Authentication succeeded.

Authenticated: postmaster@extmail.org (uid 1000, gid 1000)

Home Directory: /home/domains/extmail.org/postmaster

Maildir: /home/domains/extmail.org/postmaster/Maildir/

Quota: 104857600S

Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0

Cleartext Password: extmail

Options: (none)

这样表明ExtMan的正确安装,数据库也正确导入,courier-authlib能正确连接到mysql数据库
最后访问http://mail.extmail.org/extmail/,如无意外,将看到webmail的登陆页,不过此时还没有加正式的用户,所以不能登陆,包括postmaster@extmail.org也不行。必须要登陆到http://mail.extmail.org/extman/ 里增加一个新帐户才能登陆。
ExtMan的默认超级管理员帐户:root@extmail.org,初始密码:extmail*123*,登陆成功后,建议将密码修改,以确保安全。
这时候我们新建立个test@extmail.org用户,密码为test
为后面的实验做准备。
配置Extman后台的图形化日志功能
启动mailgraph_ext

/usr/local/mailgraph_ext/mailgraph-init start

启动cmdserver(在后台显示系统信息)

/var/www/extsuite/extman/daemon/cmdserver --daemon

加入开机自启动:

echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.d/rc.local

echo "/var/www/extsuite/extman/daemon/cmdserver -v -d" >> /etc/rc.d/rc.local

配置Courier-imap(imappop3接收邮件代理)
注:由于Courier-imap的IMAP目录是按UTF-7编码的,ExtMail目前还没有正式支持IMAP目录,因此需要屏蔽IMAP,只提供pop3服务。而就目前的使用情况来看,IMAP使用的非常少,绝大部分OutLook/Foxmail用户都习惯使用POP3而非IMAP。

vi /usr/lib/courier-imap/etc/imapd

修改如下:
IMAPDSTART=NO

vi /usr/lib/courier-imap/etc/imapd-ssl

修改如下:
IMAPDSSLSTART=NO

然后重新启动courier-imap:service courier-imap start


为了下面的测试,请先启动httpd postfix

测试POP3是否正常工作。(请首先登录extman自行建立test@extmail.org用户,密码:test)
下面蓝色部分是输入内容

telnet localhost 110

Trying 127.0.0.1...

Connected to localhost.localdomain (127.0.0.1).

Escape character is '^]'.

+OK Hello there.

user test@extmail.org

+OK Password required.

pass test

+OK logged in.

list

+OK POP3 clients that break here, they violate STD53.

.
quit

+OK Bye-bye.

配置cyrus-saslSMTP认证)
注:由于系统cyrus-sasl默认没有打开authdaemon的支持,为了使用集中认证的authlib,必须打开这个支持。为此我们必须删除系统的cyrus-sasl相关的所有软件包,替换成打开了authdaemon支持的sasl软件包(也就是EMOS中的软件包)。
配置cyrus-sasl
Postfix的SMTP认证需要透过Cyrus-SASL,连接到authdaemon获取认证信息。

vi /etc/postfix/main.cf

增加如下内容:

# smtpd related config

smtpd_recipient_restrictions =

        permit_mynetworks,
        permit_sasl_authenticated,
        reject_non_fqdn_hostname,
        reject_non_fqdn_sender,
        reject_non_fqdn_recipient,
        reject_unauth_destination,
        reject_unauth_pipelining,
        reject_invalid_hostname,

# SMTP sender login matching config

smtpd_sender_restrictions =

        permit_mynetworks,
        reject_sender_login_mismatch,

        reject_authenticated_sender_login_mismatch,

        reject_unauthenticated_sender_login_mismatch

smtpd_sender_login_maps =

        mysql:/etc/postfix/mysql_virtual_sender_maps.cf,

        mysql:/etc/postfix/mysql_virtual_alias_maps.cf 

# SMTP AUTH config here

broken_sasl_auth_clients = yes

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $myhostname

smtpd_sasl_security_options = noanonymous

编辑smtpd.conf文件

vi /usr/lib/sasl2/smtpd.conf

将其内容改为:

pwcheck_method: authdaemond――――此处需要注意是否为authdaemond

log_level: 3

mech_list: PLAIN LOGIN

authdaemond_path:/var/spool/authdaemon/socket

重新启动postfix:service postfix start

测试SMTP认证
通过以下命令获得postmaster@extmail.org的用户名及密码的BASE64编码:

perl -e 'use MIME::Base64; print encode_base64("postmaster\@extmail.org")'

内容如下:
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==

perl -e 'use MIME::Base64; print encode_base64("extmail")'

内容如下:
ZXh0bWFpbA==
然后本机测试:

telnet localhost 25

Trying 127.0.0.1...

Connected to localhost.localdomain (127.0.0.1).

Escape character is '^]'.

220 mail.91ops.com ESMTP Postfix - by extmail.org

ehlo localhost

250-mail.91ops.com
250-PIPELINING

250-SIZE 5242880

250-VRFY
250-ETRN

250-AUTH LOGIN PLAIN

250-AUTH=LOGIN PLAIN

250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
^]

telnet> quit

Connection closed.

第四部分:设置服务开机启动,并进行邮件互发测试

chkconfig httpd on

chkconfig mysqld on

chkconfig postfix on

chkconfig courier-imap on

chkconfig courier-authlib on

第五部分:测试
注意:使用Outlook,foxmail时,用户名需要为:用户名@域名,tom@btiask.com

Centos5.5搭建postfix邮件服务器:Postfix+extmail_postfix_03