Nginx implementation of MySQL load balancing

Source: Internet
Author: User

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

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.