1. High-availability architecture has characteristics
1. Master-slave switching or duplex
1) Master-slave switching means that when the service of one of the machines is down, the caller can quickly switch to other available services and upgrade from the service to the main service. This switching speed should be controlled at the second level.
When the down service is restored, it will automatically become a slave service, and the roles of the master and slave services will be switched. The master-slave switchover must pay a price, so when the master service is restored, the existing master service will no longer be replaced.
2) Duplex mode (mutual backup and mutual assistance) Working principle: Two hosts run their own services at the same time and monitor each other. When any host goes down, the other host immediately takes over all its work. To ensure real-time work, the key data of the application service system is stored in the shared storage system
2. Cluster work
The request volume is relatively large, and a single service cannot meet the needs. At this time, multiple machines are required to provide the same service, and all requests are distributed to different machines.
The high-availability architecture should have rich load balancing strategies and easy-to-adjust load methods.
It can even be automated and intelligently adjusted. For example, due to the performance of the machine, the response time may be different. At this time, you can distribute a little less to the poorly performing machine to ensure the balance of the response time of each machine.
3. Easy to expand horizontally
When the number of users is increasing and the existing services cannot carry more users, the service needs to be extended. The extension method is best not to touch the original service, and it is transparent to the caller of the service.
2. High-availability solution
One master and multiple slaves, read and write separation
2. Nginx load balancing
Nginx is a reverse proxy server with a rich load balancing strategy, used between the client and the server, as an implementation of load balancing.
Reverse proxy: The proxy is the server, that is, the client accesses a so-called server. The server forwards the request to the real server in the background, and the real server responds, and the result is returned to the client through the proxy server. The server is hidden from the user, and the user does not know which server is the real one.
Using nginx to achieve high availability of services, nginx itself may become a single point, two solutions encountered,
One is that the company builds its own DNS to resolve requests to different NGINX,
One is to cooperate with keepalive to realize service survival detection. As shown below:
1) Multi-master and multi-slave mode, three-master and three-slave cluster mode, deployed on three servers
2) Pseudo-cluster mode, you can also create a pseudo-cluster and multiple nodes when there is only one server.
Same as redis
Same as redis