璐熻浇鍧囪
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了璐熻浇鍧囪相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/for' title='for'>for
cal 鑺傜偣 roc web href 瀹樼綉 received 鏈嶅姟鐩殑
- 瑙e喅鍗曚釜鑺傜偣鍘嬪姏杩囧ぇ锛岄€犳垚 Web 鏈嶅姟鍝嶅簲杩囨參锛屼弗閲嶇殑鎯呭喌涓嬪鑷存湇鍔$槴鐥紝鏃犳硶姝e父鎻愪緵鏈嶅姟銆?/li>
- 鎻愬崌 Web 鏈嶅姟鍣ㄥ搷搴旀€ц兘
nginx
http://nginx.org/en/docs/http/load_balancing.html
- 杞惊锛堥粯璁わ級
Nginx鏍规嵁璇锋眰娆℃暟锛屽皢姣忎釜璇锋眰鍧囧寑鍒嗛厤鍒版瘡鍙版湇鍔?/p>
- 鍣ㄦ渶灏戣繛鎺?/li>
灏嗚姹傚垎閰嶇粰杩炴帴鏁版渶灏戠殑鏈嶅姟鍣ㄣ€侼ginx浼氱粺璁″摢浜涙湇鍔″櫒鐨勮繛鎺ユ暟鏈€灏戙€?/p>
- IP Hash
缁戝畾澶勭悊璇锋眰鐨勬湇鍔″櫒銆傜涓€娆¤姹傛椂锛屾牴鎹瀹㈡埛绔殑IP绠楀嚭涓€涓狧ASH鍊硷紝灏嗚姹傚垎閰嶅埌闆嗙兢涓殑鏌愪竴鍙版湇鍔″櫒涓娿€傚悗闈㈣瀹㈡埛绔殑鎵€鏈夎姹傦紝閮藉皢閫氳繃HASH绠楁硶锛屾壘鍒颁箣鍓嶅鐞嗚繖鍙板鎴风璇锋眰鐨勬湇鍔″櫒锛岀劧鍚庡皢璇锋眰浜ょ粰瀹冩潵澶勭悊銆?/p>
浠ヨ疆璇㈣礋杞界瓥鐣ヤ负瀹炰緥
- 濡備笅涓恒€岃疆璇€嶉厤缃枃浠?Nginx.conf:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 65535;
}
stream {
log_format basic 鈥?remote_addr [$time_local] 鈥? 鈥?protocol $status $bytes_sent $bytes_received 鈥? 鈥?session_time鈥?
upstream test_cluster {
server 192.168.1.100:4010 weight=2 max_fails=3 fail_timeout=15;;
server 192.168.1.101:4011 weight=3;
server 192.168.1.102:4012 weight=1;
server 192.168.1.103:4013 weight=4;
}
server {
listen 50052;
proxy_connect_timeout 1s;
proxy_pass test_cluster;
access_log /var/log/nginx/test_cluster.log basic;
error_log /var/log/nginx/ptest_cluster-error.log debug;
}
}
- 閰嶇疆鏂囦欢涓弬鏁拌鏄庯細
- proxy_pass test_cluster锛氳〃绀哄皢鎵€鏈夎姹傝浆鍙戝埌 test_cluster 鏈嶅姟鍣ㄧ粍涓厤缃殑鏌愪竴鍙版湇鍔″櫒涓?/li>
- upstream妯″潡锛氶厤缃弽鍚戜唬鐞嗘湇鍔″櫒缁勶紝Nginx浼氭牴鎹厤缃紝灏嗚姹傚垎鍙戠粰缁勯噷鐨勬煇涓€鍙版湇鍔″櫒銆倀est_cluster 鏄湇鍔″櫒缁勭殑鍚嶇О銆?/li>
- upstream妯″潡涓嬬殑server鎸囦护锛氶厤缃鐞嗚姹傜殑鏈嶅姟鍣↖P鎴栧煙鍚嶏紝绔彛鍙€夛紝涓嶉厤缃粯璁や娇鐢?0绔彛銆傞€氳繃涓婇潰鐨勯厤缃紝Nginx榛樿灏嗚姹備緷娆″垎閰嶇粰100锛?01锛?02鏉ュ鐞嗭紝鍙互閫氳繃淇敼涓嬮潰杩欎簺鍙傛暟鏉ユ敼鍙橀粯璁ょ殑鍒嗛厤绛栫暐锛?
weight
榛樿涓?锛屽皢璇锋眰骞冲潎鍒嗛厤缁欐瘡鍙皊erver锛岄厤缃?weight 鍊硷紝鍗抽厤缃垎閰嶈姹傛潈閲?/p>
max_fails
榛樿涓?銆傛煇鍙癝erver鍏佽璇锋眰澶辫触鐨勬鏁帮紝瓒呰繃鏈€澶ф鏁板悗锛屽湪fail_timeout鏃堕棿鍐咃紝鏂扮殑璇锋眰灏嗕笉浼氬垎閰嶇粰杩欏彴鏈哄櫒銆傚鏋滆缃负0锛孨ginx浼氬皢杩欏彴Server缃负姘镐箙鏃犳晥鐘舵€侊紝鐒跺悗灏嗚姹傚彂缁欏畾涔変簡proxy_next_upstream, fastcgi_next_upstream, uwsgi_next_upstream, scgi_next_upstream, and memcached_next_upstream鎸囦护鏉ュ鐞嗚繖娆¢敊璇殑璇锋眰
fail_timeout
榛樿涓?0绉掋€傛煇鍙癝erver杈惧埌max_fails娆″け璐ヨ姹傚悗锛屽湪fail_timeout鏈熼棿鍐咃紝nginx浼氳涓鸿繖鍙癝erver鏆傛椂涓嶅彲 鐢紝涓嶄細灏嗚姹傚垎閰嶇粰瀹冦€傦紙192.168.0.100杩欏彴鏈哄櫒锛屽鏋滄湁3娆¤姹傚け璐ワ紝nginx鍦?5绉掑唴锛屼笉浼氬皢鏂扮殑璇锋眰鍒嗛厤缁欏畠銆傦級
鍙傝€冭祫鏂欙細
- http://nginx.org/en/docs/http/load_balancing.html
- https://blog.csdn.net/xyang81/article/details/51702900
以上是关于璐熻浇鍧囪的主要内容,如果未能解决你的问题,请参考以下文章