首页 > 代码库 > 基于nginx和tengine的tcp反向代理,负载均衡 安装和配置
基于nginx和tengine的tcp反向代理,负载均衡 安装和配置
先下载nginx_tcp_proxy_module模块。
- wget https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zip
-
先看看自己原来nginx安装有哪些模块(编译参数):
[root@111]# /tengine/sbin/nginx -V
configure arguments: –prefix=/tengine –user=www –group=www –with-pcre=../pcre –with-http_ssl_module –with-http_stub_status_module –with-openssl=../openssl –with-zlib=../zlib-1.2.8 –with-http_upstream_check_module –with-http_concat_module –with-syslog –with-backtrace_module –with-http_realip_module –add-module=../ngx_cache_purge –add-module=../ngx_http_accounting_module
Tengine version: Tengine/2.1.1 (nginx/1.6.2)
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
TLS SNI support enabled - 复制一下,进入到nginx的源码目录
- patch -p1 < /path/to/nginx_tcp_proxy_module/tcp.patch
- ./configure –prefix=/usr/local/nginx –user=www –group=www –with-pcre=../pcre –with-http_ssl_module –with-http_stub_status_module –with-openssl=../openssl –with-zlib=../zlib-1.2.8 –with-http_upstream_check_module –with-http_concat_module –with-syslog –with-backtrace_module –with-http_realip_module –add-module=../ngx_cache_purge –add-module=../ngx_http_accounting_module –add-module=/path/to/nginx_tcp_proxy_module
- make
- cp objs/nginx /usr/local/nginx/sbin/nginx
- 假定你有两个服务需要通过Nginx的Tcp(8888)端口进行负载均衡,参考如下配置:
Shell代码
- tcp {
- upstream cluster {
- # simple round-robin
- server 192.168.0.1:80;
- server 192.168.0.2:80;
- check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;
- #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;
- #check interval=3000 rise=2 fall=5 timeout=1000 type=http;
- #check_http_send “GET / HTTP/1.0\r\n\r\n”;
- #check_http_expect_alive http_2xx http_3xx;
- }
- server {
- listen 8888;
- proxy_pass cluster;
- }
- }
/usr/local/nginx/sbin/nginx -s reload
-
/tengine/conf/tcp_proxy/socket.xxx.com
-
nginx.conf增加一条include tcp_proxy/*;
-
- cat socket.xxx.com
- tcp {
- upstream socket_xxx_com {
- server 1.1.1.1:8888;
- check interval=3000 rise=2 fall=5 timeout=1000; #check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;
- }
- server {
- listen 8888;
- proxy_pass socket_xxx_com;
- }
- }
基于nginx和tengine的tcp反向代理,负载均衡 安装和配置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。