Nginx------ngx_stream_core_module
*stream 模块用于一般的 TCP 代理和负载均衡。
安装stream模块
[root@hhht-hly-hly-srv02 conf.d]# nginx -V ####原安装模块
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/src/nginx-module-vts-0.1.18/ --with-http_stub_status_module --with-http_sub_module
安装stream模块实现tcp代理
cd nginx-1.14.2/
[root@hhht-hly-hly-srv02 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/src/nginx-module-vts-0.1.18/ --with-http_stub_status_module --with-http_sub_module --with-stream
[root@hhht-hly-hly-srv02 nginx-1.14.2]# make
Nginx -s stop
备份原有的nginx二进制文件
Mv /use/sbin/nginx{,.bak}
替换原nginx二进制文件
Cp objs/nginx /use/sbin/
启动nginx
[root@hhht-hly-hly-srv02 nginx-1.14.2]# nginx
查看版本模块信息:nginx -V
[root@hhht-hly-hly-srv02 conf.d]# nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/src/nginx-module-vts-0.1.18/ --with-http_stub_status_module --with-http_sub_module --with-stream
配置nginx配置文件。
1,nginx.conf
http{
.....
stream {
proxy_connect_timeout 3s;
include ./conf.d/*.stream.conf;
}
.....
}
[root@hhht-hly-hly-srv02 conf.d]# cat proxy-server.http.conf
server {
listen 8081;
server_name localhost;
location / {
proxy_pass http://10.2.19.177:8787;
}
}
server {
listen 8082;
server_name localhost;
location / {
proxy_pass http://10.2.19.177:3000;
}
}
[root@hhht-hly-hly-srv02 conf.d]# cat proxy-server.stream.conf
server {
listen 8083;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass 10.2.19.171:3306;
}
server {
listen 8084;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass 10.2.19.171:7001;
}
server {
listen 8085;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass 10.2.19.171:5672;
}