OpenResty Load Balancing MySQL

Source: Internet
Author: User

OpenResty Load Balancing MySQL

OpenResty
Https://openresty.org/download/ngx_openresty-1.9.3.2.tar.gz

Nginx_tcp_proxy_module needs to be downloaded separately
Https://github.com/yaoweibin/nginx_tcp_proxy_module

First, extract the above files
[Nginx @ localhost ~] $ Ll
Total usage 3668
Drwxrwxr-x 7 nginx 4096 August 18 23:39 nginx_tcp_proxy_module-master
-Rw-r -- 1 nginx 213069 December 8 15:05 nginx_tcp_proxy_module-master.zip
Drwxrwxr-x 5 nginx 4096 December 8 15:31 ngx_openresty-1.9.3.2
-Rw-r -- 1 nginx 3529639 November 30 10:22 ngx_openresty-1.9.3.2.tar.gz

Then, patch
[Nginx @ localhost ~] $ Cd ngx_openresty-1.9.3.2/bundle/nginx-1.9.3
[Nginx @ localhost ~ /Ngx_openresty-1.9.3.2/bundle/nginx-1.9.3] $ patch-p1 Patching file src/core/ngx_log.c
Hunk #1 FAILED at 66.
1 out of 1 hunk FAILED -- saving rejects to file src/core/ngx_log.c.rej
Patching file src/core/ngx_log.h
Hunk #1 FAILED at 29.
Hunk #2 FAILED at 36.
2 out of 2 hunks FAILED -- saving rejects to file src/core/ngx_log.h.rej
Patching file src/event/ngx_event_connect.h
Hunk #1 succeeded at 33 (offset 1 line ).
Hunk #2 succeeded at 45 with fuzz 2 (offset 2 lines ).

Last
[Nginx @ localhost ~] $ Ngx_openresty-1.9.3.2 cd
[Nginx @ localhost ~ /Ngx_openresty-1.9.3.2] $./configure -- prefix =/home/nginx/OpenResty -- add-module =/home/nginx/nginx_tcp_proxy_module-master

Make-j 'cat/proc/cpuinfo | grep processor | wc-l'
Make install

Modify configuration file
[Nginx @ localhost ~] $ Cd OpenResty/nginx/conf
[Nginx @ localhost ~ /OpenResty/nginx/conf] $ vim nginx. conf

Tcp {
Upstream mysql {
Server 172.16.1.25: 3306 weight = 10;
Server 172.16.1.78: 3306 weight = 10 down;
# Check interval = 10000 rise = 2 fall = 5 timeout = 10000 type = mysql;
}

Server {
Listen 9999;
Proxy_pass mysql;
Timeout 1d;
Proxy_read_timeout 1d;
Proxy_send_timeout 1d;
Proxy_connect_timeout 3000;
So_keepalive on;
Tcp_nodelay on;
}
}


Note: check must be commented out; otherwise, the connection fails. The reason is unknown.

Refer:
Https://github.com/yaoweibin/nginx_tcp_proxy_module

This article permanently updates the link address:

Related Article

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.