Chinaunix首页 | 论坛 | 博客
  • 博客访问: 304903
  • 博文数量: 58
  • 博客积分: 2763
  • 博客等级: 少校
  • 技术积分: 731
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-04 19:07
文章分类

全部博文(58)

文章存档

2011年(55)

2009年(1)

2008年(2)

分类: LINUX

2011-08-25 12:00:47

配置整个基于webmail的邮件服务
如图:
一、
1.配置yum源,安装所需的rpm包
#vim /etc/yum.repos.d/server.reop
[base]
name=Server
baseurl=
gpgcheck=0
#yum clean all
#yum list all

安装开发包组
yum groupinstall "Development Tools" "Development Libraries" "Legacy Software Development" "X
Software Development"
yum install httpd php 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.配置DNS
#yum install bind
-----------------------------
#vim /etc/named.conf
options {
        directory "/var/named";
};
zone "." IN {
        type hint;
        file "named.ca";
};
zone "localhost" IN {
        type master;
        file "localhost.zone";
};
zone "0.0.127.in-addr.arpa" IN {
        type master;
        file "named.local";
};
zone "hanlenry.com" IN {
        type master;
        file "hanlenry.com.zone";
};
zone "0.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.0.zone";
};
------------------------------
cd /var/named
-----------------------------

#vim named.ca
#dig -t NS . > /var/named/named.ca
------------------------------
vim localhost.zone

$TTL    86400
@               IN SOA  localhost.       admin.localhost. (
                                        2011082201             
                                        1H             
                                        10M            
                                        7D           
                                        1D )           
                IN NS           localhost.
                IN A            127.0.0.1
               
------------------------------
vim named.local
     
$TTL    86400
@       IN      SOA     localhost. admin.localhost.  (
                                      2011082201
                                      1H
                                      10M
                                      7D
                                      1D )
        IN      NS      localhost.
1       IN      PTR     localhost.
------------------------------
vim hanlenry.com.zone

$TTL 86400
@       IN      SOA     hanlenry.com.   admin.hanlenry.com. (
                                2011082201
                                1H
                                10M
                                7D
                                1D )
        IN      NS      ns.hanlenry.com.
        IN      MX 10   mail.hanlenry.com.
ns      IN      A       192.168.0.15
mail    IN      A       192.168.0.15
-----------------------------
#vim 192.168.0.zone
$TTL 86400
@       IN      SOA     hanlenry.com.   admin.hanlenry.com. (
                                2011082201
                                1H
                                10M
                                7D
                                1D )
        IN      NS      ns.hanlenry.com.
15      IN      PTR     ns.hanlenry.com.
15      IN      PTR     mail.hanlenry.com.
---------------------------------------
#vim /etc/resolv.conf
nameserver 192.168.0.15
做测试:
#dig -t A mail.hanlenry.com
#dig -x 192.168.0.15
----------------------------------------
3.启动mysql数据库,并给mysql的root用户设置密码
#service mysqld start
#chkconfig mysqld on
#mysql
set password for );
set password for );

二、下载postfix,安装配置postfix
1.
#tar xf postfix-2.6.5.tar.gz
#cd postfix-2.6.5
#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
#make makefile '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 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效率极低:
#  newaliases
2.进行一些基本配置:
#postconf -m ,看一下是否有mysql
#cd /etc/postfix
#postconf -n
#cp main.cf main.cf.bak  ,对配置文件做一下备份。
#vim main.cf
作必要修改
myhostname = mail.test.com
myorigin = test.com
mydomain = test.com
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.1.0/24, 127.0.0.0/8
启动newaliases
#postfix start
做测试
#telnet mail.hanlenry.com 25
Trying 192.168.0.15...
Connected to mail.hanlenry.com (192.168.0.15).
Escape character is '^]'.
220 Welcome to our mail.hanlenry.com
mail from:gentoo@hanlenry.com
250 2.1.0 Ok
rcpt to:centos@hanlenry.com
250 2.1.5 Ok
data
354 End data with .
Hello
.
250 2.0.0 Ok: queued as E3AF61BF00C
quit
221 2.0.0 Bye
Connection closed by foreign host.

postfix启动脚本,我跟你提供有postfix.startup
#vim postfix.startup ,基本不需要做什么修改。
#cp postfix.startup /etc/init.d/postfix
#chkconfig --add postfix
#chkconfig postfix on
#chmod +x /etc/init.d/postfix
#postfix -a

三、为postfix开启基于cyrus-sasl的认证功能

#vim /etc/postfix/main.cf
broken_sasl_auth_client = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions=premit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_local_domain = $myhostname
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!
     
#cd /usr/lib/sasl2
#vim smtpd.conf
 pwcheck_method: saslauthd
     mech_list: PLAIN LOGIN  
#service saslauthd start
#service postfix restart
做测试
#telnet mail.a.org 25
#telnet mail.hanlenry.com 25
Trying 192.168.0.15...
Connected to mail.hanlenry.com (192.168.0.15).
Escape character is '^]'.
220 Welcome to our mail.hanlenry.com ESMTP,Warning: Version not Available!
ehlo mail.hanlenry.com
250-mail.hanlenry.com
250-PIPELINING
250-SIZE 14336000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN   (认证功能)
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN 
-----------
四、安装Courier authentication library
#tar xf courier-authlib-0.62.4.tar.bz2
#cd courier-authlib-0.62.4
#./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
#make
#make install
#chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
#cp /etc/authdaemonrc.dist  /etc/authdaemonrc
#cp /etc/authmysqlrc.dist /etc/authmysqlrc
#vim /etc/authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
#vim /etc/authmysqlrc
MYSQL_SERVER localhost
MYSQL_PORT 3306                   (指定你的mysql监听的端口,这里使用默认的3306)
MYSQL_USERNAME  extmail      (这时为后文要用的数据库的所有者的用户名)
MYSQL_PASSWORD extmail        (密码)
MYSQL_SOCKET  /var/lib/mysql/mysql.sock
MYSQL_DATABASE  extmail
MYSQL_USER_TABLE  mailbox
MYSQL_CRYPT_PWFIELD  password
MYSQL_UID_FIELD  '2525'
MYSQL_GID_FIELD  '2525'
MYSQL_LOGIN_FIELD  username
MYSQL_HOME_FIELD  concat('/mailbox/',homedir)
MYSQL_NAME_FIELD  name
MYSQL_MAILDIR_FIELD  concat('/mailbox/',maildir)

#cp courier-authlib.sysvinit /etc/init.d/courier-authlib
#chmod 755 /etc/init.d/courier-authlib
#chkconfig --add courier-authlib
#chkconfig courier-authlib on
#echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
#ldconfig -v
#service courier-authlib start
-----------
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
#mkdir -pv /var/mailbox
#chown -R postfix /var/mailbox
#cd /usr/lib/sasl2
接下来重新配置SMTP 认证,编辑smtpd.conf ,确保其为以下内容:
#vim smtp.conf
pwcheck_method:authdaemond
log_level:3
mech_list:PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
---------
五、让postfix支持虚拟域和虚拟用户
1.
#vim /etc/postfix/main.cf
编辑/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-1.1.tar.gz,并为extman源码目录下的docs目录中的extmail.sql和init.sql建立数据库
 
#tar xf extman-1.1.tar.gz
#cd extman-1.1/docs
#mysql -u root -p < extmail.sql
#mysql -u root -p < init.sql
cp mysql*  /etc/postfix/
授予用户extmail访问extmail数据库的权限
#mysql
grant all privileges on extmail.* to identified by 'extmail';
grant all privileges on extmail.* to identified by 'extmail';
说明:启用虚拟域以后,需要取消中心域,即注释掉myhostname, mydestination, mydomain, myorigin几个指
令;当然,你也可以把mydestionation的值改为你自己需要的。
#service postfix start
-------------
六、配置dovecot
#vim /etc/postfix/main.cf
 启动home_mailbox = Maildir/
#vim /etc/dovecot.conf
mail_localtion = maildir:/var/mailbox/%d/%n/Maildir
auth default {
把pam注释掉
把passdb sql启用
   添加args=/etc/dovecot-mysql.conf
把userdb syq启用
   添加args=/etc/dovecot-mysql.conf
#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'
   
#service dovecort start
#chkconfig dovecot on
--------------------

七、安装Extmail-1.2
mkdir -pv /var/www/extsuite
#tar xf extmail-1.2.tar.gz -C /var/www/extsuite
#cd /var/www/extsuite
#mv extmail-1.2 extmail
#cp webmail.cf.default webmail.cf
#vim /var/www/extsuite/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_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
 
--------------
#yum install httpd
修改httpd的主配置文件
#vim /etc/httpd/cong/httpd.conf
创建虚拟主机,注销中心主机,开启虚拟主机
User postfix
Group postfix

ServerName mail.hanlenry.com
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
Alias /extmail /var/www/extsuite/extmail/html

修改用户和组为postfix
#chown -R postfix:postfix /var/www/extsuite/extmail/cgi/
依赖关系的解决
extmail将会用到perl的Unix::syslogd功能
# tar zxvf Unix-Syslog-0.100.tar.gz
# cd Unix-Syslog-0.100
# perl Makefile.PL
# make
# make install
#service httpd start
#chkconfig httpd on
------------
八、安装Extman-1.1
#cd
#mv extman-1.1 /var/www/extsuite/extman
# cp /var/www/extsuite/extman/webman.cf.default  /var/www/extsuite/extman/webman.cf
# vi /var/www/extsuite/extman/webman.cf
SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox

修改cgi目录的属主:
# 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
创建其运行时所需的临时目录,并修改其相应的权限:
#mkdir  -pv  /tmp/extman
#chown postfix.postfix  /tmp/extman
修改
SYS_CAPTCHA_ON = 1

SYS_CAPTCHA_ON = 0
 
OK,一切都搞定了,接下来你在浏览器的地址栏中输入mail.hanlenry.org,就会出现登陆界面。
如图:
 
选择“登陆邮箱管理”即可登入extman进行后台管理了。
默认管理帐号为:  密码为:extmail*123*
如图:
 

进入之后的界面,选择域列表。如图:

再选择添加域,如图:


进入到编辑域界面,如图:
 
你可以根据自己的情况编辑,在允许自由注册的那一项,在你修改完域列表之后,保存修改之后,还得再次修改一下,再把这一选项勾上。然后保存修改。
接下来你重新登陆,就可以给你的用户创建免费邮箱了。
快来试试吧!
 
可能会出现的问题:
如果你建立了邮箱后,但是登陆不了,可能会提示如下错误:
Can't chdir to /var/mailbox/hanlenry.com/hjkhan/Maildir/, No such file or directory
请你查看一下/etc/postfix/main.cf中你的mydestination是否注销了。
阅读(8636) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~