沒有考慮特別複雜的場景,比如多層代理, 多個負載均衡設備。 未來也就做一個IP_HASH就搞定一切問題.
因此session是我們未來會始終堅持的技術方案。 自然也不會捨棄Session來追求負載均衡。
Nginx 話說還是很多公司採用的方案, 因此值得擁有,比如,隨便測試幾個大網站:
ab -n 10 -c 10 http://www.sina.com.cn/
得到的迴應:
[root@iZ237jmox9wZ webapps]# ab -n 10 -c 10 http://www.sina.com.cn/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.sina.com.cn (be patient).....done
Server Software: nginx
Server Hostname: www.sina.com.cn
Server Port: 80
Document Path: /
Document Length: 561996 bytes
Concurrency Level: 10
Time taken for tests: 0.715 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 5623576 bytes
HTML transferred: 5619960 bytes
Requests per second: 13.98 [#/sec] (mean)
Time per request: 715.431 [ms] (mean)
Time per request: 71.543 [ms] (mean, across all concurrent requests)
Transfer rate: 7676.17 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 25 27 2.3 25 31
Processing: 365 522 101.2 514 690
Waiting: 25 27 2.7 26 32
Total: 390 548 101.6 544 715
Percentage of the requests served within a certain time (ms)
50% 544
66% 587
75% 625
80% 664
90% 715
95% 715
98% 715
99% 715
100% 715 (longest request)
[root@iZ237jmox9wZ webapps]#
新浪都在用這個,你還等待什麼? 附帶APACHE的壓力測試工具,叫做AB,很不錯。
由於自己有阿里雲服務器, 任性一下, 不需要修改本地Host就可以驗證idea
worker_processes 1;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream www.down-line.com {
server 61.172.201.16:80; #這兩個玩意是隨便從網上找來的
server 54.192.98.136:80;
}
server {
listen 8084;
server_name localhost;
location / {
proxy_pass http://www.xxx-xxx.com;#自己的域名,匿了
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
這個Ngix部署阿里雲的服務器上, 作爲一個IT從業者, 每個月花上50¥,擁有一個服務器,是一個不太過分,且回報率很高的選擇。
至此,訪問網站+ 端口,不斷刷新,就可以看到負載均衡的現象了。
1. 進一步研究可以配置Server的權重.
2. 進一步研究,可以再s配置ip_hash, 也就是前文提到我未來需要學習的內容
參考文獻:
1. wiki網站 http://wiki.nginx.org/Install
2. 入門手冊, 這個非常棒! http://blog.martinfjordvald.com/2010/07/nginx-primer/
3. 參考資料2 的不完全翻譯: http://www.360doc.com/showWeb/0/0/438819674.aspx