首页 > 其他 > 详细

nginx基于tcp负载均衡

时间:2018-05-20 00:34:33      阅读:263      评论:0      收藏:0      [点我收藏+]

官方参考文档:http://nginx.org/en/docs/stream/ngx_stream_core_module.html
只有nginx1.9以上的版本才支持tcp负载均衡
配置必须出现在main段,不能配置在http,event和server标签段

(1)安装官方nginx

1.配置官方yum源

#vim /etc/yum.repos.d/nginx.repo 
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
yum makecache
yum repolist 

2.安装nginx

yum install nginx -y 
systemctl start nginx 
systemctl enable nginx 

(2)配置tcp负载均衡

#vim /etc/nginx/nginx.conf 
stream {
        upstream ssh_proxy {
                hash $remote_addr consistent;                               //一致性hash
                server 192.9.191.31:22 max_fails=2 fail_timeout=2s;         //健康状态检测
                server 192.9.191.32:22 max_fails=2 fail_timeout=2s;
                }
        server {
                listen 2222;
                proxy_connect_timeout 1s;                       //连接超时
                proxy_timeout 20s;                              //连接超时时间,如果不配置,永远不超时
                proxy_pass ssh_proxy;       
                }
}
#systemctl reload nginx 

nginx基于tcp负载均衡

原文:https://www.cnblogs.com/lovelinux199075/p/9062219.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!