Nginx TCP代理和负载均衡
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx TCP代理和负载均衡相关的知识,希望对你有一定的参考价值。
nginx1.9 版本以后增加 stream模块,可以对tcp,udp请求进行代理和负载均衡了
1、安装
yum -y install pcre-devel
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar zxf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/usr/local/nginx --with-stream --with-stream_ssl_module
make
make install
2、配置
#vim /usr/local/nginx/conf/nginx.conf
worker_processes auto;
error_log /usr/local/nginx/logs/error.log error;
events {
worker_connections 1024;
}
stream {
log_format main ‘$remote_addr [$time_local]‘
‘ $protocol $status $bytes_sent $bytes_received‘
‘$session_time $upstream_addr $upstream_bytes_sent‘
‘$upstream_bytes_received $upstream_connect_time‘;
upstream backend {
#hash $remote_addr consistent;
least_conn;
server 127.0.0.8:50179;
server 127.0.0.9:50179;
server 127.0.0.248:50179;
server 127.0.0.249:50179;
server 127.0.0.32:50179;
server 127.0.0.33:50179;
server 127.0.0.34:50179;
server 127.0.0.35:50179;
server 127.0.0.36:50179;
server 127.0.0.8:50179;
}
server {
listen 1080;
access_log /usr/local/nginx/logs/access.log main;
proxy_pass backend;
}
}
3、启动:
/usr/local/nginx/sbin/nginx
以上是关于Nginx TCP代理和负载均衡的主要内容,如果未能解决你的问题,请参考以下文章
通过Nginx TCP反向代理实现Apache Doris负载均衡