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: