-------------------------------------------
一、前言
二、环境
三、流程分析
四、具体配置
1.安装apache和mysql
2.卸载postfix RPM包
3.安装postfix源码包
4.安装courier-authlib
5.创建mailbox
6.导入数据库
7.安装dovecot
8.配置extmail
9.配置extman
五、测试
六、后台mysql数据库用户信息
七、出现的错误及解决方法
-------------------------------------------
一、前言
Extmail 是一个以perl语言编写,面向大容量/ISP级应用,免费的高性能Webmail软件,主要包括ExtMail、Extman两个部分的程序套件。ExtMail套件用于提供从浏览器中登录、使用邮件系统的Web操作界面,而Extman套件用于提供从浏览器中管理邮件系统的Web操作界面。它以GPL版权释出,设计初衷是希望设计一个适应当前高速发展的IT应用环境,满足用户多变的需求,能快速进行开发、改进和升级,适应能力强的webmail系统。
二、环境
1.系统环境
CentOS6.4 32位
2.6.32-358.el6.i686
2.环境配置
Development tool
Additional Development
Server Platform Development
3.更改主机名
# hostname mail.a.com # vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=mail.a.com # hostname mail.a.com
4.所需源码包
courier-authlib-0.63.0.tar.bz2
extmail-1.2.tar.gz
extman-1.1.tar.gz
postfix-2.8.2.tar.gz
Unix-Syslog-0.100.tar.gz
三、流程分析
四、具体配置
1.安装apache和mysql
# yum install httpd mysql mysql-server mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect # service mysqld start # mysqladmin -u root -p password '123'
2.卸载postfix RPM包,创建postfix和postdrop用户
# cp /etc/init.d/postfix /etc/init.d/postfix.bak # yum remove postfix # id postfix uid=89(postfix) gid=89(postfix) groups=89(postfix),12(mail) # groupdel postfix groupdel: cannot remove the primary group of user 'postfix' # userdel -r postfix userdel: /var/spool/postfix not owned by postfix, not removing # groupdel postfix groupdel: group 'postfix' does not exist # userdel -r postfix userdel: user 'postfix' does not exist # groupadd -g 2525 -r postfix # useradd -g postfix -u 2525 -s /sbin/nologin -M postfix # groupdel postdrop # userdel -r postdrop userdel: user 'postdrop' does not exist # groupadd -g 2526 -r postdrop # useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop # id postfix uid=2525(postfix) gid=2525(postfix) groups=2525(postfix) # id postdrop uid=2526(postdrop) gid=2526(postdrop) groups=2526(postdrop)
3.安装postfix
# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src/ # cd /usr/local/src/postfix-2.8.2/ # 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' # make # make install
[]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值。
install_root: [/] tempdir: [/usr/local/src/postfix-2.8.2] /tmp config_directory: [/etc/postfix] command_directory: [/usr/sbin] daemon_directory: [/usr/libexec/postfix] data_directory: [/var/lib/postfix] html_directory: [no] mail_owner: [postfix] mailq_path: [/usr/bin/mailq] manpage_directory: [/usr/local/man] newaliases_path: [/usr/bin/newaliases] queue_directory: [/var/spool/postfix] readme_directory: [no] sendmail_path: [/usr/sbin/sendmail] setgid_group: [postdrop]
# newaliases 生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低 # cd /etc/init.d/ # mv postfix.bak postfix # chown -R postfix /var/lib/postfix/ # chown -R postfix /var/spool/postfix/private/ # chown -R postfix /var/spool/postfix/public/ # service postfix restart [root@localhost init.d]# netstat -tupln |grep 25 tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 11488/master # chkconfig --add postfix # chkconfig postfix on
3-1.配置postfix
# vim /etc/postfix/main.cf 75 myhostname = mail.a.com 83 mydomain = a.com 99 myorigin = $mydomain 161 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 260 mynetworks = 127.0.0.0/8 # service postfix restart # cd /usr/local/lib # mkdir sasl2 # cd sasl2/ # vim smtpd.conf 1 pwcheck_method: saslauthd 2 mech_list: PLAIN LOGIN # service postfix restart # service saslauthd restart # chkconfig saslauthd on # vim /etc/postfix/main.cf 652 broken_sasl_auth_clients = yes 653 smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_host name,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,re ject_unauth_pipelining,reject_unauth_destination 654 smtpd_sasl_auth_enable = yes 655 smtpd_sasl_local_domain = $myhostname 656 smtpd_sasl_security_options = noanonymous 657 smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available! # service postfix restart # telnet 127.0.0.1 25 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. 220 Welcome to our mail.a.com ESMTP,Warning: Version not Available! EHLO 127.0.0.1 250-mail.a.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-AUTH PLAIN LOGIN CRAM-MD5 DIGEST-MD5 250-AUTH=PLAIN LOGIN CRAM-MD5 DIGEST-MD5 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN quit 221 2.0.0 Bye Connection closed by foreign host.
4.安装courier-authlib
# tar -jxvf courier-authlib-0.63.0.tar.bz2 -C /usr/local/src/ # cd /usr/local/src/courier-authlib-0.63.0/ # ./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc # make && make install # cd /usr/local/courier-authlib/ # vim /etc/ld.so.conf.d/courier-authlib.conf /usr/local/courier-authlib/lib/courier-authlib # ldconfig # ln -s /usr/local/courier-authlib/include/ /usr/include/courier-authlib # cd /usr/local/src/courier-authlib-0.63.0/ # cp courier-authlib.sysvinit /etc/init.d/courier-authlib # chmod a+x /etc/init.d/courier-authlib # cd /usr/local/courier-authlib/var/spool/ # chmod 755 authdaemon/ # cp /etc/authmysqlrc.dist /etc/authmysqlrc # cp /etc/authdaemonrc.dist /etc/authdaemonrc # vim /etc/authdaemonrc 27 authmodulelist="authmysql" 34 authmodulelistorig="authmysql" # vim /etc/authmysqlrc 26 MYSQL_SERVER localhost 27 MYSQL_USERNAME extmail 28 MYSQL_PASSWORD extmail 49 MYSQL_SOCKET /var/lib/mysql/mysql.sock /tmp/mysql.sock(源码) 56 MYSQL_PORT 3306 68 MYSQL_DATABASE extmail 83 MYSQL_USER_TABLE mailbox 92 MYSQL_CRYPT_PWFIELD password 105 DEFAULT_DOMAIN a.com 113 MYSQL_UID_FIELD 2525 119 MYSQL_GID_FIELD 2525 128 MYSQL_LOGIN_FIELD username 133 MYSQL_HOME_FIELD concat('/var/mailbox/',homedir) 139 MYSQL_NAME_FIELD name 150 MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir) # service courier-authlib start Starting Courier authentication services: authdaemond # chkconfig --add courier-authlib # chkconfig courier-authlib on
5.创建mailbox
# mkdir /var/mailbox # chown -R postfix /var/mailbox/ # vim /usr/local/lib/sasl2/smtpd.conf (覆盖原来两行) 1 pwcheck_method: authdaemond 2 log_level: 3 3 mech_list:PLAIN LOGIN 4 authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket # service saslauthd restart # service courier-authlib restart # vim /etc/postfix/main.cf 658 ########################Virtual Mailbox Settings######################## 659 virtual_mailbox_base = /var/mailbox 660 virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf 661 virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf 662 virtual_alias_domains = 663 virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf 664 virtual_uid_maps = static:2525 665 virtual_gid_maps = static:2525 666 virtual_transport = virtual 667 maildrop_destination_recipient_limit = 1 668 maildrop_destination_concurrency_limit = 1 669 ##########################QUOTA Settings######################## 670 message_size_limit = 14336000 671 virtual_mailbox_limit = 20971520 672 virtual_create_maildirsize = yes 673 virtual_mailbox_extended = yes 674 virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf 675 virtual_mailbox_limit_override = yes 676 virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later. 677 virtual_overquota_bounce = yes
6.导入数据库
# tar -zxvf extman-1.1.tar.gz # cd extman-1.1/docs/ # mysql -u root -puse mysql; mysql> select user,host from user; +---------+-----------------------+ | user | host | +---------+-----------------------+ | root | 127.0.0.1 | | | localhost | | extmail | localhost | | root | localhost | | webman | localhost | | | localhost.localdomain | | root | localhost.localdomain | +---------+-----------------------+ mysql> show databases; mysql> use extmail; mysql> show tables; +-------------------+ | Tables_in_extmail | +-------------------+ | alias | | domain | | domain_manager | | mailbox | | manager | +-------------------+ mysql> select * from mailbox\G *************************** 1. row *************************** username: [email protected] uid: postmaster password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0 clearpwd: name: PostMaster mailhost: maildir: extmail.org/postmaster/Maildir/ homedir: extmail.org/postmaster quota: 104857600S netdiskquota: 52428800S domain: extmail.org uidnumber: 1000 gidnumber: 1000 createdate: 2007-02-14 15:10:04 expiredate: 2010-11-08 active: 1 disablepwdchange: 0 disablesmtpd: 0 disablesmtp: 0 disablewebmail: 0 disablenetdisk: 0 disableimap: 0 disablepop3: 0 question: my question answer: my answer mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail'; mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail'; mysql> flush privileges;
7.安装dovecot
# cd extman-1.1/docs/ # cp mysql_virtual_* /etc/postfix/ # service postfix restart # yum install dovecot # cd /etc/dovecot/conf.d/ # vim 10-mail.conf 24 mail_location = maildir:/var/mailbox/%d/%n/Maildir # vim auth-sql.conf.ext 9 args = /etc/dovecot/dovecot-sql.conf 21 args = /etc/dovecot/dovecot-sql.conf # vim /etc/dovecot/dovecot-sql.conf 1 driver = mysql 2 connect = host=localhost dbname=extmail user=extmail password=extmail 3 default_pass_scheme = CRYPT 4 password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u' 5 user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u' # service dovecot start # chkconfig dovecot on
8.安装并配置extmail
# tar -zxvf extmail-1.2.tar.gz # mkdir /var/www/extsuite # mv extman-1.1 extmail-1.2 /var/www/extsuite/ # cd /var/www/extsuite/ # mv extmail-1.2/ extmail # mv extman-1.1/ extman # cd extmail/ # cp webmail.cf.default webmail.cf # vim webmail.cf 77 SYS_USER_LANG = zh_CN 127 SYS_MAILDIR_BASE = /var/mailbox 139 SYS_MYSQL_USER = extmail 140 SYS_MYSQL_PASS = extmail 197 SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket # chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
9.配置extman
# cd /var/www/extsuite/extman/ # cp webman.cf.default webman.cf # vim webman.cf 12 SYS_MAILDIR_BASE = /var/mailbox 21 SYS_CAPTCHA_ON = 0 (关闭验证码) 39 SYS_LANG = zh_CN # vim /etc/postfix/main.cf 415 home_mailbox = Maildir/ # service postfix restart # chown -R postfix.postfix /var/www/extsuite/extman/cgi/ # vim /etc/httpd/conf/httpd.conf 242 User postfix 243 Group postfix 10101011 ServerName mail.test.com 1012 DocumentRoot /var/www/extsuite/extmail/html/1013 ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi 1014 Alias /extmail /var/www/extsuite/extmail/html 1015 ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi 1016 Alias /extman /var/www/extsuite/extman/html 1017 # service httpd restart
五、测试
1.浏览器访问http://服务器IP/extmail
2.登陆邮箱管理,创建域。
3.默认管理帐号为:[email protected] 密码为:extmail*123*
4.创建虚拟域 a.com
5.创建虚拟域 b.com
6.创建用户user10,隶属于虚拟域a.com
7.创建用户user11,隶属于虚拟域b.com
8.user10登陆邮箱
9.user10向user11发送一封测试邮件
10.user10在写邮件
11.user11登陆邮箱
12.user11查看信件,来自于user10
六、后台mysql数据库用户信息
mysql> select * from mailbox\G *************************** 2. row *************************** username: [email protected] uid: user10 password: $1$kOABRATa$an67c39Vj1oIq56u2It7i. clearpwd: name: user10 mailhost: maildir: a.com/user10/Maildir/ homedir: a.com/user10 quota: 5242880S netdiskquota: 5242880S domain: a.com uidnumber: 1000 gidnumber: 1000 createdate: 2014-03-06 07:31:16 expiredate: 0000-00-00 active: 1 disablepwdchange: 0 disablesmtpd: 0 disablesmtp: 0 disablewebmail: 0 disablenetdisk: 0 disableimap: 1 disablepop3: 0 question: answer: *************************** 3. row *************************** username: [email protected] uid: user11 password: $1$IHtvRkzH$39KySDanfpkgX7ALLs5EH. clearpwd: name: user11 mailhost: maildir: b.com/user11/Maildir/ homedir: b.com/user11 quota: 5242880S netdiskquota: 5242880S domain: b.com uidnumber: 1000 gidnumber: 1000 createdate: 2014-03-06 07:43:58 expiredate: 0000-00-00 active: 1 disablepwdchange: 0 disablesmtpd: 0 disablesmtp: 0 disablewebmail: 0 disablenetdisk: 0 disableimap: 1 disablepop3: 0 question: answer:
七、出现的错误及解决方法
错误1:
Can't locate CGI.pm in @INC (@INC contains: /var/www/extsuite/extmail/libs /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl
/usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5) at /var/www/extsuite/extmail/libs/Ext/CGI.pm line 20. BEGIN failed--compilation aborted at
/var/www/extsuite/extmail/libs/Ext/CGI.pm line 20. Compilation failed in require at /var/www/extsuite/extmail/libs/Ext/App.pm line 23. BEGIN failed--compilation
aborted at /var/www/extsuite/extmail/libs/Ext/App.pm line 23. Compilation failed in require at /var/www/extsuite/extmail/libs/Ext/App/Login.pm line 16. BEGIN failed--
compilation aborted at /var/www/extsuite/extmail/libs/Ext/App/Login.pm line 16. Compilation failed in require at /var/www/extsuite/extmail/cgi/index.cgi line 20.
解决办法:安装perl-CGI和perl-CGI-Session
# yum install perl-CGI perl-CGI-Session
错误2:
Unix::Syslog not found, please install it first! (in cleanup) Undefined subroutine &Ext::Logger::do_closelog called at /var/www/extsuite/extmail/libs/Ext/Logger.pm
line 86.
解决办法:安装Unix-Syslog补丁
# tar -zxvf Unix-Syslog-0.100.tar.gz -C /usr/local/src/
# cd /usr/local/src/Unix-Syslog-0.100/
# perl Makefile.PL
# make && make install
错误3
Can't open /tmp/extman//sid_7c6f62cdb13d7028d93c0b267aa2b02c, No such file or directory
解决办法:
# mkdir /tmp/extman
# chown postfix.postfix /tmp/extman
错误4:无法发送邮件(针对mysql源码安装不一定成功)
解决办法:# vim /etc/postfix/main.cf 关闭161行
161 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
错误5
#!/usr/bin/perl -wT # vim: set cindent expandtab ts=4 sw=4: use vars qw($DIR); BEGIN { if ($ENV{SCRIPT_FILENAME} =~ m!(.*/)cgi!) { $DIR = $1; }else { $DIR = '../'; }
my $path = $DIR . 'libs'; unshift @INC, $path unless grep /^$path$/, @INC; #print "content-type: text/html\r\n\r\n"; #$SIG{__WARN__} = $SIG{__DIE__} = sub { print @_
}; } use strict; eval { require Ext::App::Login; my $app = Ext::App::Login->new( config => $DIR.'webmail.cf', directory => $DIR ); $app->run; }; if ($@) { print
"Content-type: text/html\r\n\r\n"; print "$@"; }
解决办法:加载cgid模块
# vim /etc/httpd/conf/httpd.conf
LoadModule cgid_module modules/mod_cgid.so
错误6 (针对mysql源码安装)
Can't locate /var/www/extsuite/extman/lang/en_US in @INC (@INC contains: /usr/local/apache/htdocs/extsuite/extman/libs /usr/local/lib/perl5 /usr/local/share/perl5
/usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at /usr/local/apache/htdocs/extsuite/extman/libs/Ext/Lang.pm line 65.
解决办法:更改/usr/local/apache/htdocs/extsuite/extmail/webmail.cf以及extman/webmail.cf配置中的路径
错误7
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: /usr/local/apache/htdocs/extsuite/extman/libs /usr/local/lib/perl5
/usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at (eval 14) line 3. Perhaps the DBD::mysql perl
module hasn't been fully installed, or perhaps the capitalisation of 'mysql' isn't right. Available drivers: DBM, ExampleP, File, Gofer, Pg, Proxy, Sponge. at
/usr/local/apache/htdocs/extsuite/extman/libs/Ext/Mgr/MySQL.pm line 45
解决办法:# yum install perl-DBD-MySQL
错误8 (添加域失败)
DBD::mysql::st execute failed: Incorrect integer value: '' for column 'can_signup' at row 1 at /usr/local/apache/htdocs/extsuite/extman/libs/Ext/Mgr/MySQL.pm line 397
解决办法:将198行can_sign改成can_signup
# vim /usr/local/apache/htdocs/extsuite/extman/libs/Ext/MgrApp/Domain.pm
198 can_signup => $q->cgi('cansignup') ? 1 : 0,
错误9 (无法发送邮件,部分日志信息)
# tail -f /var/log/maillog
Mar 7 19:54:28 mail postfix/trivial-rewrite[4550]: warning: connect to mysql server localhost: Can't connect to local MySQL server through socket
'/var/lib/mysql/mysql.sock' (2)
Mar 7 19:54:28 mail postfix/trivial-rewrite[4550]: fatal: mysql:/etc/postfix/mysql_virtual_domains_maps.cf(0,lock|fold_fix): table lookup problem
Mar 7 19:54:29 mail postfix/smtpd[4541]: warning: problem talking to service rewrite: Success
Mar 7 19:54:29 mail postfix/master[4531]: warning: process /usr/libexec/postfix/trivial-rewrite pid 4550 exit status 1
Mar 7 19:54:29 mail postfix/master[4531]: warning: /usr/libexec/postfix/trivial-rewrite: bad command startup -- throttling
Mar 7 19:54:30 mail postfix/postfix-script[4566]: stopping the Postfix mail system
Mar 7 19:54:30 mail postfix/master[4531]: terminating on signal 15
Mar 7 19:54:30 mail postfix/postfix-script[4633]: warning: not owned by group postdrop: /var/spool/postfix/public
Mar 7 19:54:31 mail postfix/postfix-script[4640]: starting the Postfix mail system
Mar 7 19:54:31 mail postfix/master[4641]: daemon started -- version 2.8.2, configuration /etc/postfix
Mar 7 19:57:33 mail postfix/smtpd[4663]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Mar 7 19:57:33 mail postfix/smtpd[4663]: connect from localhost[127.0.0.1]
解决办法:创建链接
# mkdir /var/lib/mysql/
# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
# vim /etc/postfix/main.cf
#mydestination = $myhostname, localhost.$mydomain, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
错误10
warning: SASL authentication problem: unable to open Berkeley db /etc/sasldb2: No such file or
directory
解决办法
# cp /usr/local/sasl2/lib/sasl2/smtpd.conf /etc/sasl2/
# mkdir /etc/sasldb2/
# cp /usr/local/sasl2/lib/sasl2/smtpd.conf /etc/sasldb2/