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

最新文章

  1. WinDbg 蓝屏dump分析教程
  2. PhoneGap--001 入门 安装
  3. wlan-mcs来自百度百科
  4. Maven中的dependencyManagement 意义
  5. 一个 Sql语句优化的问题- STATISTICS 统计信息
  6. Unity NGUI 2D场景添加按钮
  7. Node 写文件
  8. 【转】Java多线程操作局部变量与全局变量
  9. 无废话WCF入门教程二[WCF应用的通信过程]
  10. U3D游戏开发基础
  11. 第八章 关于SQL查询出错的一些问题
  12. template.helper()方法
  13. Java:多态乃幸福本源
  14. python2,python3同时安装时,python3可以安装并升级pip库,python2报错的解决办法
  15. Linux 安装 ffmpeg
  16. Iptables-redhat/centos
  17. git reset命令使用
  18. 179. Largest Number(INT, String)
  19. 对SingleTask和TaskAffinity的理解(转至 http://www.2cto.com/kf/201311/254450.html)
  20. 一次使用Python连接数据库生成二维码并安装为windows服务的工作任务

热门文章

  1. TI Code Composer Studio MSP430系列驱动源代码
  2. xgboost参数调优的几个地方
  3. Appium Android Bootstrap源代码分析之启动执行
  4. Spring 配置文件头部xmls解析
  5. C#开发 —— 基础知识
  6. POj 2159 Dividing
  7. 不固定高宽的 div 水平垂直居中
  8. tokumx的安装和使用
  9. [NOI.AC#41]最短路 线性基
  10. Android学习笔记进阶20之得到图片的缩略图