zoukankan      html  css  js  c++  java
  • nginx作为负载均衡服务器——测试

    i. 需求

    nginx作为负载均衡服务器,用户请求先到达nginx,再由nginx根据负载配置将请求转发至 tomcat服务器。

    nginx负载均衡服务器:192.168.101.3

    tomcat1服务器:192.168.101.5

    tomcat2服务器:192.168.101.6

    ii. 配置

    根据上边的需求在nginx.conf文件中配置负载均衡,如下:

    upstream tomcat_server_pool{

            server 192.168.101.5:8080 weight=10;

            server 192.168.101.6:8080 weight=10;

            }

        server {

            listen 80;

            server_name aaa.test.com;

            location / {

                     proxy_pass http://tomcat_server_pool;

                     index index.jsp index.html index.htm;

            }

        }

    节点说明:

    http节点里添加:

    #定义负载均衡设备的 Ip及设备状态

    upstream myServer {   

        server 127.0.0.1:9090 down;

        server 127.0.0.1:8080 weight=2;

        server 127.0.0.1:6060;

        server 127.0.0.1:7070 backup;

    }

    在需要使用负载的Server节点下添加

    proxy_pass http://myServer;

    upstream 每个设备的状态:

    down 表示单前的server暂时不参与负载

    weight  默认为1.weight越大,负载的权重就越大。

    max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误

    fail_timeout:max_fails 次失败后,暂停的时间。

    backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

    iii. 测试

    请求aaa.test.com,通过nginx负载均衡,将请求转发到tomcat服务器。

    通过观察tomcat的访问日志或tomcat访问页面即可知道当前请求由哪个tomcat服务器受理。

  • 相关阅读:
    我为何需要使用空接口?
    Castle 整合.NET Remoting
    MVC结构简介
    在asp.net页面上得到Castle容器的实例
    Castle.MVC框架介绍
    08.vue-router动态路由匹配
    07. vue-router嵌套路由
    06.路由重定向
    04 Vue Router路由管理器
    ES6新特性之 let 、const
  • 原文地址:https://www.cnblogs.com/justuntil/p/5538870.html
Copyright © 2011-2022 走看看