源码构建extmail服务


一. 安装前的准备工作   
1.安装所需要的rpm包
[root@localhost ~]# cd /mnt/cdrom/Server/
[root@localhost Server]# yum -y 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.关闭sendmail,并将它的随系统自动启动功能关闭:
[root@localhost Server]# cd
[root@localhost ~]# service sendmail stop
Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]
[root@localhost ~]# chkconfig sendmail off
3. 安装以下开发所用到的rpm包组:
Development Libraries
Development Tools
Legacy Software Development
X Software Development
[root@localhost ~]# yum groupinstall "Development Libraries" "Development Tools" "Legacy Software Development" "X Software Development"
4.配置DNS
[root@localhost ~]# vim /etc/resolv.conf
nameserver 222.88.88.88
nameserver 192.168.2.100
search localdomain
[root@localhost ~]# yum install bind bind-chroot caching-nameserver 
[root@localhost ~]# cd /var/named/chroot/etc/
[root@localhost etc]# cp -p named.caching-nameserver.conf named.conf
[root@localhost etc]# vim named.conf
15         listen-on port 53 { any; };
27         allow-query     { any; };
 28         allow-query-cache { any; };
37         match-clients      { any; };
 38         match-destinations { any; };  
[root@localhost etc]# vim named.rfc1912.zones
21 zone "a.org" IN {
22         type master;
23         file "a.org.db";
24         allow-update { none; };
25 };
26 zone "2.168.192.in-addr.arpa" IN {
27         type master;
28         file "192.168.2.db";
29         allow-update { none; };
30 }; 
[root@localhost etc]# cd ../var/named/
[root@localhost named]# cp -p localhost.zone a.org.db
[root@localhost named]# vim a.org.db
  1 $TTL    86400
  2 @               IN SOA  ns.a.org.       root (
  3                                         42              ; serial (d. adams)
  4                                         3H              ; refresh
  5                                         15M             ; retry
  6                                         1W              ; expiry
  7                                         1D )            ; minimum
  8
  9 @               IN NS           ns.a.org.
 10 ns              IN A            192.168.2.100
 11 mail            IN A            192.168.2.100
 12 pop3            IN CNAME        mail
 13 smtp            IN CNAME        mail
 14 @               IN MX 10        mail
[root@localhost named]# cp -p named.local 192.168.2.db
[root@localhost named]# vim 192.168.2.db
$TTL    86400
@       IN      SOA     localhost. root.localhost.  (
                                      1997022700 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
        IN      NS      localhost.
100     IN      PTR     mail.a.org.
[root@localhost named]# chkconfig named on
[root@localhost named]# service named start
Starting named:                                            [  OK  ]
[root@localhost named]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=mail.a.org
[root@localhost named]# vim /etc/hosts
127.0.0.1       mail.a.org localhost.localdomain localhost   
[root@localhost named]# init 6
[root@mail ~]# dig -t mx a.org

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <<>> -t mx a.org
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20756
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; QUESTION SECTION:
;a.org.    IN MX

;; ANSWER SECTION:
a.org.   86400 IN MX 10 mail.a.org.

;; AUTHORITY SECTION:
a.org.   86400 IN NS ns.a.org.

;; ADDITIONAL SECTION:
mail.a.org.  86400 IN A 192.168.2.100
ns.a.org.  86400 IN A 192.168.2.100

;; Query time: 4 msec
;; SERVER: 192.168.2.100#53(192.168.2.100)
;; WHEN: Mon Apr  9 15:08:17 2012
;; MSG SIZE  rcvd: 93   
5. 启动mysql数据库,并给mysql的root用户设置密码:
[root@mail ~]# service mysqld start
[root@mail ~]# chkconfig mysqld on
[root@mail ~]# mysqladmin -u root password 'redhat'
6. 启动saslauthd服务,并将其加入到自动启动队列:
[root@mail ~]# service saslauthd start
Starting saslauthd:                                        [  OK  ]
[root@mail ~]# chkconfig saslauthd on
二.安装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
[root@mail ~]# tar -zxvf postfix-2.8.2.tar.gz
[root@mail ~]# cd 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: [/root/postfix-2.8.2] /tmp
config_directory: [/etc/postfix] /etc/postfix
command_directory: [/usr/sbin]
daemon_directory: [/usr/libexec/postfix]
data_directory: [/var/lib/postfix]
html_directory: [no] /var/www/postfix_html
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]
1.生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低:
[root@mail postfix-2.8.2]# newaliases
2.进行一些基本配置,测试启动postfix并进行发信
[root@mail postfix-2.8.2]# vim /etc/postfix/main.cf
修改以下几项为您需要的配置
76 myhostname = mail.a.org
83 mydomain = a.org
98 myorigin = $mydomain
114 inet_interfaces = all
189 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
190         mail.$mydomain,
www.$mydomain, ftp.$mydomain
261 mynetworks = 192.168.2.0/24, 127.0.0.0/8
3.启动postfix
[root@mail ~]# /usr/sbin/postfix start
[root@mail ~]# mkdir abc
[root@mail ~]# 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 ~]# chkconfig --add postfix     
[root@mail ~]# chkconfig postfix on
[root@mail init.d]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
4.连接postfix,验正服务启动状况:
[root@mail ~]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to mail.a.org (127.0.0.1).
Escape character is '^]'.
220 mail.a.org ESMTP Postfix
EHLO mail.a.org
250-mail.a.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:user1@a.org
250 2.1.0 Ok
rcpt to:user1.a.org
550 5.1.1 <user1.a.org>: Recipient address rejected: User unknown in local recipient table
rcpt to:user1@a.org
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
aaaa
.
250 2.0.0 Ok: queued as 4E6D9B7525
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@mail ~]# su - user1
[user1@mail ~]$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/user1": 1 message 1 new
>N  1
user1@a.org           Mon Apr  9 16:40  13/402 
& q
Held 1 message in /var/spool/mail/user1
You have mail in /var/spool/mail/user1
三.为postfix开启基于cyrus-sasl的认证功能
1.使用以下命令验正postfix是否支持cyrus风格的sasl认证,如果您的输出为以下结果,则是支持的:
[root@mail ~]# /usr/sbin/postconf -a
cyrus
dovecot
[root@mail ~]# vim /etc/postfix/main.cf
############################CYRUS-SASL############################
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/smtp.conf
2.添加如下内容:
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
3.启动sasl服务
[root@mail ~]# chkconfig saslauthd on
[root@mail ~]# service saslauthd start
4.让postfix重新加载配置文件
[root@mail ~]# postfix reload
postfix/postfix-script: refreshing the Postfix mail system
[root@mail ~]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to mail.a.org (127.0.0.1).
Escape character is '^]'.
220 Welcome to our mail.a.org ESMTP,Warning: Version not Available!
ehlo mail.a.org
250-mail.a.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
四.安装Courier authentication library
[root@mail ~]# tar -jxvf courier-authlib-0.63.1.20111230.tar.bz2
[root@mail ~]# cd courier-authlib-0.63.1.20111230
[root@mail courier-authlib-0.63.1.20111230]# ./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.20111230]# make
[root@mail courier-authlib-0.63.1.20111230]# make install
[root@mail ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
[root@mail spool]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@mail etc]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
[root@mail etc]# vim /etc/authdaemonrc
27 authmodulelist="authmysql"
34 authmodulelistorig="authmysql"
53 daemons=10
[root@mail etc]# 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
83 MYSQL_USER_TABLE        mailbox
92 MYSQL_CRYPT_PWFIELD     password
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)
[root@mail courier-authlib-0.63.1.20111230]#  cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@mail courier-authlib-0.63.1.20111230]# chmod a+x /etc/init.d/courier-authlib
[root@mail courier-authlib-0.63.1.20111230]# chkconfig --add courier-authlib
[root@mail courier-authlib-0.63.1.20111230]# chkconfig --level 2345 courier-authlib on
[root@mail lib]# vim /etc/ld.so.conf.d/courier-authlib.conf
/usr/local/courier-authlib/lib
[root@mail lib]# service courier-authlib start
1.新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
[root@mail ~]# mkdir -pv /var/mailbox
[root@mail ~]# chown -R postfix /var/mailbox/
2.接下来重新配置SMTP 认证,编辑 /usr/lib/sasl2/smtpd.conf ,确保其为以下内容:
[root@mail ~]# vim /usr/lib/sasl2/smtp.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 ~]# 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
Enter password:
[root@mail docs]#  mysql -u root -p <init.sql
Enter password:
[root@mail docs]#  cp mysql*  /etc/postfix/
3. 授予用户extmail访问extmail数据库的权限
[root@mail docs]#  mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>  GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
Query OK, 0 rows affected (0.00 sec)
mysql>  GRANT all privileges on extmail.* TO
extmail@127.0.0.1 IDENTIFIED BY 'extmail';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@mail docs]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
六.设置dovecot
[root@mail docs]# vim /etc/dovecot.conf
211 mail_location = maildir:/var/mailbox/%d/%n/Maildir
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 ~]# vim /etc/postfix/main.cf
home_mailbox = Maildir/
[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)
1.安装
[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 8
drwxr-xr-x  7 500 500 4096 Dec 25  2009 extmail-1.2
drwxr-xr-x 11 500 500 4096 Dec 24  2009 extman-1.1
[root@mail extsuite]# mv extmail-1.2/ extmail
 [root@mail extsuite]# cd extmail/
[root@mail extmail]# cp webmail.cf.default webmail.cf
2. 修改主配置文件
[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
3. apache相关配置
[root@mail extmail]# vim /etc/httpd/conf/httpd.conf
User postfix
Group postfix
992 <VirtualHost *:80>
993 ServerName mail.a.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 </VirtualHost>
[root@mail extmail]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
4.依赖关系的解决
extmail将会用到perl的Unix::syslogd功能,您可以去
http://search.cpan.org搜索下载原码包进行安装。
[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
[root@mail Unix-Syslog-1.1]# make install
5.启动apache服务
[root@mail extmail]# service httpd start
Starting httpd:                                            [  OK  ]
[root@mail extmail]# chkconfig httpd on
八安装Extman-1.1
1.安装及基本配置
[root@mail ~]# tar -zxvf extman-1.1.tar.gz -C /var/www/extsuite/
[root@mail extsuite]# mv extman-1.1/ extman
[root@mail extman]# pwd
/var/www/extsuite/extman
[root@mail extman]# cp webman.cf.default webman.cf 
[root@mail extman]# vim webman.cf
12 SYS_MAILDIR_BASE = /var/mailbox
21 SYS_CAPTCHA_ON = 0
[root@mail extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
2.在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行:
ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
Alias /extman /var/www/extsuite/extman/htm
3.创建其运行时所需的临时目录,并修改其相应的权限:
[root@mail ~]# mkdir -pv /tmp/extman
mkdir: created directory `/tmp/extman'
[root@mail ~]# chown postfix.postfix /tmp/extman/
4.重启服务
[root@mail ~]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]
[root@mail ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
5.在浏览器中输入指定的虚拟主机的名称进行访问,如下:
http://mail.a.org
 

6.选择管理即可登入extman进行后台管理了。默认管理帐号为:root@extmail.org  密码为:extmail*123*

 


 
7.新建域


8.注册新用户

 
9.测试邮件发送


10.登录aaa@a.org查看收件箱