Nginx之Stream模块
1. stream模块介绍
nginx从1.9.0版本开始,新增加了一个stream模块,用来实现四层协议的转发,代理或者负载均衡。
2. stream模块安装
默认nginx不会安装stream模块,需要编译安装的时候,手工添加上这个模块,--with-stream.
第一安装,执行make,make install
如果在已有的nginx上安装stream模块,只需要make就可以了,不用make install
安装完成后,查看一下模块:
/usr/local/nginx/sbin/nginx -m
nginx: ngx_stream_module (static) nginx: ngx_stream_core_module (static) nginx: ngx_stream_log_module (static) nginx: ngx_stream_proxy_module (static) nginx: ngx_stream_upstream_module (static) nginx: ngx_stream_write_filter_module (static) nginx: ngx_stream_limit_conn_module (static) nginx: ngx_stream_access_module (static) nginx: ngx_stream_geo_module (static) nginx: ngx_stream_map_module (static) nginx: ngx_stream_split_clients_module (static) nginx: ngx_stream_return_module (static) nginx: ngx_stream_upstream_hash_module (static) nginx: ngx_stream_upstream_least_conn_module (static) nginx: ngx_stream_upstream_random_module (static) nginx: ngx_stream_upstream_zone_module (static)
3. stream模块使用
1. 配置文件中,stream与http在同一级别
stream {
upstream yangjianbo {
server 192.168.10.10:3306; #这里配置成要访问的地址
server 192.168.10.20:3306;
server 192.168.10.30:3306; #需要代理的端口,在这里我代理一一个kevin模块的接口8081
}
server {
listen 3306; #需要监听的端口
proxy_timeout 20s;
proxy_pass yangjianbo;
}
}
2. 负载均衡的调度算法
RR 轮询调度
WRR 权重调度
least-connected 对于每个请求,选择当前连接数最少的server来处理
upstream kevin {
least_conn;
server 192.168.10.10:8080; #这里配置成要访问的地址
server 192.168.10.20:8081;
server 192.168.10.30:8081; #需要代理的端口,在这里我代理一一个kevin模块的接口8081
}
一往无前虎山行,拨开云雾见光明

浙公网安备 33010602011771号