Load Balancing for mysql using nginx

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.