码迷,mamicode.com
首页 > 其他好文 > 详细

nginx基于tcp负载均衡

时间:2018-05-20 00:47:15      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:etc   time   安装nginx   star   一致性hash   负载均衡   ack   str   hash   

官方参考文档: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负载均衡

标签:etc   time   安装nginx   star   一致性hash   负载均衡   ack   str   hash   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!