Primary Site architecture diagram
Original content Welcome reprint, please specify Source: http://dushii.blog.163.com/blog/static/17305193200883044111183/
Website Basic Architecture Diagram:
For reference only, this architecture is for general applications with only a few servers, and portal applications are definitely more complex.
This diagram is drawn by Edraw experts, and this drawing software is highly recommended.
Principal Contradiction
For the high concurrency of the web site system, the first problem is the database bottleneck, Super Bull database system will soon become the bottleneck of access speed. Therefore, the first bottleneck to improve access speed is database access. Strategy is
First, Cache:
1, Squid front-end cache;
2, memcached back-end cache;
3, create an external index file, such as the use of Sphinx;
Second, database server array:
1, separate the database read and write operations, divided into the main from the server;
2, the master-slave server in accordance with a certain rules set into arrays;
In summary, minimize the number of requests to the database, and further use load balancing to minimize the pressure on a single server.
UseNginxreasons to do load balancing:
- Free use
- High connection concurrency, capable of supporting responses of up to 50,000 concurrent connections
- Nginx is written in C with low memory and CPU overhead
- Simple configuration file
- Supports URL rewriting and supports gzip compression for bandwidth savings
- Ultra-stable, almost uninterrupted operation, even if running for several months does not require a reboot
- There are many well-known sites in China using Nginx as a Web server or reverse proxy server
Detailed Introduction
After the client enters the domain name in the browser address bar, it will first access the most front-end proxy server, the static text file has this server to return directly, here set up a separate picture server, suitable for pictures of very many sites. A part of the specific URL proxy to the back-end squid server, squid server based on the URL to check whether there is cached content, or back to the front-end server, or then access the back-end of the PHP application, get content and cache for the next visit. Squid servers can be either one or an array organized by a certain set of rules.
PHP application can also be one or an array, the situation of a single server is relatively simple, array words need to consider the client session to answer the problem, the solution has two:
1, Array server sharing session reply, such as unified use memcached storage session;
2, the front-end server can determine which PHP server the client is processing, and always will this client proxy to this PHP application;
To compare these two approaches, the second approach may be more appropriate in the long term, from an extensibility perspective. For the first time access to the PHP application client, the recurrence rules for load-balancing, PHP to the client set a cookie way of the token, re-access is based on the cookie information linked to the previous PHP application.
For example: Set a cookie information host=n,n is a number, Nginx can obtain the client's cookie information string,
Upstream Backend {
Server backend1.example.com weight=5;
Server backend2.example.com:8080;
}
if ($http _cookie ~* "host= ([^;] +)(?:;|$)" ) {
Proxy_pass http://192.168.0.$1;
} else {
Proxy_pass Http://backend;
}
memcached data cache, Sphinx Station Search, MySQL master-slave array and other uses can find the relevant detailed information.
There will be additions later.
Primary Site architecture Diagram