Website Web business architecture evolved from small to large

Source: Internet
Author: User
Tags fpm

One day, I had a whim to create a site, based on the LNMP architecture, initially only I visited, and later because I was a bit more and more traffic, so eventually led to the following architecture evolution.

1. Single Machine

Single machine because it is only a small station, the number of visits a day does not have much UV (less than 100), so with a 1-core 1g machine enough. The CentOS system is installed on the machine, and the NGINX+PHP-FPM+MYSQL environment is built.

2, one set to change two

Access more and more large, daily UV breakthrough 5000, a single machine is not enough, this can increase the machine configuration Programming 4 core 8G, but considering also to change the machine, so directly add a DB server to run the MySQL service alone. The original server only needs to run NGINX+PHP-FPM, the new server runs MySQL service. Here, often encounter a problem, is how to compile and install the LAMP environment on multiple machines, compile on a single machine is no problem, PHP in the end, because it relies on MySQL, but we need to put MySQL to another machine, so the compilation will definitely error. To solve this problem, it is very simple, even if you do not need MySQL on the WEB, we have to install it, because when compiling PHP depends on it.

3. Increase memcached

Traffic continues to increase, UV on the W, DB Server and WEB server pressure is getting bigger, this time we need to add a cache to alleviate the pressure of the DB server. The same is two machines, but the Web machine configuration needs to upgrade, the original 1 core 1g is not enough, not only to add the CPU and memory, because on the web we need to run the memcached service, while PHP also needs to install the memcache extension.

4, add the Web and do MySQL master and slave

Access is expanded, UV to 5w, the database server because the first configuration is very high, so there is no pressure, but the WEB server load is a bit high, at the peak can feel the site access slowed. So, you have to consider adding a WEB server. In addition, the database is a single point, if the disk is damaged, may have unintended consequences, so we need to add a server from the DB as a backup of the data.

Here, two WEB servers we do not do load balancing, because in order to save resources, temporarily not to buy servers to do load balancing, we use the DNS polling method to send the user's request to two machines, but this architecture has a problem, once a WEB machine downtime, Half of the users will not have access to the business. There is also a problem, we also need to consider how to ensure that the data on the Web server consistent, such as the user may upload images to the Web server, if he uploaded to the WEB1, the WEB2 does not exist this image. So we need to make a shared storage so that WEB1 and WEB2 can be accessed at the same time, so here I put WEB1 a directory using NFS share out, let WEB2 go mount. There is also a problem is how to allocate memcached services, here, I am the memcaced service installed on two separate WEB, their own memcached service.

5. mysql read/write separation

Traffic continues to rise, UV has reached hundreds of thousands of. The site is always going to be a bit of a time during peak times. After the investigation, found that there are many slow queries on the MySQL server, after various tuning is still not too obvious effect, and finally decided to do read and write separation.

There are two ways to do read and write separation, the first can be implemented by the program, all the write operation point to the main MySQL, all the read operation point to from MySQL. For this scenario, the number of machines and the environment do not have to make any adjustments, the only thing to do is to change the program code. The second can be achieved with mysql-proxy, without modifying the code, saving development costs, but need to add a role. The architecture is like this.

6. Avoid a single point of load Balancing

Two WEB servers because there is a relatively old, so at the peak, after all, is not able to carry and hang off. As a result, half of the users are not accessing the site. After the accident, I had to modify the architecture to try to avoid a single point, so I set up the load balancer on the WEB front end and made it highly available.

Here I took Nginx to do a load balancer, and did not use LVS, because I think nginx easier to operate, better control. In order to save costs, I did not separate the mysql-proxy out as a standalone server, because in that case, it will have to consider a single point of the problem. In this architecture, there is actually a flaw, that is, the NFS server is also risky, more insurance is to engage in a separate servers to do NFS services.

7. Continue to expand

UV up to 100w, two WEB servers are obviously not enough, and the bottleneck is not on MySQL. So, just add the WEB, pick up the NFS server separately, and make an alternate NFS server.

8. Introduction of NoSQL

UV nearly 1000w, three WEB servers have not enough, increased to 5 units, and MySQL server pressure gradually become larger, for MySQL slow query, found that the pressure is mainly reflected in the individual SQL statements, the optimization has been optimized to the extreme, for these several queries, in fact, can use NoSQL. So, I find the PHP development of friends to help me modify the program, some of the large number of data access to Redis, thereby reducing the pressure on the MySQL server. Redis also did the master and slave to prevent a single point.

9. mysql Architecture Evolution

Http://www.cnblogs.com/liwei0526vip/p/6424605.html

Website Web business architecture evolved from small to large

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.