OpenResty負載平衡MySQL

來源:互聯網
上載者:User

OpenResty負載平衡MySQL

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

 nginx_tcp_proxy_module模組需要單獨下載
https://github.com/yaoweibin/nginx_tcp_proxy_module

首先,解壓縮上述檔案
[nginx@localhost~]$ll
總用量 3668
 drwxrwxr-x 7 nginx nginx    4096 8月  18 23:39 nginx_tcp_proxy_module-master
 -rw-r--r-- 1 nginx nginx  213069 12月  8 15:05 nginx_tcp_proxy_module-master.zip
 drwxrwxr-x 5 nginx nginx    4096 12月  8 15:31 ngx_openresty-1.9.3.2
-rw-r--r-- 1 nginx nginx 3529639 11月 30 10:22 ngx_openresty-1.9.3.2.tar.gz

然後,打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 < /home/nginx/nginx_tcp_proxy_module-master/tcp.patch
 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).

最後
[nginx@localhost~]$cd ngx_openresty-1.9.3.2
 [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

修改設定檔
[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;
        } 
 }


注意:check要注釋,否則串連不上.原因未知.

參考:
https://github.com/yaoweibin/nginx_tcp_proxy_module

本文永久更新連結地址:

相關文章

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.