nginx基於tcp負載均衡


官方參考文檔: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 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM