Nginx+Tomcat搭建高性能负载均衡集群( 三 )


  1.  
  2. upstream backend {
  3. server squid1:3128;
  4. server squid2:3128;
  5. hash $request_uri;
  6. hash_method crc32;
  7. }
  8. tips:
  9. upstream bakend{#定义负载均衡设备的Ip及设备状态
  10. ip_hash;
  11. server 127.0.0.1:9090 down;
  12. server 127.0.0.1:8080 weight=2;
  13. server 127.0.0.1:6060;
  14. server 127.0.0.1:7070 backup;
  15. }
 
在需要使用负载均衡的server中增加
proxy_pass http://bakend/;
每个设备的状态设置为:
1.down 表示单前的server暂时不参与负载
2.weight 默认为1.weight越大,负载的权重就越大 。
3.max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误
4.fail_timeout:max_fails次失败后,暂停的时间 。
5.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器 。所以这台机器压力会最轻 。
nginx支持同时设置多组的负载均衡,用来给不用的server来使用 。
client_body_in_file_only 设置为On 可以讲client post过来的数据记录到文件中用来做debug
client_body_temp_path 设置记录文件的目录 可以设置最多3层目录
location 对URL进行匹配 。可以

【Nginx+Tomcat搭建高性能负载均衡集群】


推荐阅读