Discuz! NT Load Balancing Solution

Source: Internet
Author: User
Tags database load balancing remote ftp server
Previous articles Article In discuz! Cross-Site cache data in NT and database load balancing. However, if you want to distribute the product to several machines and form a cluster to jointly support the entire business, there are still some problems (which will be introduced later ). The following describes how to use discuz! The NT Server Load balancer solution builds distributed applications.

Discuz! The front-end load balancing of NT can be nginx, LVS, haproxy, etc. Of course, the most simple configuration is based on nginx. Below are some of its introductions:

Nginx ("engine X") is a lightweight HTTP server written by Russians. It is not only a high-performance HTTP and reverse proxy server, but also an IMAP/POP3/SMTP proxy server. Nginx was developed by the rambler.ru site with the highest access volume in Russia by Igor Sysoev. It has been running on this site for more than two and a half years. Igor will Source code Issued in the form of a class BSD license.
In the Google online security blog, the nginx service or proxy count about 4% of all Internet virtual hosts. According to Netcraft statistics, nginx Service hosts have increased by four times in the past year. In just a few years, its ranking has jumped to 9th.
Nginx is designed for performance optimization. performance is the most important consideration, and efficiency is very important in implementation. It supports the kernel poll model and can withstand the high load test. The report shows that it supports up to 50,000 concurrent connections.
Nginx has high stability. When other HTTP servers encounter access peaks or maliciously initiate slow connections, the server may also consume physical memory and exchange frequently. In this case, the server can only be restarted if the response is lost. For example, once Apache has over 200 processes, the Web response speed is obviously very slow. Nginx adopts the phased Resource Allocation technology, making it very low in CPU and memory usage. Nginx officially said that it maintains 10,000 idle connections, which only occupies MB of memory. Therefore, DOS-like attacks are basically useless for nginx. In terms of stability, nginx Ratio
Lighthttpd is superior.
Nginx surpasses Apache's high performance and stability, making it more and more websites using nginx as web servers in China, including portal website channels such as Sina Blog, Sina podcast, and Netease news, video sharing websites such as room 6 and 56.com, shuimu Community Among other well-known forums, Douban, yupoo album, domestic SNS, thunder online and other emerging Web 2.0 websites.

The following figure briefly describes the role of nginx in our products:






The Asp.net in the figure is the corresponding IIS Site application we deployed. I believe that SLB users will find that there are many (nodes) in the large website architecture, IIS or other application servers ), nginx dynamically allocates requests to different nodes based on the corresponding weights (for nginx configuration in Windows and Linux, see this article)

As described in the following figure:




Put aside static file caching (squid is usually used and will be introduced later). The Web Server (IIS) in the figure has several clusters, which need to distribute the products to several machines, in this way, if files on a machine (node) change, a synchronization mechanism is required to ensure that files between different sites are consistent and up-to-date. In discuz! In NT products, files in some directories change frequently, for example:

1. In discuz! The NT background has a template generation mechanism, which will store the HTM template file (in discuz. WEB \ templates directory) Translate and generate the "aspx" file, and for translation conversion this part of content, see "href =" http://www.cnblogs.com/daizhj/admin/Discuz! NT % 20% E6 % A8 % a1 % E6 % 9d % BF % E6 % 9C % Ba % E5 % 88% B6 % E5 % 88% E6 % 9e % 90 "target = "_ blank "> this article.

2. foreground discuz. the configuration file under WEB \ config, which stores the corresponding configuration information of the entire Forum. The switch of all functions must be recorded, which is very important, after the Administrator modifies these configuration files on the relevant page in the background, the information needs to be synchronized to other distributed nodes immediately.

This is indeed a challenge, but fortunately, the corresponding software can help us implement this basic function, namely cwrsync, which was first a synchronization tool in Linux, and later had the Windows version, that is, cwrsync, which can be used to create a scheduled task with the help of the "Task Plan" in windows at the same time to implement the scheduled synchronization function. The minute-level synchronization mode can be set on Windows2003, as follows:


For how to set it, refer to this article.

In addition to file synchronization, there are also attachments. For example, a user sends a topic on a node and uploads relevant attachments, therefore, only the directories of the node have the corresponding attachments (such as slices), but not those of other nodes. Although the synchronization mechanism above can be used to achieve synchronization between multiple nodes, this will inevitably lead to a reduction in storage space and server performance. Fortunately, our product provides the remote attachment function, it allows you to upload attachments uploaded to a specified node to a remote FTP server in ftp mode, and change the path of the attachments in the database to the path of the remote attachment on FTP, for more information, see "href =" http://www.cnblogs.com/daizhj/admin/Discuz! NT % E4 % B8 % ad % E8 % BF % 9C % E7 % A8 % 8B % E9 % 99% 84% E4 % BB % B6 % E7 % 9A % 84% E5 % 8A % 9f % E8 % 83% BD % E5 % AE % 9e % E7 % 8e % B0 % 5 bftp % E5 % 8d % 8f % E8 % AE % 5d "target =" _ blank "> this article.

In addition to the above two problems, nginx is not enough to support Ajax, because load balancing should be performed on different nodes, therefore, scripts obtained from one node may be balanced by nginx to another node, resulting in cross-node Ajax security issues. This problem is very serious in our products. As we all know, after version 3.0, we changed all the original functions into Ajax methods, such as posting, replying, logging on, and managing front-end moderators. To solve this problem fundamentally, you can only hope for the nginx development team. However, after testing, we found that there is still a work und, that is, in the nginx configuration file
(Nginx. conf), you can set the following information:

 

Code

Location /{
......
Proxy_set_header host $ host;
Proxy_set_header X-real-IP $ remote_addr; # prevents Ajax security request Problems
Proxy_set_header remote-host $ remote_addr; # prevents Ajax security request Problems
...

 


In this way, we can fool IIS and make it think that the currently allocated Ajax request is from the local machine. At the same time, we add the corresponding port binding to implement the Ajax request, as shown below:

Code

......
Upstream 10.0.2.136 {
Server 10.0.2.136: 8086; # the same port is used to prevent Ajax security requests.
Server 10.0.2.small: 8086;
}

Server {
Listen 8086;
SERVER_NAME 10.0.2.136;
......

 


Note that the port must be the same (for example, port 8086 above ). In this way, the Ajax security call problem can be solved, if the IP address is afraid of conflict or insufficient
You can bind multiple IP addresses to a server to solve the problem that some sites must use port 80. For detailed settings, you can download this file.

 

Now, let's look at the overall load balancing solution. The first is the database read/write splitting method:



Then there is the distributed cache solution:




Of course, there are still some factors in the solution that have not been analyzed too much at present and compared squid file acceleration. For example, the following section describes the architecture of Server Load balancer that is often used on Linux.Red box on the right side:



In addition, CDN and so on will be added in the subsequent sections, so stay tuned.

 

Link: http://www.cnblogs.com/daizhj/archive/2010/06/24/1667422.html

Blog: http://daizhj.cnblogs.com/

Author: daizhj, Dai zhenjun

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.