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