Nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信。
stream模块默认不安装的,需要手动添加参数:–with-stream,官方下载地址:download,根据自己系统版本选择nginx1.9或以上版本
./configure --add-module=../yaoweibin-nginx_tcp_proxy_module-121c026
1、Nginx安装:参考https://www.cnblogs.com/toov5/p/9902692.html 安装支持TCP协议的四层负载均衡Nginx
下载 wget http://nginx.org/download/nginx-1.9.10.tar.gz
解压 tar -xzvf nginx-1.9.0.tar.gz
补丁命令安装 yum -y install patch
打补丁 patch -p1 < ../yaoweibin-nginx_tcp_proxy_module-121c026/tcp.patch
编译Nginx
./configure --add-module=../yaoweibin-nginx_tcp_proxy_module-121c026
make && make install
报错:
[root@joe nginx-1.9.0]# make && make install
make -f objs/Makefile
make[1]: Entering directory `/home/nginx/nginx-1.9.0'
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../yaoweibin-nginx_tcp_proxy_module-121c026/modules -I ../yaoweibin-nginx_tcp_proxy_module-121c026/parsers -I ../yaoweibin-nginx_tcp_proxy_module-121c026 -I objs -I src/http -I src/http/modules -I src/mail -I src/stream \
-o objs/addon/yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.o \
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c: 在函数‘ngx_tcp_upstream_connect’中:
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:374: 错误:‘ngx_peer_connection_t’没有名为‘check_index’的成员
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:374: 错误:‘NGX_INVALID_CHECK_INDEX’未声明(在此函数内第一次使用)
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:374: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:374: 错误:所在的函数内也只报告一次。)
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:375: 错误:‘ngx_peer_connection_t’没有名为‘check_index’的成员
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c: 在函数‘ngx_tcp_upstream_next’中:
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:520: 错误:‘ngx_peer_connection_t’没有名为‘check_index’的成员
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:520: 错误:‘NGX_INVALID_CHECK_INDEX’未声明(在此函数内第一次使用)
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:521: 错误:‘ngx_peer_connection_t’没有名为‘check_index’的成员
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:522: 错误:‘ngx_peer_connection_t’没有名为‘check_index’的成员
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c: 在函数‘ngx_tcp_upstream_finalize_session’中:
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:576: 错误:‘ngx_peer_connection_t’没有名为‘check_index’的成员
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:576: 错误:‘NGX_INVALID_CHECK_INDEX’未声明(在此函数内第一次使用)
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:577: 错误:‘ngx_peer_connection_t’没有名为‘check_index’的成员
../yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.c:578: 错误:‘ngx_peer_connection_t’没有名为‘check_index’的成员
make[1]: *** [objs/addon/yaoweibin-nginx_tcp_proxy_module-121c026/ngx_tcp_upstream.o] 错误 1
make[1]: Leaving directory `/home/nginx/nginx-1.9.0'
make: *** [build] 错误 2
原因:不是最新补丁
解决:
- wget https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zip
2.patch -p1 </home/nginx/patch/nginx_tcp_proxy_module-master/tcp.patch (绝对目录)
3. ./configure --add-module=/home/nginx/patch/nginx_tcp_proxy_module (nginx目录里面操作)
解决完毕:
继续 ./configure --add-module=../yaoweibin-nginx_tcp_proxy_module-121c026
然后 make && make install