CentOS-5安装配置ExtMail Web邮件收发系统

本文参考http://wiki.extmail.org/extmail_solution_for_linux_centos-5,内容和病毒过滤不在本文之内,如需配置请参考官方文档。下面是在CentOS-5 32位系统的安装实录。

制作_yum_仓库

编译CentOS-Base.repo文件

  1. vi /etc/yum.repos.d/CentOS-Base.repo

加入如下内容:

  1. # EMOS-Base.repo
  2. #
  3. # Created by ExtMail Dev Team: http://www.extmail.org/
  4. #
  5. # $Id$
  6.  
  7. [EMOS-base]
  8. name=EMOS-Base
  9. baseurl=http://mirror.extmail.org/yum/emos/1.5/os/$basearch/
  10. gpgcheck=0
  11. priority=0
  12. protect=0
  13.  
  14. [EMOS-update]
  15. name=EMOS-Updates
  16. baseurl=http://mirror.extmail.org/yum/emos/1.5/updates/$basearch/
  17. gpgcheck=0
  18. priority=0
  19. protect=0

保存后,然后尝试执行一下yum list 等操作,看看是否已经成功;

配置mta-postfix

1、安装postfix

  1. # yum -y install postfix
  2. # yum remove sendmail

2、配置postfix

  1. # postconf -n > /etc/postfix/main2.cf
  2. # mv /etc/postfix/main.cf /etc/postfix/main.cf.old
  3. # mv /etc/postfix/main2.cf /etc/postfix/main.cf

编辑main.cf:

  1. # vi /etc/postfix/main.cf

增加如下内容:

  1. # hostname
  2. mynetworks = 127.0.0.1
  3. myhostname = mail.centos.bz
  4. mydestination = $mynetworks $myhostname
  5.  
  6. # banner
  7. mail_name = Postfix - by extmail.org
  8. smtpd_banner = $myhostname ESMTP $mail_name
  9.  
  10. # response immediately
  11. smtpd_error_sleep_time = 0s
  12.  
  13. # Message and return coolcode control
  14. message_size_limit = 5242880
  15. mailbox_size_limit = 5242880
  16. show_user_unknown_table_name = no
  17.  
  18. # Queue lifetime control
  19. bounce_queue_lifetime = 1d
  20. maximal_queue_lifetime = 1d

注:myhostname改为自己的。
设置postfix开机自启:

  1. # chkconfig postfix on

配置courier-authlib

1、安装Courier-Authlib

安装以下软件包:

  1. # yum -y install courier-authlib
  2. # yum -y install courier-authlib-mysql

删除并编辑/etc/authlib/authmysqlrc文件:

  1. # cat /dev/null >/etc/authlib/authmysqlrc
  2. # vi /etc/authlib/authmysqlrc

增加如下内容:

  1. MYSQL_SERVER            localhost
  2. MYSQL_USERNAME          extmail
  3. MYSQL_PASSWORD          extmail
  4. MYSQL_SOCKET            /var/lib/mysql/mysql.sock
  5. MYSQL_PORT              3306
  6. MYSQL_OPT               0
  7. MYSQL_DATABASE          extmail
  8. MYSQL_USER_TABLE        mailbox
  9. MYSQL_CRYPT_PWFIELD     password
  10. MYSQL_UID_FIELD         uidnumber
  11. MYSQL_GID_FIELD         gidnumber
  12. MYSQL_LOGIN_FIELD       username
  13. MYSQL_HOME_FIELD        homedir
  14. MYSQL_NAME_FIELD        name
  15. MYSQL_MAILDIR_FIELD     maildir
  16. MYSQL_QUOTA_FIELD       quota
  17. MYSQL_SELECT_CLAUSE     SELECT username,password,"",uidnumber,gidnumber,\
  18.                         CONCAT('/home/domains/',homedir),               \
  19.                         CONCAT('/home/domains/',maildir),               \
  20.                         quota,                                          \
  21.                         name                                            \
  22.                         FROM mailbox                                    \
  23.                         WHERE username = '$(local_part)@$(domain)'

修改authdaemonrc文件

  1. # vi /etc/authlib/authdaemonrc

修改如下内容:

  1. authmodulelist="authmysql"
  2. authmodulelistorig="authmysql"

或者使用如下命令直接修改:

  1. sed -i 's/authmodulelist=.*/authmodulelist="authmysql"/g' /etc/authlib/authdaemonrc
  2. sed -i 's/authmodulelistorig=.*/authmodulelistorig="authmysql"/g' /etc/authlib/authdaemonrc

2、启动courier-authlib:

  1. # service courier-authlib start

修改authdaemon socket目录权限

  1. # chmod 755 /var/spool/authdaemon/

配置maildrop

1、安装maildrop

  1. # yum -y install maildrop

配置master.cf 为了使Postfix支持Maildrop,必须修改/etc/postfix/master.cf文件,注释掉原来的maildrop的配置内容,并改为:

  1. maildrop   unix        -       n        n        -        -        pipe
  2.   flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}

注意:flags前面有“两个空格”

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

  1. # vi /etc/postfix/main.cf
  1. maildrop_destination_recipient_limit = 1

2、测试maildrop对authlib支持

  1. # maildrop -v

看是否出现以下内容:

  1. maildrop 2.1.0 Copyright 1998-2005 Double Precision, Inc.
  2. GDBM/DB extensions enabled.
  3. Courier Authentication Library extension enabled.
  4. Maildir quota extension enabled.
  5. This program is distributed under the terms of the GNU General Public
  6. License. See COPYING for additional information.

配置apache

1、安装httpd

  1. # yum -y install httpd

2、虚拟主机设置

编辑httpd.conf文件:

  1. # vi /etc/httpd/conf/httpd.conf

在最后一行加上:

  1. NameVirtualHost *:80
  2. Include conf/vhost_*.conf

编辑 vhost_extmail.conf

  1. # vi /etc/httpd/conf/vhost_extmail.conf

里面定义虚拟主机的相关内容:

  1. # VirtualHost for ExtMail Solution
  2. <VirtualHost *:80>
  3. ServerName mail.centos.bz
  4. DocumentRoot /var/www/extsuite/extmail/html/
  5.  
  6. ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/
  7. Alias /extmail /var/www/extsuite/extmail/html/
  8.  
  9. ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/
  10. Alias /extman /var/www/extsuite/extman/html/
  11.  
  12. # Suexec config
  13. SuexecUserGroup vuser vgroup
  14. </VirtualHost>

注意:把ServerName修改成自己的。
设置apache开机启动并重启apache

  1. # chkconfig httpd on
  2. # service httpd restart

配置webmail-extmail

1、安装ExtMail

  1. # yum -y install extsuite-webmail

2、编辑webmail.cf

  1. # cd /var/www/extsuite/extmail
  2. # cp webmail.cf.default webmail.cf
  3. # vi webmail.cf

主要变动的内容见下:

  1. SYS_MYSQL_USER = extmail
  2. SYS_MYSQL_PASS = extmail
  3. SYS_MYSQL_DB = extmail

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

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

配置管理后台-extman

1、yum安装ExtMan

  1. # yum -y install extsuite-webman

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

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

链接基本库到Extmail

  1. # mkdir /tmp/extman
  2. # chown -R vuser:vgroup /tmp/extman

注意事项:
由于RedHat发行版中包含了一个叫tmpwatch的工具,该工具会定期扫描/tmp/下的文件,如果这些文件很久都没被使用,将被删除,因此如果后台长期不使用,/tmp/extman目录有可能被tmpwatch删除,所以要么定期登陆后台,要么修改 webman.cf将临时目录修改到另一个地方。此处暂以/tmp/extman默认值为例。

2、安装mysql数据库

  1. # yum -y install mysql mysql-server

3、数据库初始化

启动Mysql

  1. # service mysqld start
  2. # chkconfig mysqld on

导入mysql数据库结构及初始化数据,root密码默认为空

  1. # mysql -u root -p < /var/www/extsuite/extman/docs/extmail.sql
  2. # 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等错误。

4、设置虚拟域和虚拟用户的配置文件

  1. # cd /var/www/extsuite/extman/docs
  2. # cp mysql_virtual_alias_maps.cf /etc/postfix/
  3. # cp mysql_virtual_domains_maps.cf /etc/postfix/
  4. # cp mysql_virtual_mailbox_maps.cf /etc/postfix/
  5. # cp mysql_virtual_sender_maps.cf /etc/postfix/

配置main.cf:

  1. # vi /etc/postfix/main.cf

增加以下内容:

  1. # extmail config here
  2. virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
  3. virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
  4. virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
  5. virtual_transport = maildrop:

重启postfix :

  1. # service postfix restart

5、测试authlib

  1. # /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.centos.bz/extmail/,如无意外,将看到webmail的登陆页,不过此时还没有加正式的用户,所以不能登陆,包括postmaster@extmail.org也不行。必须要登陆到http://mail.centos.bz/extman/ 里增加一个新帐户才能登陆。

ExtMan的默认超级管理员帐户:root@extmail.org,初始密码:extmail*123*,登陆成功后,建议将密码修改,以确保安全。

6、配置图形化日志

启动mailgraph_ext

  1. # /usr/local/mailgraph_ext/mailgraph-init start

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

  1. # /var/www/extsuite/extman/daemon/cmdserver --daemon

加入开机自启动:

  1. # echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.d/rc.local
  2. # echo "/var/www/extsuite/extman/daemon/cmdserver -v -d" >> /etc/rc.d/rc.local

使用方法: 等待大约15分钟左右,如果邮件系统有一定的流量,即可登陆到extman里,点“图形日志”即可看到图形化的日志。具体每天,周,月,年的则点击相应的图片进入即可。

配置cyrus-sasl

1、安装cyrus-sasl

删除系统的cyrus-sasl:

  1. # rpm -e cyrus-sasl --nodeps

安装新的支持authdaemon的软件包

  1. # yum -y install cyrus-sasl cyrus-sasl-plain

2、配置main.cf文件

Postfix的SMTP认证需要透过Cyrus-SASL,连接到authdaemon获取认证信息。
编辑main.cf

  1. # vi /etc/postfix/main.cf

增加如下内容:

  1. # smtpd related config
  2. smtpd_recipient_restrictions =
  3.         permit_mynetworks,
  4.         permit_sasl_authenticated,
  5.         reject_non_fqdn_hostname,
  6.         reject_non_fqdn_sender,
  7.         reject_non_fqdn_recipient,
  8.         reject_unauth_destination,
  9.         reject_unauth_pipelining,
  10.         reject_invalid_hostname,
  11.  
  12. # SMTP sender login matching config
  13. smtpd_sender_restrictions =
  14.         permit_mynetworks,
  15.         reject_sender_login_mismatch,
  16.         reject_authenticated_sender_login_mismatch,
  17.         reject_unauthenticated_sender_login_mismatch
  18.  
  19. smtpd_sender_login_maps =
  20.         mysql:/etc/postfix/mysql_virtual_sender_maps.cf,
  21.         mysql:/etc/postfix/mysql_virtual_alias_maps.cf
  22.  
  23. # SMTP AUTH config here
  24. broken_sasl_auth_clients = yes
  25. smtpd_sasl_auth_enable = yes
  26. smtpd_sasl_local_domain = $myhostname
  27. smtpd_sasl_security_options = noanonymous

3、编辑smtpd.conf文件

  1. # vi /usr/lib/sasl2/smtpd.conf

确保其内容为:

  1. pwcheck_method: authdaemond
  2. log_level: 3
  3. mech_list: PLAIN LOGIN
  4. authdaemond_path:/var/spool/authdaemon/socket

重新启动postfix:

  1. # service postfix restart

4、测试SMTP认证

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

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

内容如下:
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==

  1. # perl -e 'use MIME::Base64; print encoolcode_base64("extmail")'

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

  1. # telnet localhost 25

其过程如下:
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.
220 mail.extmail.org ESMTP Postfix – by extmail.org
ehlo demo.domain.tld 配置courier-imap

1、安装Courier-imap

默认的courier-authlib及courier-imap都会增加系统自启动设置,因此下一次服务器启动将自动启动相应的authlib及POP3服务

  1. # yum -y install courier-imap

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

  1. # vi /usr/lib/courier-imap/etc/imapd

修改内容如下:

  1. IMAPDSTART=NO
  1. # vi /usr/lib/courier-imap/etc/imapd-ssl

修改内容如下:

  1. IMAPDSSLSTART=NO

然后重新启动courier-imap:

  1. # service courier-imap start

测试POP3 请按如下步骤输入pop3命令测试其是否正常工作,注意蓝色的信息是我们输入到POP3服务器的(请首先登录extman自行建立test@extmail.org用户,密码:extmail)

  1. # 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 最后说明

至此,ExtMail的安装配置基本完成,如想配置内容,病毒过滤请到官方网站学习配置。登录extmail系统后台后,请及时修改密码或者用户名。最后需要确认的是,是否已经设置好邮件域名的MX记录或者A记录,这样才能正常收取邮件。

FAQ

1、64位系统可能安装不上courier-imap。请参考http://hahayong.blog.51cto.com/231965/530016

标签:Centos 发布于:2019-10-14 03:09:59