准备:
Proxy-Server:1.1.1.22(负载均衡服务器)
Nginx-Server23:1.1.1.23(web23)
Nginx-Server24:1.1.1.24(web24)
环境版本:
Linux Nginx-Proxy 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
①:安装配置完成Nginx,具体可以参考:http://note.t4x.org/system/centos-nginx-spdy/
WEB服务器预配置:
0 1 |
[root@Nginx-Server23 ~]# echo "1.1.1.23-server23" > /usr/local/nginx/html/index.html [root@Nging-Server24 ~]# echo "1.1.1.24-server24" > /usr/local/nginx/html/index.html |
负载均衡服务器配置:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[root@Nginx-Proxy conf]# egrep -v "#|^$" /usr/local/nginx/conf/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream note.t4x.org { server 1.1.1.23:80 weight=20; #weight值决定分配值,对此负载服务器大约访问两次1.1.1.23,访问一次1.1.1.24 server 1.1.1.24:80 weight=10; } server { listen 80; server_name note.t4x.org; location / { proxy_pass http://note.t4x.org; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } |
备注:server 1.1.1.23:80 weight=20; 等同于 server 1.1.1.23:80 weight=20 max_fails=1 fail_timeout=10s;
测试:
0 1 2 3 4 5 6 7 8 9 10 11 |
[root@Nginx-Proxy conf]# curl 1.1.1.22 1.1.1.23-server23 [root@Nginx-Proxy conf]# curl 1.1.1.22 1.1.1.23-server23 [root@Nginx-Proxy conf]# curl 1.1.1.22 1.1.1.24-server24 [root@Nginx-Proxy conf]# curl 1.1.1.22 1.1.1.23-server23 [root@Nginx-Proxy conf]# curl 1.1.1.22 1.1.1.23-server23 [root@Nginx-Proxy conf]# curl 1.1.1.22 1.1.1.24-server24 |
备注:当其中一台WebServer宕机以后,大概需要约10s后此台服务器将被剔除。
参考:http://nginx.org/en/docs/http/ngx_http_upstream_module.html
参考:http://tengine.taobao.org/document_cn/http_upstream_consistent_hash_cn.htmlSourceByrd's Weblog-https://note.t4x.org/system/configure-nginx-proxy-server-load-balance/ SourceByrd's Weblog-https://note.t4x.org/system/configure-nginx-proxy-server-load-balance/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!