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. But lvs this thing is not familiar with, mainly is the company's load balancing is nginx so decided to study the implementation of nginx this function, the following briefly introduces the implementation method: www.2cto.com 1. Download module: http://up.2cto.com/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 ;}} www.2cto.com} 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 www.2cto.com 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.107 0.0.0.0: 3306 18:22:35 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 18:22:37 10.10.10.10.18: 3306 1444 43832012/09/07 18:22:39 [3921] 10.10.10.10.107 0.0.0.0: 3306 18:22:38 10.10.10.10.17: 3306 1445 4383