Nginx implements mysql load balancing Nginx
BitsCN.com
Nginx is a layer-7 architecture that supports http and does not support tcp. Therefore, server load balancer cannot be implemented on behalf of mysql. However, lvs is not familiar with this. the company's server load balancer is nginx, so I decided to study the implementation of nginx. The following describes the implementation methods: 1. download module: http: // uploadfile/2012/0908/20120908102658486.zip
$ 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 indicates 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 // compile $ make $ make install 2. modify the 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 ;}} completes the configuration and starts nginx for testing, below is the log printed in the test: 18:22:32 [3921] 10.10.10.107 0.0.0.0: 3306 18:22:31 10.10.10.10.18: 3306 1446 43832012/09/07 18:22:32 [3921] 10.10.10.107 0.0.0.0: 3306 18:22:32 10.10.10.10.10.17: 3306 1446 43832012/09/07 18:22:33 [3921] 10.10.10.107 0.0.0.0: 3306 2012/09/07 18:22:32 10.10.10.18: 3306 1447 43832012/09/07 18:22:33 [3921] 10.10.10.107 0.0.0.0: 3306 18:22:33 10.10.10.10.10.17: 3306 1445 43832012/09/07 18:22:34 [3921] 10.10.10.107 0.0.0.0: 3306 2012/09/07 18:22:33 10.10.10.18: 3306 1445 43832012/09/07 18:22:34 [3921] 10.10.10.107 0.0.0.0: 3306 18:22:34 10.10.10.10.10.17: 3306 1446 4383 18:22:35 [3921] 10.10.10.107 0.0.0.0: 3306 18:22:34 10.10.10.10.18: 3306 1445 43832012/09/07 18:22:35 [3921] 10.10.10.107 0.0.0.0: 3306 18:22:35 10.10.10.10.10.17: 3306 1445 43832012/09/07 18:22:36 [3921] 10.10.10.107 0.0.0.0: 3306 2012/09/07 18:22:35 10.10.10.18: 3306 1445 43832012/09/07 18:22:37 [3921] 10.10.10.107 0.0.0.0: 3306 18:22:36 10.10.10.10.10.17: 3306 1446 43832012/09/07 18:22:37 [3921] 10.10.10.107 0.0.0.0: 3306 2012/09/07 18:22:37 10.10.10.18: 3306 1446 43832012/09/07 18:22:37 [3921] 10.10.10.107 0.0.0.0: 3306 18:22:37 10.10.10.10.10.17: 3306 1445 43832012/09/07 18:22:38 [3921] 10.10.10.107 0.0.0.0: 3306 2012/09/07 18:22:37 10.10.10.18: 3306 1444 43832012/09/07 18:22:39 [3921] 10.10.10.107 0.0.0.0: 3306 18:22:38 10.10.10.10.10.17: 3306 1445 4383bitsCN.com