nginx 在1.9.0 版本发布以前如果要想做到基于TCP的代理及负载均衡需要通过打名为nginx_tcp_proxy_module的第三方patch来实现,该模块的代码托管在github上 网址:https://github.com/yaoweibin/nginx_tcp_proxy_module/,而我们今年要来简单测试一下nginx 的ngx_stream_core_module,该模块有nginx 官方发布并支持tcp代理及负载均衡。

ngx_stream_core_module 这个模块在1.90版本后将被启用。但是并不会默认安装,需要在编译时通过指定 --with-stream 参数来激活这个模块。

其他改进包括:

  • Change: 删除过时的 aio 和 rtsig 事件处理方法
  • Feature: 可在 upstream 块中使用 "zone" 指令
  • Feature: 流模块,支持 TCP 代理和负载均衡
  • Feature: ngx_http_memcached_module 支持字节范围
  • Feature: Windows 版本支持使用共享内存,带随机化地址空间布局.
  • Feature: "error_log" 指令可在 mail 和 server 级别
  • Bugfix: the "proxy_protocol" parameter of the "listen" directive did not work if not specified in the first "listen" directive for a listen socket.

简单配置步骤如下(测试MYSQL负载):

wget http://nginx.org/download/nginx-1.9.3.tar.gz
tar zxvf nginx-1.9..tar.gz
cd nginx-1.9.yum -y install proc*
yum -y install openssl*
yum -y install pcre* ./configure --prefix=/usr/local/nginx-1.9.3_tcp \
--with-http_ssl_module --with-http_spdy_module \
--with-http_stub_status_module --with-pcre \
--with-stream cd /usr/local/nginx-1.9.3_tcp/conf/
mv nginx.conf{,.bak}
vim nginx.conf worker_processes auto;
events {
worker_connections ;
}
error_log /var/log/nginx_error.log info;
stream {
upstream mysqld {
hash $remote_addr consistent;
server 192.168.1.42: weight= max_fails= fail_timeout=10s;
server 192.168.1.43: weight= max_fails= fail_timeout=10s;
} server {
listen ;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass mysqld;
} }

另外还可以实现一个ssh 转发代理

upstream ssh {
hash $remote_addr consistent;
server 192.168.1.42: weight=;
} server {
listen ;
proxy_pass ssh;
}

参考:

http://zhangge.net/5037.html

http://nginx.org/en/docs/stream/ngx_stream_core_module.html

Nginx TCP代理的更多相关文章

  1. 早期nginx tcp代理(基于patch实现)

    nginx tcp代理功能由nginx_tcp_proxy_module模块提供,同时监测后端主机状态.该模块包括的模块有: ngx_tcp_module, ngx_tcp_core_module, ...

  2. nginx TCP 代理& windows傻瓜式安装

    一.下载nginx Windows http://nginx.org/en/download.html 二.解压到目录 三.进入目录并start nginx.exe即可启动 cd d:/java/ng ...

  3. nginx : TCP代理和负载均衡的stream模块

    一直以来,Nginx 并不支持tcp协议,所以后台的一些基于TCP的业务就只能通过其他高可用负载软件来完成了,比如Haproxy. 这算是一个nginx比较明显的缺憾.不过,在1.90发布后这个认知将 ...

  4. Nginx 配置TCP代理

    Nginx 1.9 版本以后增加了stream模块,可以对tcp,udp请求进行代理和负载均衡了,今天来体验一下首先编译安装过程configure的时候增加选项 --with-stream --wit ...

  5. nginx做TCP代理实现群集

    nginx做TCP代理实现群集 nginx从版本1.9开始,既能做HTTP代理,又能做TCP代理,这就非常完美了. 配置nginx.conf. 为了简单起见,笔者故意去掉了HTTP代理配置部分,只保留 ...

  6. Nginx 反向代理功能-实现Nginx tcp负载均衡

    Nginx 反向代理功能-实现Nginx tcp负载均衡 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.

  7. 二十.Nginx反向代理、Nginx的TCP/UDP调度器、Nginx常见问题处理

    proxy client web1 web2 1.nginx反向代理   使用Nginx实现Web反向代理功能,实现如下功能:   后端Web服务器两台(web1 192.168.2.100 web2 ...

  8. Nginx反向代理,Nginx的TCP/UDP调度器以及Nginx常见问题处理

    nginx反向代理: 方案 使用4台RHEL7虚拟机,其中一台作为Nginx代理服务器,该服务器需要配置两块网卡,IP地址分别为192.168.4.5和192.168.2.5,两台Web服务器IP地址 ...

  9. iperf测试流量转发(nginx反向代理tcp/udp)

    一.准备工作 服务器1:192.168.33.102     搭建nginx服务,作为反向代理的中转站 服务器2:192.168.33.103    nginx要反向代理的服务器 服务器3:192.1 ...

随机推荐

  1. Android Netroid解析之——断点续传下载及问题修正

    提到Netroid也许非常多人不知道这个框架,但我假设说Volley想必没有人不知道吧. Netroid是一个基于Volley实现的Android Http库.提供运行网络请求.缓存返回结果.批量图片 ...

  2. 九度 题目1154:Jungle Roads

    题目描写叙述: The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid mon ...

  3. 关于HashMap

    总是觉得对HashMap很熟悉,但最近连续被问到几个关于它的问题,才发现它其实并不简单.这里对关于它的一些问题做个总结,也希望能够大家一个参考. 都知道它是基于hash值,可以进行常量时间消化的存储结 ...

  4. Sparse Coding: Autoencoder Interpretation

    稀疏编码 在稀疏自编码算法中,我们试着学习得到一组权重参数 W(以及相应的截距 b),通过这些参数可以使我们得到稀疏特征向量 σ(Wx + b) ,这些特征向量对于重构输入样本非常有用. 稀疏编码可以 ...

  5. CString与 char *之间的转换

    http://www.cnblogs.com/watsonlong/archive/2011/04/15/2017086.html

  6. 3.第一个Node.js程序:Hello World!

    转自:http://www.runoob.com/nodejs/nodejs-tutorial.html 以下是我们的第一个Node.js程序: console.log("Hello Wor ...

  7. jQuery post 打开新窗口

    //使用POST方式打开界面 function doOpenPostWin(url, args, name, windowParam) { //创建表单对象 var _form = $("& ...

  8. vue移动端上拉加载更多

    LoadMore.vue <template> <div class="load-more-wrapper" @touchstart="touchSta ...

  9. Spring MVC modelandview

    一开始${Name} 不能显示 原来是: import org.springframework.web.portlet.ModelAndView; --错误的引入 import org.springf ...

  10. 【Codeforces Round #429 (Div. 2) A】Generous Kefa

    [Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [Numb ...