openresty mysql 批量_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

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值