Extmail配置:
Extmail 是一个以perl语言编写,面向大容量/ISP级应用,免费的高性能Webmail软件,主要包括ExtMail、Extman两个部分的程序套件。ExtMail套件用于提供从浏览器中登录、使用邮件系统的Web操作界面,而Extman套件用于提供从浏览器中管理邮件系统的Web操作界面。它以GPL版权释出,设计初衷是希望设计一个适应当前高速发展的IT应用环境,满足用户多变的需求,能快速进行开发、改进和升级,适应能力强的webmail系统。
本实验采用的是redhat5.3的操作系统,其中会用到一些源码包
postfix-2.8.2.tar.gz
courier-authlib-0.63.1.tar.bz2
extmail-1.2.tar.gz
extman-1.1.tar.gz
Unix-Syslog-1.1.tar.gz
一、安装前的准备工作
1、首先安装所需的rpm包:
[root@server ~]# yum install -y httpd php-mysql, 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
2、关闭sendmail,并将它的随系统自动启动功能关闭:
root@server ~]# service sendmail stop
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
[root@server ~]# chkconfig sendmail off
3、安装以下开发所用到的rpm包组:
Development Libraries
Development Tools
Legacy Software Development
X Software Development
以下方式查询是发现全部安装:
[root@server ~]# yum grouplist all Development Libraries
4、启动mysql数据库,并给mysql的root用户设置密码:
[root@server ~]# service mysqld start
[root@server ~]# chkconfig mysqld on
[root@server ~]# mysqladmin -u root password 'redhat'
[root@server ~]# mysql -u root –p
#授权本地用户
SET PASSWORD FOR root@'localhost'=PASSWORD('redhat');
SET PASSWORD FOR root@'127.0.0.1'=PASSWORD('redhat');
FLUSH PRIVILEGES;
#授权远程用户
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'redhat';
FLUSH PRIVILEGES;
-> \q 退出
5、启动saslauthd服务,并将其加入到自动启动队列:
[root@server ~]# service saslauthd start
Starting saslauthd: [ OK ]
[root@server ~]# chkconfig saslauthd on
6、DNS配置 Dns指向的配置:
[root@server ~]# vim /etc/resolv.conf
nameserver 192.168.101.253
安装dns的rpm包
[root@server ~]# yum install -y bind bind-chroot caching-nameserver
修改dns配置文件:
[root@server ~]# cd /var/named/chroot/etc/
[root@server etc]# cp named.caching-nameserver.conf named.conf
[root@server etc]# vim named.conf 作如下修改
15 listen-on port 53 { any; };
27 allow-query { any; };
36 match-clients { any; };
37 match-destinations { any; };
编辑区域配置文件:
[root@server etc]# vim named.rfc1912.zones
21 zone "test.org" IN {
22 type master;
23 file "test.org.db";
24 allow-update { none; };
25 };
编辑数据库文件
[root@server etc]# cd ../var/named/
[root@server named]# cp -p localhost.zone test.org.db
[root@server named]# vim test.org.db
2 @ IN SOA ns.test.org. root (
9 @ IN NS ns.test.org.
10 ns IN A 192.168.101.253
11 mail IN A 192.168.101.253
12 pop3 IN CNAME mail
13 smtp IN CNAME mail
14 @ IN MX 10 mail
修改named.conf的所有者为named
[root@server named]# cd /var/named/chroot/etc/
[root@server etc]# chown named named.conf
然后启动dns服务
[root@server etc]# service named start
Starting named: [ OK ]
[root@server etc]# chkconfig named on
修改主机名
[root@server etc]# vim /etc/sysconfig/network
HOSTNAME=mail.test.org
[root@server etc]# vim /etc/hosts
127.0.0.1 mail.test.org
重启系统:
[root@server etc]# init 6 以使主机名生效
解析测试
[root@mail ~]# nslookup mail.test.org
Server: 192.168.101.253
Address: 192.168.101.253#53
Name: mail.test.org
Address: 192.168.101.253
二、安装配置postfix
创建两个用户以及组:
[root@mail ~]# groupadd -g 2525 postfix
[root@mail ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix #允许者
[root@mail ~]# groupadd -g 2526 postdrop
[root@mail ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop #投递员
解压编译安装postfix包
[root@mail ~]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/src/
[root@mail ~]# cd /usr/src/postfix-2.8.2/
[root@mail 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'
[root@mail postfix-2.8.2]# make
[root@mail postfix-2.8.2]# make install
按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
install_root: [/] /
tempdir: [/usr/local/src/ postfix-2.6.5] /tmp
config_directory: [/etc/postfix] /etc/postfix
daemon_directory: [/usr/libexec/postfix]
command_directory: [/usr/sbin]
queue_directory: [/var/spool/postfix]
sendmail_path: [/usr/sbin/sendmail]
newaliases_path: [/usr/bin/newaliases]
mailq_path: [/usr/bin/mailq]
mail_owner: [postfix]
setgid_group: [postdrop]
html_directory: [no] /var/www/postfix_html
manpages: [/usr/local/man]
readme_directory: [no]
生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低:
[root@mail postfix-2.8.2]# newaliases
2.进行一些基本配置,测试启动postfix并进行发信
[root@mail postfix-2.8.2]# vim /etc/postfix/main.cf
75 myhostname = mail.test.org
83 mydomain = test.org
99 myorigin = $mydomain
160 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
260 mynetworks = 192.168.101.0/24, 127.0.0.0/8
说明:
myorigin参数用来指明发件人所在的域名;
mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
mydomain参数指定您的域名,默认情况下,postfix将myhostname的第一部分删除而作为mydomain的值;
mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
inet_interfaces 参数指定postfix系统监听的网络接口;
注意:
1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;
3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;
4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续
启动postfix服务
[root@mail postfix-2.8.2]# /usr/src/postfix-2.8.2/bin/postfix start
postfix/postfix-script: starting the Postfix mail system
为了以后可以方便启动postfix可以做如下配置
[root@mail postfix-2.8.2]# mkdir abc
[root@mail postfix-2.8.2]# cd abc/
[root@mail abc]# cp /mnt/cdrom/Server/postfix-2.3.3-2.1.el5_2.i386.rpm ./
[root@mail abc]# rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio –id
[root@mail abc]# cd etc/rc.d/init.d/
[root@mail init.d]# cp postfix /etc/init.d/
[root@mail init.d]# vim /etc/init.d/postfix
[root@mail init.d]# service postfix restart
^[[AShutting down postfix: [ OK ]
Starting postfix: [ OK ]
[root@mail init.d]# chkconfig --add postfix
[root@mail init.d]# chkconfig postfix on
[root@mail init.d]# telnet mail.test.org 25
Trying 127.0.0.1...
Connected to mail.test.org (127.0.0.1).
Escape character is '^]'.
220 mail.test.org ESMTP Postfix
EHLO mail.test.org
250-mail.test.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
三、为postfix开启基于cyrus-sasl的认证功能
使用以下命令验正postfix是否支持cyrus风格的sasl认证,如果您的输出为以下结果,则是支持的:
[root@mail ~]# /usr/src/postfix-2.8.2/bin/postconf -a
cyrus
dovecot
[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
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
启动sasl服务
[root@mail sasl2]# chkconfig saslauthd on
[root@mail sasl2]# service saslauthd restart
Stopping saslauthd: [ OK ]
Starting saslauthd: [ OK ]
[root@mail sasl2]# service postfix restart
[root@mail sasl2]# telnet mail.test.org 25
Trying 127.0.0.1...
Connected to mail.test.org (127.0.0.1).
Escape character is '^]'.
220 Welcome to our mail.test.org ESMTP,Warning: Version not Available!
EHLO mail.test.org
250-mail.test.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN 表明有验证
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
四、安装Courier authentication library
[root@mail sasl2]# cd
[root@mail ~]# tar jxvf courier-authlib-0.63.1.tar.bz2 -C /usr/src
[root@mail src]# cd /usr/src/courier-authlib-0.63.1/
[root@mail courier-authlib-0.63.1]# ./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 --with-ltdl-lib=/usr/lib --with-ltdl-include=/usr/include
编译安装该包:
[root@mail courier-authlib-0.63.1]# make && make install
权限修改
[root@mail courier-authlib-0.63.1]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
[root@mail courier-authlib-0.63.1]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@mail courier-authlib-0.63.1]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
[root@mail courier-authlib-0.63.1]# vim /etc/authdaemonrcim
27 authmodulelist="authmysql"
34 authmodulelistorig="authmysql"
53 daemons=10
[root@mail courier-authlib-0.63.1]# vim /etc/authmysqlrc
26 MYSQL_SERVER localhost
27 MYSQL_USERNAME extmail
28 MYSQL_PASSWORD extmail
49 MYSQL_SOCKET /var/lib/mysql/mysql.sock
56 MYSQL_PORT 3306
68 MYSQL_DATABASE extmail
[root@mail courier-authlib-0.63.1]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@mail courier-authlib-0.63.1]# chmod 755 /etc/init.d/courier-authlib
[root@mail courier-authlib-0.63.1]# chkconfig --add courier-authlib
[root@mail courier-authlib-0.63.1]# chkconfig --level 2345 courier-authlib on
[root@mail courier-authlib-0.63.1]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
[root@mail courier-authlib-0.63.1]# ldconfig -v
[root@mail courier-authlib-0.63.1]# service courier-authlib start
Starting Courier authentication services: authdaemond
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
[root@mail courier-authlib-0.63.1]# mkdir -pv /var/mailbox
mkdir: created directory `/var/mailbox'
[root@mail courier-authlib-0.63.1]# chown -R postfix /var/mailbox/
接下来重新配置SMTP 认证,编辑 /usr/lib/sasl2/smtpd.conf ,确保其为以下内容:
[root@mail courier-authlib-0.63.1]# vim /usr/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
log_level: 3
mech_list:PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
五、让postfix支持虚拟域和虚拟用户
1、编辑/etc/postfix/main.cf,添加如下内容
[root@mail courier-authlib-0.63.1]# vim /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
virtual_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
2、使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库:
解压该包
[root@mail ~]# tar zxvf extman-1.1.tar.gz
[root@mail ~]# cd extman-1.1/docs/
[root@mail docs]# mysql -u root -p <extmail.sql
[root@mail docs]# mysql -u root -p <init.sql
[root@mail docs]# cp mysql* /etc/postfix/
3、授予用户extmail访问extmail数据库的权限
[root@mail docs]# mysql -u root -p
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; 让设置的内容生效
mysql> \q
Bye
说明:启用虚拟域以后,需要取消中心域,即注释掉myhostname, mydestination, mydomain, myorigin几个指令;当然,你也可以把mydestionation的值改为你自己需要的。
[root@mail docs]# service postfix restart
[root@mail docs]# vim /etc/postfix/main.cf
414 home_mailbox = Mailbox
六、配置dovecot
795 #passdb pam {
828 #}
896 #userdb passwd {
903 #}
869 passdb sql {
870 # Path for SQL configuration file, see doc/dovecot-sql-example.conf
871 args = /etc/dovecot-mysql.conf
872 }
930 userdb sql {
931 # Path for SQL configuration file, see doc/dovecot-sql-example.conf
932 args = /etc/dovecot-mysql.conf
933 }
[root@mail docs]# vim /etc/dovecot-mysql.conf
driver = 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服务
[root@mail docs]# service dovecot start
Starting Dovecot Imap: [ OK ]
[root@mail docs]# chkconfig dovecot on
七、安装Extmail-1.2 (先安装httpd)
[root@mail ~]# mkdir -pv /var/www/extsuite
[root@mail ~]# tar -zxvf extmail-1.2.tar.gz -C /var/www/extsuite/
[root@mail ~]# cd /var/www/extsuite/
[root@mail extsuite]# ll
total 4
drwxr-xr-x 7 leijun leijun 4096 Dec 25 2009 extmail-1.2
[root@mail extsuite]# mv extmail-1.2/ extmail
[root@mail extsuite]#
[root@mail extsuite]# cd extmail/
[root@mail extmail]# cp webmail.cf.default webmail.cf
修改主配置文件
[root@mail extmail]# 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 此句用来指明authdaemo socket文件的位置
[root@mail extmail]# vim /etc/httpd/conf/httpd.conf
由于extmail要进行本地邮件的投递操作,故必须将运行apache服务器用户的身份修改为您的邮件投递代理的用户;本例中打开了apache服务器的suexec功能,故使用以下方法来实现虚拟主机运行身份的指定。此例中的MDA为postfix自带,因此将指定为postfix用户:
<VirtualHost *:80>
231 User postfix
232 Group postfix
992 <VirtualHost 192.168.101.253:80>
993 ServerName mail.test.org
994 DocumentRoot /var/www/extsuite/extmail/html/
995 ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
996 Alias /extmail /var/www/extsuite/extmail/html
998 </VirtualHost>
修改 cgi执行文件属主为apache运行身份用户:
[root@mail extmail]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
4、依赖关系的解决
extmail将会用到perl的Unix::syslogd功能
[root@mail ~]# tar zxvf Unix-Syslog-1.1.tar.gz
[root@mail ~]# cd Unix-Syslog-1.1
[root@mail Unix-Syslog-1.1]# perl Makefile.PL
[root@mail Unix-Syslog-1.1]# make && make install
启动apache服务
[root@mail Unix-Syslog-1.1]# chkconfig httpd on
[root@mail Unix-Syslog-1.1]# service httpd start
八、安装Extman-1.1
1、 安装及基本配置
[root@mail ~]# mv extman-1.1 /var/www/extsuite/extman
修改配置文件以符合本例的需要:
[root@mail ~]# cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf
[root@mail ~]# vi /var/www/extsuite/extman/webman.cf
12 SYS_MAILDIR_BASE = /var/mailbox 此处即为您在前文所设置的用户邮件的存放目录
21 SYS_CAPTCHA_ON = 0
修改cgi目录的属主
[root@mail ~]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行:
[root@mail ~]# vim /etc/httpd/conf/httpd.conf
992 <VirtualHost 192.168.101.253:80>
993 ServerName mail.test.org
994 DocumentRoot /var/www/extsuite/extmail/html/
995 ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
996 Alias /extmail /var/www/extsuite/extmail/html
997 ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi该行和下一行为添加内容
998 Alias /extman /var/www/extsuite/extman/html
创建其运行时所需的临时目录,并修改其相应的权限:
[root@mail ~]# mkdir -pv /tmp/extman
mkdir: created directory `/tmp/extman'
[root@mail ~]# chown postfix.postfix /tmp/extman/
重启apache服务
[root@mail ~]# service httpd restart
可以在浏览器中输入指定的虚拟主机的名称进行访问,如下:
http://mail.test.org
选择登陆邮箱管理即可登入extman进行后台管理了。默认管理帐号为:[email protected] 密码为:extmail*123*