Linux下mail服务器架构之
一、安装前的准备工作:
准备:关闭firewall和SELinux(略)
准备:下载以下软件
1.#修改ip地址为192.168.101.210,修改dns指向为192.168.101.210
[root@junjie ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
[root@junjie ~]# service network restart
nameserver 192.168.101.210
2、卸载sendmail,sendmail将占用tcp 25端口,和postfix冲突:
[root@junjie ~]# rpm -e sendmail --nodeps
3、安装以下开发所用到的rpm包组:
Legacy Software Development
X Software Development
#安装方法: yum groupinstall "packge_group_name"
4.构建本地yum服务器(略)
5.安装配置dns服务器:
[root@junjie ~]# yum install -y bind bind-chroot caching-nameserver
[root@junjie ~]# cd /var/named/chroot/etc/
[root@junjie etc]# cp –p named.caching-nameserver.conf named.conf
[root@junjie etc]# vim named.conf
15 listen-on port 53 { any; };
27 allow-query { any; };
37 match-clients { any; };
38 match-destinations { any; };
[root@junjie etc]# vim named.rfc1912.zones
20 zone "junjie.com" IN {
37 zone "101.168.192.in-addr.arpa" IN {
[root@junjie etc]# cd ../var/named/
[root@junjie named]# cp -p localhost.zone junjie.com.db
[root@junjie named]# vim junjie.com.db
[root@junjie named]# cp -p named.local 192.168.101.db
[root@junjie named]# vim 192.168.101.db
210 IN PTR mail.junjie.com.
[root@junjie named]# chkconfig named on
[root@junjie named]# service named start
[root@junjie named]# rndc reload
[root@junjie named]# nslookup pop3.junjie.com
[root@junjie named]# nslookup mail.junjie.com
[root@junjie named]# dig -t mx junjie.com
[root@junjie named]# nslookup 192.168.101.210
6.修改主机名称,并重新启动系统,重启后挂载光盘
[root@junjie named]# vim /etc/sysconfig/network
[root@junjie named]# init 6
[root@mail ~]# mount /dev/cdrom /mnt/cdrom/
7、安装所需的rpm包,这包括以下这些:
#openssl-devel, dovecot, perl-DBD-MySQL, tcl, tcl-devel, libart_lgpl,
#libart_lgpl-devel, libtool-ltdl, libtool-ltdl-devel, expect
[root@junjie ~]# yum install -y 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
[root@mail ~]# netstat -tupln |grep mysqld
[root@mail ~]# mysqladmin -u root password "123"
mysql> SET PASSWORD FOR root@'localhost'=PASSWORD('redhat');
Query OK, 0 rows affected (0.00 sec)
mysql> SET PASSWORD FOR root@'127.0.0.1'=PASSWORD('redhat');
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'redhat';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
#---------------------------------授权本地用户
#SET PASSWORD FOR root@'localhost'=PASSWORD('redhat');
#SET PASSWORD FOR root@'127.0.0.1'=PASSWORD('redhat');
#-------------------------------授权远程用户
#GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'redhat';
8.启动saslauthd服务,并将其加入到自动启动队列:
Starting saslauthd: [ OK ]
二、安装配置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 mail]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/src/
[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'
tempdir: [/usr/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]
[root@mail postfix-2.8.2]# cp /etc/postfix/main.cf /etc/postfix/main.cf.bak
[root@mail postfix-2.8.2]# vim /etc/postfix/main.cf
76 myhostname = mail.junjie.com
83 mydomain = junjie.com
99 myorigin = $mydomain
113 inet_interfaces = all
162 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
163 mail.$mydomain, www.$mydomain, ftp.$mydomain
260 mynetworks = 192.168.101.0/24, 127.0.0.0/8
说明:
注意:
[root@mail postfix-2.8.2]# service postfix restart
postfix: unrecognized service
[root@mail postfix-2.8.2]# mkdir /root/abc
[@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
-rwxr-xr-x 1 root root 2404 Apr 1 12:24 postfix
[root@mail abc]# cp etc/rc.d/init.d/postfix /etc/init.d/
[root@mail abc]# ll /etc/init.d/postfix
-rwxr-xr-x 1 root root 2404 Apr 1 12:27 /etc/init.d/postfix
Starting postfix: [ OK ]
[root@mail abc]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
[root@mail abc]# chkconfig --add postfix
[root@mail abc]# chkconfig postfix on
[root@mail abc]# chkconfig --list postfix
Trying 192.168.101.210...
Connected to mail.junjie.com (192.168.101.210).
Escape character is '^]'.
220 mail.junjie.com ESMTP Postfix
354 End data with <CR><LF>.<CR><LF>
250 2.0.0 Ok: queued as CF06916DC89
Connection closed by foreign host.
You have new mail in /var/spool/mail/root
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 2 messages 2 new
From [email protected] Mon Apr 9 16:53:29 2012
X-Original-To: [email protected]
Delivered-To: [email protected]
Saved 1 message in mbox
Held 1 message in /var/spool/mail/root
三、为postfix开启基于cyrus-sasl的认证功能
[root@mail ~]# yum list all |grep sasl
652 ############################CYRUS-SASL##################### #######
653 broken_sasl_auth_clients = yes
654 smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_ authenticated,reject_invalid_hostname,reject_non_fqdn_hostn ame,reject_unknown_sender_domain,reject_non_fqdn_sender,rej ect_non_fqdn_recipient,reject_unknown_recipient_domain,reje ct_unauth_pipelining,reject_unauth_destination
655 smtpd_sasl_auth_enable = yes
656 smtpd_sasl_local_domain = $myhostname
657 smtpd_sasl_security_options = noanonymous
658 smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Ve rsion not Available!
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
#启动 sasl服务,让postfix重新加载配置文件
Starting saslauthd: [ OK ]
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
[root@mail ~]# telnet mail.junjie.com 25
Trying 192.168.101.210...
Connected to mail.junjie.com (192.168.101.210).
Escape character is '^]'.
220 Welcome to our mail.junjie.com ESMTP,Warning: Version not Available!
EHLO mail.junjie.com
四、安装Courier authentication library
[root@mail mail]# tar -jxvf courier-authlib-0.63.1.20111230.tar.bz2 -C /usr/src/
[root@mail mail]# cd /usr/src/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 courier-authlib-0.63.1.20111230]# cd /usr/local/courier-authlib/var/spool/
drwxr-x--- 2 daemon daemon 4096 Apr 9 17:38 authdaemon
[root@mail spool]# chmod 755 authdaemon/
[root@mail spool]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@mail spool]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
27 authmodulelist="authmysql"
34 authmodulelistorig="authmysql"
[root@mail spool]# vim /etc/authmysqlrc
MYSQL_SERVER localhost
MYSQL_PORT 3306 #(指定你的mysql监听的端口,这里使用默认的3306)
MYSQL_USERNAME extmail #(这时为后文要用的数据库的所有者的用户名)
MYSQL_PASSWORD extmail #(密码)
[root@mail ~]# cd /usr/src/courier-authlib-0.63.1.20111230/
[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]# cd
[root@mail ~]# chmod 755 /etc/init.d/courier-authlib
[root@mail ~]# chkconfig --add courier-authlib
[root@mail ~]# chkconfig --level 2345 courier-authlib on
[root@mail ~]# chkconfig --list courier-authlib
[root@mail ~]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
[root@mail ~]# service courier-authlib start
Starting Courier authentication services: authdaemond
#接下来重新配置SMTP 认证,编辑/usr/lib/sasl2/smtpd.conf ,
[root@mail ~]# vim /usr/lib/sasl2/smtpd.conf
4 authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
五、让postfix支持虚拟域和虚拟用户
659 ########################Virtual Mailbox Settings########################
660 virtual_mailbox_base = /var/mailbox
661 virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
662 virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
663 virtual_alias_domains =
664 virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
665 virtual_uid_maps = static:2525
666 virtual_gid_maps = static:2525
667 virtual_transport = virtual
668 maildrop_destination_recipient_limit = 1
669 maildrop_destination_concurrency_limit = 1
670 ##########################QUOTA Settings########################
671 message_size_limit = 14336000
672 virtual_mailbox_limit = 20971520
673 virtual_create_maildirsize = yes
674 virtual_mailbox_extended = yes
675 virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit _maps.cf
676 virtual_mailbox_limit_override = yes
677 virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later.
678 virtual_overquota_bounce = yes
[root@mail mail]# tar -zxvf extman-1.1.tar.gz
[root@mail docs]# mysql -u root -p <extmail.sql
[root@mail docs]# mysql -u root -p <init.sql
mysql> show databases;
| information_schema |
4 rows in set (0.01 sec)
[root@mail docs]# cp mysql* /etc/postfix/
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 [email protected] IDENTIFIED BY 'extmail';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
说明:启用虚拟域以后,需要取消中心域,即注释掉myhostname, mydestination, mydomain, myorigin几个指令;当然,你也可以把mydestionation的值改为你自己需要的。
[root@mail docs]# vim /etc/postfix/main.cf
162 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
163 # mail.$mydomain, www.$mydomain, ftp.$mydomain
六、配置dovecot
205 mail_location = maildir:/var/mailbox/%d/%n/Maildir
415 home_mailbox = Maildir/
[root@mail ~]# vim /etc/dovecot-mysql.conf
2 connect = host=localhost dbname=extmail user=extmail password=extmail
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 mailbo x WHERE username = '%u'
Starting Dovecot Imap: [ OK ]
七、安装Extmail-1.2 (先安装httpd)
[root@mail mail]# mkdir -pv /var/www/extsuite
mkdir: created directory `/var/www/extsuite'
[root@mail mail]# tar -zxvf extmail-1.2.tar.gz -C /var/www/extsuite/
[root@mail mail]# tar -zxvf extman-1.1.tar.gz -C /var/www/extsuite/
[root@mail extsuite]# mv extmail-1.2/ extmail
[root@mail extsuite]# mv extman-1.1/ extman
[root@mail extmail]# cp webmail.cf.default webmail.cf
[root@mail extmail]# vim /var/www/extsuite/extmail/webmail.cf
197 SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
由于extmail要进行本地邮件的投递操作,故必须将运行apache服务器用户的身份修改为您的邮件投递代理的用户;本例中打开了apache服务器的suexec功能,故使用以下方法来实现虚拟主机运行身份的指定。此例中的MDA为postfix自带,因此将指定为postfix用户:
[root@mail ~]# vim /etc/httpd/conf/httpd.conf
992 <VirtualHost 192.168.101.210:80>
993 ServerName mail.junjie.com
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>
修改 cgi执行文件属主为apache运行身份用户:
[root@mail ~]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
[root@mail mail]# tar -zxvf Unix-Syslog-1.1.tar.gz
[root@mail Unix-Syslog-1.1]# perl Makefile.PL
[root@mail Unix-Syslog-1.1]# make install
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using mail.junjie.com for ServerName [ OK ]
八、安装Extman
[root@mail Unix-Syslog-1.1]# cd /var/www/extsuite/extman
修改配置文件以符合本例的需要:
[root@mail extman]# cp webman.cf.default webman.cf
12 SYS_MAILDIR_BASE = /var/mailbox
21 SYS_CAPTCHA_ON = 0
修改cgi目录的属主:
[root@mail extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行:
[root@mail extman]# vim /etc/httpd/conf/httpd.conf
992 <VirtualHost 192.168.101.210:80>
993 ServerName mail.junjie.com
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
999 </VirtualHost>
创建其运行时所需的临时目录,并修改其相应的权限:
mkdir: created directory `/tmp/extman'
[root@mail extman]# chown postfix.postfix /tmp/extman
好了,到此为止,重新启动apache服务器后,您的Webmail和Extman已经可以使用了,可以在浏览器中输入指定的虚拟主机的名称进行访问,如下:
[root@mail extman]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using mail.junjie.com for ServerName
[ OK ]
说明:
九、测试
选择管理即可登入extman进行后台管理了。默认管理帐号为:[email protected] 密码为:extmail*123*
#选择管理即可登入extman进行后台管理了。默认管理帐号为:[email protected] 密码为:extmail*123*
##用户[email protected]注册
Apr 9 20:42:56 mail extmail[15058]: user=<[email protected]>, client=192.168.101.1, module=login, status=loginok
Apr 9 20:44:15 mail postfix/smtpd[15067]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Apr 9 20:44:15 mail postfix/smtpd[15067]: connect from localhost.localdomain[127.0.0.1]
Apr 9 20:44:15 mail postfix/smtpd[15067]: C0F7E16DF4C: client=localhost.localdomain[127.0.0.1]
Apr 9 20:44:15 mail postfix/cleanup[15073]: C0F7E16DF4C: message-id=<[email protected]>
Apr 9 20:44:15 mail postfix/qmgr[14514]: C0F7E16DF4C: from=<[email protected]>, size=659, nrcpt=1 (queue active)
Apr 9 20:44:15 mail postfix/smtpd[15067]: disconnect from localhost.localdomain[127.0.0.1]
Apr 9 20:44:15 mail postfix/virtual[15075]: C0F7E16DF4C: to=<[email protected]>, relay=virtual, delay=0.29, delays=0.17/0.08/0/0.04, dsn=2.0.0, status=sent (delivered to maildir)
Apr 9 20:44:15 mail postfix/qmgr[14514]: C0F7E16DF4C: removed
Apr 9 20:51:35 mail extmail[15177]: user=<[email protected]>, client=192.168.101.1, module=login, status=loginok
Apr 9 20:53:59 mail postfix/smtpd[15190]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Apr 9 20:53:59 mail postfix/smtpd[15190]: connect from localhost.localdomain[127.0.0.1]
Apr 9 20:54:00 mail postfix/smtpd[15190]: 0AB0F16DF71: client=localhost.localdomain[127.0.0.1]
Apr 9 20:54:00 mail postfix/cleanup[15196]: 0AB0F16DF71: message-id=<[email protected]>
Apr 9 20:54:01 mail postfix/qmgr[14514]: 0AB0F16DF71: from=<[email protected]>, size=4801480, nrcpt=1 (queue active)
Apr 9 20:54:01 mail postfix/smtpd[15190]: disconnect from localhost.localdomain[127.0.0.1]
Apr 9 20:54:01 mail postfix/virtual[15199]: 0AB0F16DF71: to=<[email protected]>, relay=virtual, delay=1.4, delays=1.2/0.05/0/0.21, dsn=2.0.0, status=sent (delivered to maildir)
Apr 9 20:54:01 mail postfix/qmgr[14514]: 0AB0F16DF71: removed
--xjzhujunjie
--2012/04/09—21:25