Nginx代理tcp端口实现负载均衡
1.修改配置文件
vi /etc/nginx/nginx.conf
添加如下配置:
stream
{
###XXX
upstream notify
{
hash $remote_addr consistent;
server 172.16.16.24:22268 weight=8 max_fails=3 fail_timeout=30s;
server 172.16.16.26:22268 weight=8 max_fails=3 fail_timeout=30s;
server 172.16.76.24:22268 weight=2 max_fails=3 fail_timeout=30s;
server 172.16.76.26:22268 weight=2 max_fails=3 fail_timeout=30s;
}
server
{
listen 22268;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass notify;
}
}
2.检查配置
nginx –t
3.重载配置
###检查配置无误之后,
nginx -s reload