服务器 | 设计圈 |


777yjt 的BLOG 
留言  收藏

2008 11.18 Tue
      1
2345678
9101112131415
16171819202122
23242526272829
30      
«» 2008 - 11 «»

搜索BLOG文章

 

博客基本信息
用户名: 777yjt
等级: 四星会员
威望: 4360
金钱: 10875
在线时间: 2786 分钟
日志总数: 2175
评论数量: 24
访问次数: 92189
建立时间: 2006-10-07




XML RSS 2.0 WAP

作者: 777yjt   发表日期: 2006-12-01
复制 TAG: 收藏



1、简介

近年来几种新的web邮件产品(如IMP)的出现使web设计者能利用这些产品很容易的实现基于web的邮件系统。然而随着使用这些产品的web邮件系统解决方案日趋流行,web邮件系统的可扩展性的矛盾就日益尖锐。大多数web邮件系统(不仅仅局限于开放资源的软件)都是在单邮件服务器单web服务器上实现的,从而出现了单个服务器的性能瓶颈。如果系统需要扩展到可以同时支持数以千记的用户时,往往就出现问题。所以需要一种有良好的可扩展性的web邮件解决方案。

1.1、背景材料

基于web的邮件系统的发展是速度非常迅猛的,随着bigfoot,hotmail,rocketmail等wen邮件系统的出现,web系统应用日益受欢迎。从而其他很多ICP也纷纷在自己的站点上添加WEB邮件服务。由此,诸如EmuMail及IMP的产品开始出现来实现WEB邮件系统。然而,随着基于这些产品的web邮件站点变的越来越受欢迎,逐渐增加了网络及服务器的负载。由于没有可定制的解决方案,如hotmail等直接使用现成的这些产品的web邮件系统逐渐出现了问题。所以,对寻找一种即相对容易实现又有良好的可扩展性,可以支持几千到百万级的用户的的web邮件的解决方案变的越来越重要。

某ICP的web系统的的解决方案是:两台服务器,一台运行 Sendmail和UW IMAP,另外一台运行IMP(IMP的相关材料可以通过访问这里得到),其可以说是最棒的一个使用PHP开发的开放源代码web邮件系统。该系统非常容易实现,并且工作情况良好。然而,若干个月以后,随着申请用户的到达一定数量,可以明显的发现该系统的负载过大。所以需要寻求一种新的解决方案,同时由于该ICP已经有一定数量的用户,所以而且不能丢弃这些用户的信件。先前该ICP选择IMP是出于起优秀的性能及遵从开放源代码的特点(这样以来,就可以自己对IMP进行二次开发而不涉及版权问题)选择Sendmail和UW IMAP是因为它们都是标准的工具。但是这两个系统虽然功能完善强大但是过于庞大复杂,从而影响了其运行效率,所以寻找其他的替代工具。这里推荐一个名为postfix的工具来替代sendmail,因为它至少要比sendmail快三倍,而且其同样是免费软件;用cyrus来替代UW IMAP,是因为cyrus不需要使用系统的帐户而且不象UW IMAP那样消耗资源。这里仍然使用IMP是由于其易于配置,无须考虑版权问题而且可以保持用户以前的界面不变。同时,postfix也支持LDAP(LDAP可以在这里 这里 这里得到),可以使用LDAP作为其别名数据库(使用maildrop属性及mailacceptinggeneralid属性)。同样的,有一个Cyrus补丁可以使Cyrus使用LDAP服务器实现身份验证。将前述各种工具和对多台前端web/incoming邮件服务器的DNS查询实施轮转响应结合起来,就有了构造一个有良好的可扩展性的web邮件系统的解决方案所需要的全部构件。下面的问题就是如何配置安装了。

将这些元素组成一个基于web的邮件系统也不是一个困难的事情。可扩展性来自于postfix基于LDAP服务器的maildrop特性可以将邮件转发到别的用户或者服务器的功能。只需要为maildrop特性提供一个完整的邮件地址,该完整的邮件地址指出了该用户的用户邮件所在的真正的服务器。例如:DNS的MX记录指向前端邮件服务器mail.dom.ain,并且LDAP指示发送到地址user@dom.ain的邮件实际上是发送往user@machine44.dom.ain,然后运行在前端邮件服务器的postfix将把该邮件转发给服务器machine44上的user用户。使用这个特性,管理员就可以在本地域没有限制地开邮件用户。在性能需要时,只需要增加后端邮件服务器即可。 这里面比较棘手的问题是如何从后端的邮件服务器中取得邮件,然后传递给IMP。由于IMP已经提供在不同的服务器上WEB服务器和邮件服务器的支持。所以需要解决的问题是如何从LDAP服务器上取邮件服务器名,而不是依赖于配置设置及单台邮件服务器。

实践证明设置邮件服务器是非常容易实现的。只需要在一个文件中仅仅几行代码,并且IMP的缺省的配置文件中增添新的配置参数。这里使用postfix及IMP分别实现在多个邮件服务器发送(forwarding)读取邮件。

然而,UW IMAP仍然是一个需要解决的问题,由于多个原因,它的效率对于大型web文件系统来说过于低下:它使用一个没有分层的文件,这种结构对于大量邮件消息可扩展性不够好,它使用Linux主机自身的认证系统,而主机认证系统需要为用户建立主机系统帐户,而且每次认证都需要解析/etc/passwd文件,所以效率相对来说比较低下。故这里使用Cyrus来替代UW IMAP,Cyrus来作为系统的IMAP服务器不具有上面所述的缺陷。而且,通过Clayton Donely开发的Cyrus的LDAP补丁http://www.linc-dev.com/,这里可以使用与postfix相同的LDAP来实现认证。这样就使新的WEB邮件系统不但有良好的可扩展性,而且很轻便。系统里不需要保存多个口令拷贝,只需要在LDAP中保存一份就足够了。这就是LDAP的设计目标。

这个系统具有若干个web/mail服务器,在客户(浏览器)对前端邮件服务器进行DNS查询时,DNS被配置为该域名在若干台web/mail服务器间轮转。这些web/mail服务器使用LDAP服务器选择一个合适的后端邮件服务器来转发和读取邮件,而后端的邮件服务器服务器同样借助LDAP服务器来进行用户认证。由于LDAP服务器也是可备份的。所以整个系统里任何一个节点的崩溃会导致系统的不可用。这正是可扩展性的实现目标。

1.2 要求

该文档提到了三种服务器:web服务器,imap服务器和LDAP服务器。这些服务器可以位于独立的主机上,或若干个独立的机器上(例如:23个web服务器,5个LDAP服务器和10个IMAP服务器),或单台服务器上。同时需要具有在Linux环境下从源代码安装软件的基本知识

1.3 使用的软件

构建该系统需要以下的软件包: Apache 1.3.6 或以上版本http://www.apache.org/ PHP 3.0.12 需要将对IMAP和LDAP的支持编译进来 OpenLDAP 1.2 Cyrus 1.5.19 (注:不要使用1.6) postfix 19990627 pwcheck_ldap patch (针对cyrus 1.5的) IMP (2.0.4, 2.0.10, 和2.1.3-dev进行了测试) UW IMAP (针对 c-client) 注:cyrus 1.6树使用了一种不同的,被称作SASL的鉴别方法,pwcheck_ldap补丁不是针对这种鉴别方法设计的。然而,对SASL的LDAP的补丁正在设计中,你可以参观该主页来获得最新信息。

1.4 特别注释

该系统有一个部分的可伸缩性不是很好:IMP使用的用来保存会话数据,参数,及地址簿的SQL服务器。

2. 安装软件 2.1 Web服务器的安装

在web服务器上,管理员需要安装下列软件包:Apache, PHP, postfix, OpenLDAP, UW IMAP, 及IMP. 安装Apache和PHP是很容易的,具体步骤在PHP软件包中的安装导引有详细的说明。在安装PHP时,你需要将对LDAP和IMAP的支持编译进来。 安装postfix可以参考随软件包的安装指南,特别要注意文件LDAP_README。

2.2 LDAP服务器的安装

需要安装OpenLDAP软件来构建LDAP服务器。你需要决定一个root dn并相应地向LDAP的db中加入设置。

2.3 IMAP服务器的安装

在IMAP服务器上,你将需要安装LDAP, postfix, Cyrus及cyrus的pwcheck_ldap补丁。编译postfix时需要有加入对ldap的支持。根据软件安装文档安装Cyrus,但是需要根据pwcheck_ldap补丁的文档对pwcheck_ldap.c进行修改。另外需要修改pwcheck_ldap.c来提供ldap服务器及根dn信息;同样若在linux服务器上运行IMAP服务器,则需要在在文件pwcheck_ldap.c作如下修正: 增加行: #include <linux/stddef.h> 另外还需要做一些别的语法修改,具体可以在编译是发现。 使用下面的命令配置cyrus:

./configure --with-login=unix_pwcheck --with-pwcheck=ldap

后面的编译及安装则根据cyrus的文档;

3. 如何配置服务器协同工作

3.1 LDAP服务器的配置

每个在LDAP数据库中的邮件用户信息除了其他的希望提供的信息以外需要有下面的内容:(假设你的根dn是o=someorg, c=US):

dn: uid=someuser, o=someorg, c=us
uid: someuser
userpassword: somepassword
maildrop: fulladdress@machine.dom.ain
mailacceptinggeneralid: someuser
mailacceptinggeneralid: somealias

同样,需要选择一个用户拥有cyrus管理权限。只有需要在imap服务器上配置cyrus时,才会需要考虑管理问题。另外,最好不要给一个已经存在的用户添加管理权限,这样做可能导致安全问题或者导致该用户不能查看自己的信件的问题。

3.2 imap服务器的配置

配置在IMAP服务器上的postfix使用ldap来进行别名匹配。在文档LDAP_README对这个问题进行了说明。对于Cyrus,按照软件包的安装说明文件进行即可。同样,不要忘记激活pwcheck并在imap.conf中增添管理用户。

3.3 web服务器
在这一步的设置中,web服务器同样是作为接收邮件网关的前端。配置postfix来使用ldap进行别名匹配。从而实现检查LDAP的maildrop表项并转发该邮件到maildrop地址,所以在maildrop中需要全邮件名。 例如,你可以将700,000个用户分配到各个服务器上,平均每台服务器10000个用户。邮件目的地址是user1@dom.ain的邮件将接入到某台WEB服务器,而该邮件将根据maildrop属性被转发到地址,而发网user657的邮件将被转发给user657@mail34。而且,maildrop属性同时可以被用作转发地址,如给user302的信件被转发给someuser@somewhereelse.com>

例如,你可以将700,000个用户分配到各个服务器上,平均每台服务器10000个用户。邮件目的地址是user1@dom.ain的邮件将接入到某台WEB服务器,而该邮件将根据maildrop属性被转发到地址,而发网user657的邮件将被转发给user657@mail34。而且,maildrop属性同时可以被用作转发地址,如给user302的信件被转发给someuser@somewhereelse.com

对IMP的培配置一般将根据软件文档,配置结束以后,需要做如下修改: 在config/defaults.php3增添如下内容:

 

/* LDAP/IMAP Server Default */
$default->LDAP_server = 'ldap.dom.ain';
$default->LDAP_dn = 'o=someorg,c=US';
$default->LDAP_search_field = 'uid';
$default->ldap_choose_server = true;

to mailbox.php3 apply the following patch:
Index: mailbox.php3
===================================================================
RCS file: /home/cvs/imp/mailbox.php3,v
retrieving revision 2.29
diff -c -r2.29 mailbox.php3
*** mailbox.php3 1999/07/29 07:20:00 2.29
--- mailbox.php3 1999/08/04 18:04:10
***************
*** 29,34 ****
--- 29,51 ----
require './lib/mimetypes.lib';
require './config/defaults.php3';

+ /************LDAP**************/
+
+ if ($default->ldap_choose_server) {
+ $ldapconnect = ldap_connect($default->LDAP_server);
+ if ($ldapconnect) {
+ print("YES!");
+ $ldapbind = ldap_bind($ldapconnect);
+ $ldapsearch = ldap_search($ldapconnect, $default->LDAP_dn, $default->LDAP_search_field."=".$imapuser, array("maildrop"));
+ $ldapget = ldap_get_entries($ldapconnect, $ldapsearch);
+ $ldapspl = explode("@", $ldapget[0]["maildrop"][0]);
+ $server = $ldapspl[1];
+ $port = $default->port;
+ }
+ }
+ /**********end ldap************/
+
+
/* Html styles configuration */
require './config/html.php3';
/* Mailbox configuration */
全部配置结束以后,将具有一个高可扩展性的web邮件系统。
注:1999年8月,IMP的新版本已经包含了这些补丁的内容,所以如果使用新版本的话,就不需添加这些内容。


4. Miscellaneous

4.1 Adding Users

这里是一小段向LDAP服务器中增添用户的代码,并且同时向cyrus增添一个邮件用户。这是针对IMAP服务器设计的,但是你可以修改其适应别的环境。

<?php
$ldapconn = ldap_connect(ldap.dom.ain);
$machine = mail01;
if ($ldapconn)
{
$ldhb = ldap_bind($ldapconn, cn=cyrusadmin, o=someorg,c=US,password);
$dn = uid=. $username ., o=someorg, c=US;
$info[uid]=$username;
$info[userpassword] = $password;
$info[objectclass] = account;
$info[maildrop] = $username .@ .$machine ..dom.ain;
$info[mailacceptinggeneralid] = $username;
$ldhb = ldap_add($ldapconn, $dn, $info);
ldap_close($ldapconn);
}
$imapconn = imap_open({ .$machine ..dom.ain:143}, cyrusadmin,password);
if ($imapopen)
{
imap_createmailbox($imapconn, { .$machine .dom.ain:143}user..$username );
imap_close($imapconn);
}
?>

相关链接:
BtoC 电子商务网站的赢利模式探索 http://club.sob8.com/read-htm-tid-40157.html


本文地址http://777yjt.sob8.com/blog-htm-do-showone-itemid-5348.html



文章评论1205条回复
  guest
2008-10-29


2GB MP3 PLAYER Brian Kopp's World of Warcraft Alliance. 4GB MP3 PLAYER Leveling Guide also includes numerous. buy wow gold tips for improving leveling speed I found. buying gold world of warcraft this tips alone to be very helpful They. cell phones improved my Alliance leveling speed. cheap cell phones tremendously Brian Kopp was also a beta. cheap wow gold tester for the Burning Crusade expansion. cheap wow gold and released the update 60-70 portion of. cheap wow gold his guide within a week of when Burning. cheapest wow gold Crusade became available Brian Kopp's WoW. eve isk Alliance Leveling Guide is easily the best. mp3 players resource available for any Alliance player. phones cell looking to improve their leveling in World. portable mp3 player of Warcraft All of the quest information. portable mp3 players for each Alliance race in condensed into. sell wow gold an easy to follow step-by-step guide I. world of warcraft gold found it a struggle sometimes to keep track. wow of where I should go next with James WoW Alliance. wow gold Leveling Guide That wasn't the case with. wow gold Brian Kopp's guide His guide has helped. wow gold my new Night Elf Hunter get to level. wow gold 20 in record time I'm leveling faster than. wow gold ever now I wish I had picked up Brian. wow gold Kopp's World of Warcraft Alliance Leveling. wow gold kaufen Guide sooner. wow gold kaufen



  guest
2008-10-29


8GB MP3 PLAYER which looks like a small Chinese dragon. apple ipod according to tipster Ichthallus This. canon digital camera competition does not appear to be live on. cheap world of warcraft gold the US Servers nor has anyone from. digital camera Blizzard. digital cameras spoken up to reveal if it ever . dvd player will be as of this writing We'll have to. eve isk watch and see what happens As Blizzard does. ipod not appear to be an official Olympic partner there. ipod nano is some concern from some quarters that. ipod shuffle this could simply be a copyright issue It's. ipod touch also possible that this was meant to be. ipods a Chinese servers only event and it.mp3 only accidentally got onto the EU servers. mp3 player Thanks to everyone who sent us tips on this. mp3 players The olyimpcs have a "global" start time. mp4 - if this is being released in such. portable dvd players a manner as you suggest they would be. world of warcraft buy gold starting 8/8/8 and I'm guessing 8:08pm china. wow time for each version At a off hand. wow gold guess that'd be around 3am on th. wow gold e 7th for us players I think. wow leveling Don't let the machinima snobs ruin your fun. wow powerleveling Demachic is a 13 year old girl from Ireland. zubehoer mp3 player


  guest
2008-10-29


buy cheap wow gold Despite the extensive problems and human. des po wow violations rights perpetuated by the. free online games Chinese government some in service of the. free online war games Olympic games themselves most of the world. gold wow seems to content to settle in and watch. gold wow the Beijing Olympics one way or another. mp3 player Apparently that attitude has spread to. online games Blizzard itself Currently on the European. play war games and Chinese servers there are NPCs at each. po wow major Battlemaster area in the capital. world of warcraft cities who proclaim that Battlegrounds are. world of warcraft hosting some type of "Spirit of Competition.wow For simply participating in a battleground. wow you are sent a Competitor's Tabard. wow europe which features 4 multi-colored rings on. wow geld a white background a clear reference to. wow gold the Olympics itself If you win. wow gold guide a battleground during this time period you. wow gold guide may also have a chance at receiving a gold. wow gold guide medal which summons a spirit of. wow gold verkaufen competition but it's not an exact. wow level service replica While I normally hate on. wow leveling service excessive varying transitions her. wow powerleveling guide use of them only enhances the video I'm. wow powerleveling guide eager to see. .


  guest
2008-10-29


cheap wow power leveling I'm moving this weekend and packing and. gold für wow kaufen cleaning all week so this week's episode is. gold kaufen wow a short one When I first heard that. HDRO gold Blizzard announced the Recruit-a-Friend. level wow program was going to be giving zhevra. lord of rings online gold mounts as incentive I must say that. lotro gold I heaved a very audible groan You see we've. lotro gold already referred all the friends we can. po wow talk into playing the last of which we drug into. power level our mad little World of Warcraft not even. power level a month ago So after reading through all the. wow geld kaufen things being offered as referral. wow gold incentive my significant other decided to. wow gold guide make the suggestion that I start a new. wow level account so that he can have a zhevra mount. wow leveling My response was something very similar. wow lvl to what you see when you click the banner. wow lvl That and I had to torture the target of what. wow lvl 60 I consider to be one of the most annoying. wow lvl 70 quests ever Two hours for four hooves. wow power leveling is crazy, and I am apparently that. wow powerlevel unlucky Philo you've commented before. wow powerlevel on your dislike of this comic Why. wow powerleveling the hell do you keep reading it and posting. wow powerleveling guide People have seen your negative criticism. .

<<   1   2   3   4   5  >>  Pages: ( 1/61 total )