码迷,mamicode.com
首页 > 其他好文 > 详细

基于nginx和tengine的tcp反向代理,负载均衡 安装和配置

时间:2017-08-01 14:44:42      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:port   负载   arch   sock   add   status   ref   ast   backtrace   

先下载nginx_tcp_proxy_module模块。

 

    1. wget https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zip  
    2. 先看看自己原来nginx安装有哪些模块(编译参数):

      [root@111]# /tengine/sbin/nginx -V
      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

      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
    3. 复制一下,进入到nginx的源码目录
    4. patch -p1 < /path/to/nginx_tcp_proxy_module/tcp.patch   
    5. ./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   
    6. make   
    7.  cp  objs/nginx /usr/local/nginx/sbin/nginx
    8.   假定你有两个服务需要通过Nginx的Tcp(8888)端口进行负载均衡,参考如下配置:

       

      Shell代码  技术分享
      1. tcp {  
      2.   
      3.     upstream cluster {  
      4.         # simple round-robin  
      5.         server 192.168.0.1:80;  
      6.         server 192.168.0.2:80;  
      7.   
      8.         check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;  
      9.   
      10.         #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;  
      11.   
      12.         #check interval=3000 rise=2 fall=5 timeout=1000 type=http;  
      13.         #check_http_send “GET / HTTP/1.0\r\n\r\n”;  
      14.         #check_http_expect_alive http_2xx http_3xx;  
      15.     }  
      16.   
      17.     server {  
      18.         listen 8888; 
      19.         proxy_pass cluster;  
      20.     }  
      21. }  

      /usr/local/nginx/sbin/nginx -s reload

    9.  

       

      /tengine/conf/tcp_proxy/socket.xxx.com

    10. nginx.conf增加一条include tcp_proxy/*;

    11.  

    12. cat socket.xxx.com 
    13. tcp { 
    14.     upstream socket_xxx_com { 
    15.         server 1.1.1.1:8888;  
    16.  
    17.         check interval=3000 rise=2 fall=5 timeout=1000; #check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;
    18. }
    19.  
    20.     server { 
    21.         listen 8888; 
    22.         proxy_pass socket_xxx_com; 
    23.     } 
    24. }

基于nginx和tengine的tcp反向代理,负载均衡 安装和配置

标签:port   负载   arch   sock   add   status   ref   ast   backtrace   

原文地址:http://www.cnblogs.com/itfat/p/7267877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!