本想用lua玩一把,但我发现我的要求很简单,直接用upstream的weight和backup就OK了。

于是,这样玩了一把。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

作个记录。

1)、down 表示当前的server暂时不参与负载
2)、weight 默认为1.weight越大,负载的权重就越大。
3)、backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    upstream my_server { 
              server 30.99.154.65:7999 weight=10; server 127.0.0.1:8888 backup; 
        }

    server {
        listen       8080;
        server_name  localhost;

        location / {
            proxy_pass http://my_server;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
    
    server {
        listen       8888;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄