Nginx is a seven-tier architecture that supports the HTTP protocol and does not natively support the TCP protocol. So can not agent MySQL and so on to achieve load balancing. But LVS this thing is not familiar, mainly is the company's load balancer is nginx so decided to study the Nginx this feature implementation, the following simple introduction to the implementation method:
1. Download module modules
: Https://nodeload.github.com/yaoweibin/nginx_tcp_proxy_module/zipball/master
$ Wget ' http://nginx.org/download/nginx-1.2.1.tar.gz '
$ TAR-XZVF nginx-1.2.1.tar.gz
$ CD NGINX-1.2.1/
$ PATCH-P1 </path/to/nginx_tcp_proxy_module/tcp.patch/path refers to the nginx_tcp_proxy_module path
$./configure--add-module=/usr/local/ngx_cache_purge-1.4--prefix=/usr/local/nginx--with-http_stub_status_module --add-module=/path/to/nginx_tcp_proxy_module//Compiling
$ make
$ make Install
2. Modify Nginx configuration file:
HTTP {
server {
Listen 80;
location/status {
Check_status;
}
}
}
TCP {
Upstream mysql{
Server 10.10.10.17:3306 weight=1;
Server 10.10.10.18:3306 weight=1;
#check interval=3000 rise=2 fall=5 timeout=1000;
}
server {
Listen 3306;
Proxy_pass MySQL;
}
}
This completes the configuration, launches Nginx for testing, and the following is the log printed in the test:
Nginx implementation of MySQL load balancing