Home > Operation and Maintenance > Nginx > How to use nginx load balancing database

How to use nginx load balancing database

(*-*)浩
Release: 2019-11-01 11:46:19
Original
3646 people have browsed it

How to use nginx load balancing database

I won’t say much about the installation of nginx. I can search a lot on the Internet.

It should be noted that nginx can only be configured with http before version 1.9. protocol, does not accept the proxy of the TCP protocol, so the most common function of nginx is the load balancing configuration of the server. The general process is as follows: (Recommended learning: nginx tutorial)

with Example of TONCAT's web server:

How to use nginx load balancing database

The main role of Nginx is to distribute requests and reduce the pressure on a single Tomcat, thereby improving the server's ability to carry requests ( That is, it can handle high concurrency and the server will not be paralyzed)

Using Nginx to configure mysql load balancing is similar to the above, except that TOMCAT will no longer connect to the same database server, but to nginx, nginx distributes requests to different database servers.

It should be noted that in this case, in order to ensure that the data obtained by TOMCAT is correct, I need to ensure that the data between different databases are synchronized. I used the It is the synchronization function that comes with mysql. It is set to master-master synchronization (actually multiple master-slave synchronization)

How to use nginx load balancing database

Mysql load balancing configuration is also very simple:

Add the following code to the last line of the nginx.conf text:

stream {
    server {
       listen 3306;
       proxy_pass db;    
    }
    upstream db {
       server 192.168.18.130:3305;
       server 192.168.18.129:3305;
    }
 
}
Copy after login

It should be noted that the 3306 port is monitored in the above configuration, that is Port 3306 will be occupied by nginx, and the default port used by mysql is 3306. This will cause mysql to fail to start, so it is necessary to change the port number of mysql to another port (in this article, it is set to 3305, which will cause the mysql master to fail). (explained in the synchronization blog post), proxy_pass is the proxy address

The above is the detailed content of How to use nginx load balancing database. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template