字扩展,位扩展,和字位扩展
One morning you wake up, grab some coffee, and check the how many people visited your site yesterday. (C’mon, admit it! I know I do it every day!) You look at the numbers and they just don’t look right. Maybe your coffee isn’t strong enough — there has to be a decimal point in there somewhere! They’re all too big! You received ten thousand new visitors yesterday …and it’s climbing rapidly. You’re finally making it big!
一天早上,您醒来,喝杯咖啡,然后检查昨天有多少人访问了您的网站。 (来吧,承认这一点!我知道我每天都在做!)您查看这些数字,但它们看起来并不正确。 也许您的咖啡不够浓-某处必须有一个小数点! 它们太大了! 昨天您收到了1万名新访客……而且它还在Swift攀升。 您终于要变大了!
Next, you check your email, and find a note from your ISP telling you that you need to either upgrade to a more expensive plan, or pay a fortune for bandwidth. Oh no! What to do? Well, if you designed your site properly, you can smile with the knowledge that you have everything under control.
接下来,您检查电子邮件,并从ISP找到一条说明,告知您需要升级到更昂贵的计划,或者为带宽付出大笔费用。 不好了! 该怎么办? 好吧,如果您对网站进行了适当的设计,则可以在知道一切已得到控制的情况下微笑。
You’ve reached the point where you need multiple servers. It’s time to figure out how to keep your site up and running without breaking the bank. It’s important to note that this article is also relevant to you even if you don’t have a dedicated server — it’s often beneficial to have several smaller accounts than one large one.
您已达到需要多台服务器的地步。 现在是时候弄清楚如何在不破坏资金的情况下保持网站正常运行。 重要的是要注意,即使您没有专用的服务器,本文也与您相关-与多个大型帐户相比,拥有多个较小的帐户通常是有益的。
This article will first discuss the example of a budget scalable Website, then briefly talk about the proper way to design a site of your own. Unfortunately, this method can be prohibitively expensive for small Webmasters, but it is important to know. Next, we’ll discuss how you can design a Website so that it will be easy to scale in the future, and won’t force you to radically revamp your current way of working. Finally, I’ll talk about how to convert an existing Website into a scalable site, and we’ll explore some of the technical hurdles that need to be overcome.
本文将首先讨论可扩展预算的网站示例,然后简要讨论设计自己的网站的正确方法。 不幸的是,这种方法对于小型网站管理员来说可能是昂贵的,但是要知道这一点很重要。 接下来,我们将讨论如何设计网站,以便将来轻松扩展网站,并且不会迫使您从根本上改变当前的工作方式。 最后,我将讨论如何将现有网站转换为可扩展的网站,并且我们将探讨一些需要克服的技术障碍。
Why does one need to specifically design a site to be scalable? Well, let me give you an example.
为什么需要专门设计一个可扩展的网站? 好吧,让我举一个例子。
I’m sure you’ve heard of the ever-popular “Am I Hot or Not” Website? Two college students had some free time and one day they came up with a great idea. They thought, wouldn’t it be cool to make a site where visitors can upload their own picture and have other people vote if they’re hot or not? It’s an addictive combination and it’s no surprise that virtually overnight, the site went from receiving no hits to several million an hour. They were suddenly faced with what had become the challenge to keep their site running.
我确定您已经听说过广受欢迎的“ 我热不热 ”的网站吗? 两名大学生有一些空闲时间,有一天他们想到了一个好主意。 他们认为,建立一个站点可以让游客上传自己的图片并让其他人投票(无论他们是否热)都不错吗? 这是一种令人上瘾的组合,而且几乎在一夜之间,该网站从没有受到点击的情况发展到每小时几百万也就不足为奇了。 他们突然面临保持网站正常运行的挑战。
They quickly made a key observation: every page view is independent of every other. So, if you’re viewing one page of the site, it makes no difference from which server the next page is served. This is because there are only two parts to the Website: view pages, and recording votes. This situation greatly simplified matters for these particular Webmasters. They simply used one main SQL database, and had other servers calling it for each page view. This way, they could distribute the load without having to significantly change the way their program worked.
他们很快做出了关键观察:每个页面视图彼此独立。 因此,如果您正在查看网站的一页,则与提供下一页的服务器没有区别。 这是因为网站只有两部分:查看页面和记录投票。 这种情况大大简化了这些特定网站管理员的工作。 他们仅使用一个主SQL数据库,并让其他服务器为每个页面视图调用该数据库。 这样,他们可以分配负载,而不必显着更改程序的工作方式。
So they upgraded to seven servers in seven days and, not surprisingly, their database server started choking. They noticed that almost every page simply makes a SELECT query from a database, and each vote was written right back to the database. However, they decided there was no real reason for votes to be recorded right away – after all, who would notice if the number of votes displayed was a few hours old? So, at first they simply cached the vote data and updated it periodically.
因此,他们在7天之内升级到了7台服务器,并且毫不奇怪,他们的数据库服务器开始阻塞。 他们注意到几乎每个页面都只是简单地从数据库中进行SELECT查询,并且每次投票都直接写回到数据库中。 但是,他们认为没有真正的理由立即记录投票-毕竟,谁会注意到显示的投票数是否早了几个小时? 因此,起初他们只是缓存投票数据并定期对其进行更新。
Then, after a few more days, their server started choking again, and they upgraded to running multiple database servers. From that point, they were able to scale to any size they needed, eventually reaching more than 17 servers! Now let’s see how you can do the same, on an even smaller budget. The Ideal Scalable Website Architecture Building a scalable Website can be a very tricky proposition. It involves a lot of redundancy, load balancing, multiple Webservers, a separate database server, and backup servers. For example, in the figure below, all connections to the Internet first go through a load balancer.
然后,又过了几天,他们的服务器再次开始阻塞,并升级为运行多个数据库服务器。 从那时起,他们就可以扩展到所需的任何大小,最终达到17台以上的服务器! 现在,让我们看看如何以更低的预算实现相同的目标。 理想的可扩展网站体系结构构建可扩展网站可能是一个非常棘手的问题。 它涉及大量冗余,负载平衡,多个Web服务器,单独的数据库服务器和备份服务器。 例如,在下图中,到Internet的所有连接都首先通过负载均衡器。
A load balancer will distribute traffic according to a procedure that you, as Webmaster, set up. For example, it may send most of the traffic to the server with the lowest load average. This helps keep response times nice and low, even if your site is linked to from CNN.com. Multiple servers are used to help keep the system fault-tolerant. If one server crashes, the traffic can be diverted to the other servers. The same applies to the database – there is a replicated backup in case the main database goes offline.
负载平衡器将根据您作为网站管理员设置的过程分配流量。 例如,它可以将平均流量最低的大多数流量发送到服务器。 即使您的网站是从CNN.com链接到的,这也有助于使响应时间保持良好和较低的状态。 使用多个服务器来帮助保持系统的容错能力。 如果一台服务器崩溃,则可以将流量转移到另一台服务器。 这同样适用于数据库–如果主数据库脱机,则有一个复制的备份。
As you’ve probably guessed by now, such a setup can be very expensive. Nonetheless, I urge you to look into such a system if you have the time, money, and ambition. The exact details of a complete architecture are beyond the scope of this article, but there are numerous books on this topic.
您可能已经猜到了,这样的设置可能非常昂贵。 但是,如果您有时间,金钱和野心,我还是敦促您研究这样一个系统。 完整体系结构的确切细节不在本文的讨论范围之内,但是有关该主题的书籍很多。
Fortunately for the rest of us, there’s a higher-risk, but cheaper and easier method.
幸运的是,对于我们其他人,这是一种风险更高,但更便宜且更容易的方法。
For those of us who can barely afford a single server, much less seven, there is an incremental approach you can follow. Simply design your site so it can run on one or more servers. If you’re doing well, why not rent a new server, set up your software on this server, and tell your old servers about the new one. While this is not as easy as it sounds, it’s quite doable. Simply keep a few key ideas in mind when you design your site, and should it ever dramatically grow in popularity, you won’t even break a sweat (unless it’s from a victory dance).
对于那些几乎买不起一台服务器(少于7台)的人来说,可以采用一种增量方法。 只需设计您的站点,使其可以在一台或多台服务器上运行。 如果您做得不错,为什么不租一台新服务器,在这台服务器上安装软件,并告诉旧服务器有关新服务器的信息。 尽管这听起来并不容易,但确实可行。 在设计网站时,只需记住一些关键思想,并且一旦它Swift流行起来,您甚至都不会汗流(背(除非它来自胜利之舞)。
As we’re on a budget, there are a few constraints to keep in mind. We can’t afford to run servers from our office — instead we’re going to use the many inexpensive dedicated Web hosts out there. We want to be able to add or remove servers at will, depending on traffic, and we want to minimize bandwidth usage to save costs.
由于我们的预算有限,因此需要牢记一些限制。 我们负担不起从办公室运行服务器的费用–相反,我们将在那里使用许多便宜的专用Web主机。 我们希望能够根据流量随意添加或删除服务器,并且希望最大程度地减少带宽使用量以节省成本。
Unfortunately, most budget dedicated Internet hosts are not very helpful when it comes to setting up the kind of tiered server discussed above — they will charge you a lot of money to connect several servers together. So, we want to avoid having a separate database server if at all possible. Please note that if only occasional lookups or writes are made to the database, it’s perfectly reasonable to send the requests over the Internet – this scenario won’t use up a lot of bandwidth.
不幸的是,在设置上面讨论的那种分层服务器时,大多数预算专用的Internet主机不是很有帮助-它们将向您收取大量费用以将多个服务器连接在一起。 因此,我们尽可能避免使用单独的数据库服务器。 请注意,如果仅偶尔对数据库进行查询或写入,则通过Internet发送请求是完全合理的-这种情况不会占用很多带宽。
Master and Slave Sites
主站点和从站点
First off, there are many different ways to design a scalable site. The easiest, though not necessarily the best, is simply to create a master site, and several slave sites: one main site from which all the others are replicated. Everything is copied – the database, HTML pages, everything (though you may want to use one database and have all the servers link to it in order to maintain consistency).
首先,有许多不同的方法来设计可伸缩站点。 最简单(虽然不一定是最好的)只是创建一个主站点和几个从属站点:一个主站点,从中复制所有其他站点。 一切都被复制了–数据库,HTML页面以及所有内容(尽管您可能想使用一个数据库,并且所有服务器都链接到该数据库以保持一致性)。
For example, on sitepoint.com it does not matter from which server an article is served. You may view page one of this article from a server in Sydney, and the second from a server in Detroit, and you’d never know the difference – nor does it particularly matter. However, they have a nifty little voting mechanism at the bottom of the article (you want to press the button below the number ten on this article to see what happens!). Clicking this button could hit the master server instead of a slave and update the database appropriately. Then, if you use multiple databases, once a day (or instantly if you use database replication) the data will be copied to each of the slave servers.
例如,在sitepoint.com上,从哪个服务器提供文章都没有关系。 您可能在悉尼的服务器上浏览了本文的第一页,而在底特律的服务器上浏览了第二页,您将永远不会知道两者之间的区别,也没有什么特别重要的。 但是,它们在文章底部有一个很小的投票机制(您想按一下本文数字10下方的按钮以查看会发生什么!)。 单击此按钮可以命中主服务器而不是从服务器,并适当地更新数据库。 然后,如果您使用多个数据库,则每天一次(或者如果您使用数据库复制则立即)将数据复制到每个从属服务器。
The easiest way to send users to a random server is to use a round robin DNS server. A round robin setup would send each request to a random server. However, because each request goes to a different server, it is hard to track session data (such as the user’s login details). To counter this, you can use cookies or hidden HTML fields.
将用户发送到随机服务器的最简单方法是使用轮询DNS服务器。 轮询设置会将每个请求发送到随机服务器。 但是,由于每个请求都发送到不同的服务器,因此很难跟踪会话数据(例如用户的登录详细信息)。 为了解决这个问题,您可以使用Cookie或隐藏HTML字段。
One Server Per Visit
每次访问一台服务器
A variation of this method is to use multiple servers, but have the user view pages served from the same server during their entire visit. You could have www.mysite.com, www2.mysite.com, www3.mysite.com, and so on. When a user visits your site, they are randomly sent to one server (or, if you store the user’s data on a particular server, you’d always send them to that particular server).
此方法的一种变体是使用多个服务器,但在整个访问期间,让用户查看从同一服务器提供的页面。 您可能拥有www.mysite.com,www2.mysite.com,www3.mysite.com等。 当用户访问您的站点时,它们会随机发送到一台服务器(或者,如果将用户的数据存储在特定的服务器上,则始终会将其发送到该特定的服务器)。
This is very simple, and requires virtually no changes to your site. It works well with persistent data and is easy to understand and implement. But it has a very bad Achilles heel: what if everyone starts linking to a page on the www3 server? Or what if www3 crashes? It could be floored or down, leaving the other servers sitting idle. Then again, this method is extraordinarily simple, very effective, and works well on a budget.
这非常简单,几乎不需要更改您的站点。 它与持久性数据一起很好地工作,并且易于理解和实施。 但这有一个非常糟糕的致命弱点:如果每个人都开始链接到www3服务器上的页面怎么办? 还是www3崩溃怎么办? 它可能会掉落或掉下,使其他服务器保持空闲状态。 再说一次,这种方法非常简单,非常有效,并且在预算上效果很好。
Serve Content By Type
按类型提供内容
Another method is to serve one type of content from one server, and a different type from another server. A good example of this might be to put graphics on one server, and dynamic content on another. This allows you to use a slow server and a high bandwidth provider for the graphics, and a higher quality but more expensive server for the content. This works well when you have outgrown the bandwidth allocation of your regular Web hosting account. The hitch? If one server goes down, your entire Website would be, for all practical matters, dead in the water.
另一种方法是从一台服务器提供一种类型的内容,而从另一台服务器提供不同类型的内容。 一个很好的例子就是将图形放在一台服务器上,而动态内容放在另一台服务器上。 这样,您就可以为图形使用慢速服务器和高带宽提供程序,为内容使用更高质量但更昂贵的服务器。 当您的常规Web托管帐户的带宽分配已超出限制时,这将很好地工作。 结? 如果一台服务器出现故障,那么就所有实际问题而言,您的整个网站都将被淹没。
Caching
快取
Caching is also an excellent way to scale Websites. Instead of having the user directly view your main site, they view a cached copy on a different server. In this situation, instead of serving dynamic data, you’re serving static data. One or more main servers generate all the pages and push them out to the other server/s, from which users view your site (for a more automatic and advanced method of doing this, look into using the excellent open-source Squid caching program).
缓存也是扩展网站的绝佳方法。 他们不是让用户直接查看您的主站点,而是查看其他服务器上的缓存副本。 在这种情况下,您将提供静态数据,而不是提供动态数据。 一台或多台主服务器生成所有页面,并将其推送到另一台服务器,用户可以从中查看您的站点(有关更自动和高级的方法,请使用出色的开源Squid缓存程序进行研究) 。
This solution requires only one or two expensive servers, along with several inexpensive auxiliary servers. This technique is simple and effective, though it’s not suitable for sites that are customized for each user.
该解决方案仅需要一台或两台昂贵的服务器,以及几台廉价的辅助服务器。 尽管该技术不适用于针对每个用户定制的站点,但它既简单又有效。
So how does all this help you design your site? Well, some of the lessons learned by exploring each of these alternatives include:
那么,这如何帮助您设计网站? 好吧,通过探索这些替代方法中的每一个,我们汲取的一些教训包括:
Keep your site segmented into sections. For example, keep static content in one directory, and dynamic content in another, to allow easy splitting into multiple servers later.
将您的网站分成多个部分。 例如,将静态内容保留在一个目录中,将动态内容保留在另一个目录中,以便以后轻松拆分为多个服务器。
Try to allow for pages to only use SELECT SQL queries, or session-less pages, to allow for round-robin type Web serving.
尝试允许页面仅使用SELECT SQL查询或无会话页面,以允许循环类型的Web服务。
Never hardcode links to other pages on your site. This way, you can easily update your site if you change its location. Personally, I keep all my internal links in one file and then include them (i.e. <a href="$global_mysiteURL/$home_url">Click here</a>)
切勿硬编码链接到您网站上其他页面的链接。 这样,如果您更改站点的位置,则可以轻松地更新站点。 就个人而言,我将所有内部链接保存在一个文件中,然后将它们包括在内(即<a href="$global_mysiteURL/$home_url">Click here</a> )
Use caching whenever possible. It’ll reduce the load on your server and help balance things.
尽可能使用缓存。 它将减少服务器上的负载并帮助保持平衡。
Try to avoid server side sessions, but if you need them, be sure to set them up so that either the data can be shared with the other servers, or the user uses only one server.
尝试避免服务器端会话,但是如果需要它们,请确保进行设置,以便可以与其他服务器共享数据,或者用户仅使用一台服务器。
One last note: a useful tool for synchronizing your Website between multiple servers is rsync, or, even better, cvs. If you make a change on the master server, simply commit your changes on that server, then run cvs update on the others. All customizations made on a slave server will be automatically kept intact by cvs.
最后一点:rsync,或者更好的是cvs,是在多台服务器之间同步网站的有用工具。 如果您在主服务器上进行更改,只需在该服务器上提交更改,然后在其他服务器上运行cvs update。 在从属服务器上进行的所有定制将由cvs自动保持完整。
“Okay” you say, “I already have my site …and I haven’t followed any of your suggestions! What should I do?” Don’t worry, there’s still a lot you can do to convert your site to run on multiple servers.
“好吧”,您说,“我已经有了我的网站……而且我没有遵循您的任何建议! 我该怎么办?” 不用担心,您仍然可以做很多工作来将站点转换为在多台服务器上运行。
First, let’s get the easy cases out of the way. If your site is completely made of static HTML files, then you’re set. All you need to do is copy the Website to two different servers and setup a round robin DNS. If your site is almost completely static but has a few dynamic pages, simply put all the static material on one server and the dynamic material on another.
首先,让我们摆脱一些简单的案例。 如果您的网站完全由静态HTML文件组成,那么您就定了。 您需要做的就是将网站复制到两台不同的服务器上,并设置轮询DNS。 如果您的站点几乎完全是静态的,但是有几个动态页面,则只需将所有静态资料放在一台服务器上,然后将动态资料放在另一台服务器上。
Now the hard cases: if you have a complicated user-input driven Website, some more work is necessary on your part. First, analyze your site. In particular, look at all the SQL code. Can you divide your site into distinct pieces — such as parts which could use slightly out of date data (or read-only), and parts that write to the database? If so, you can simply setup master and slaver servers. Put the pages that write on one server, and the pages that read on another. This way, you can balance the load and reduce database traffic.
现在是困难的情况:如果您有一个复杂的用户输入驱动的网站,那么您还需要做更多的工作。 首先,分析您的网站。 特别是,请查看所有SQL代码。 您是否可以将站点划分为不同的部分,例如可以使用稍微过时的数据(或只读)的部分以及可以写入数据库的部分? 如果是这样,您可以简单地设置主服务器和从属服务器。 将写入的页面放在一台服务器上,将读取的页面放在另一台服务器上。 这样,您可以平衡负载并减少数据库流量。
If none of the above suggestions works, look into setting up multiple distinct servers and send visitors to the server from which they signed up. In my opinion this is the easiest, though not necessarily the best way to go.
如果上述建议均无效,请考虑设置多个不同的服务器,并将访问者发送到他们注册的服务器。 我认为这是最简单的方法,但不一定是最好的方法。
If none of the above options is successful, running several Web servers and a database server is your best bet. This will allow your Website to run virtually unmodified. Just be sure to store sessions in the database, and not in files, to allow them to be accessed from any server. Be sure to talk to your ISP to get a direct connection between the servers (or to obtain your own rack in a co-location facility) to avoid racking up huge bandwidth charges.
如果以上选项均未成功,则最好运行多个Web服务器和一个数据库服务器。 这将使您的网站几乎可以不经修改地运行。 只需确保将会话存储在数据库中而不是文件中即可,以便可以从任何服务器访问它们。 请务必与您的ISP联系,以在服务器之间建立直接连接(或在同一位置的设备中获得您自己的机架),以避免造成巨大的带宽费用。
When your site suddenly starts growing like a beanstalk, it is both a joyous and worrisome event. If you have a big budget, no worries, but even with a minuscule budget you can keep your site running. If you start thinking about how to design your site to scale before problems start to crop up, you can prevent any downtime from occurring. In fact, there’s very little that needs to be done to prepare a site to scale — with a properly designed site, you can simply drop in your new servers and be up and running in no time. Good luck, and here’s to your site!
当您的站点突然开始像豆荚般增长时,这既是喜事,也是令人担忧的事件。 如果预算很大,不用担心,但是即使预算很小,您也可以保持网站正常运行。 如果您开始考虑在问题开始出现之前如何设计站点以进行扩展,则可以避免任何停机时间。 实际上,准备一个站点以进行扩展几乎不需要做任何事情-如果站点设计正确,您只需插入新服务器即可立即启动。 祝您好运,这是您的网站!
Recommended Reading
推荐读物
ArsDigital Systems Journal: Building a Scalable eBusiness Solution — This is a good overview of how to build a proper scalable site.
ArsDigital Systems Journal:构建可扩展的电子商务解决方案—这是如何构建适当的可扩展站点的良好概述。
ArsDigital Systems Journal: Building a Scalable eBusiness Solution — This is a good overview of how to build a proper scalable site.http://ccm.redhat.com/asj/building-scalable-ebusiness/
ArsDigital Systems Journal:构建可扩展的电子商务解决方案—这是如何构建适当的可扩展站点的良好概述。 http://ccm.redhat.com/asj/building-scalable-ebusiness/
CVS tutorial– You should most definitely use CVS whenever possible. It’s your friend!
CVS教程–您绝对应该尽可能使用CVS。 是你的朋友!
CVS tutorial– You should most definitely use CVS whenever possible. It’s your friend!https://www.sitepoint.com/article/831
CVS教程–您绝对应该尽可能使用CVS。 是你的朋友! https://www.sitepoint.com/article/831
rsync homepage
rsync主页
rsync homepagehttp://samba.anu.edu.au/rsync/
rsync主页http://samba.anu.edu.au/rsync/
Read more about the “Am I Hot or Not” story
阅读有关“我热还是不热”故事的更多信息
Read more about the “Am I Hot or Not” storyhttp://webtechniques.com/archives/2001/05/hong/
阅读有关“我热还是不热”故事的更多信息http://webtechniques.com/archives/2001/05/hong/
Free round robin DNS from mydomain.com
来自mydomain.com的免费循环DNS
Free round robin DNS from mydomain.comhttp://www.mydomain.com/help/mydomainplus/tut-robin
来自mydomain.com http://www.mydomain.com/help/mydomainplus/tut-robin的免费循环DNS
A great description of round robin Web servers
循环Web服务器的详细说明
A great description of round robin Web servershttp://www.onjava.com/pub/a/onjava/2001/09/26/load.html
循环Web服务器的详细说明http://www.onjava.com/pub/a/onjava/2001/09/26/load.html
mysql database replication. Automatically keep many slave databases the same as a master database.
mysql数据库复制。 自动使许多从数据库与主数据库相同。
mysql database replication. Automatically keep many slave databases the same as a master database.http://www.mysql.com/doc/en/Replication.html
mysql数据库复制。 自动使许多从数据库与主数据库相同。 http://www.mysql.com/doc/zh/Replication.html
翻译自: https://www.sitepoint.com/affordable-scalable-websites/
字扩展,位扩展,和字位扩展
相关资源:jdk-8u281-windows-x64.exe