zoukankan      html  css  js  c++  java
  • Varnish后端主机的健康状态检查

    author:JevonWei
    版权声明:原创作品


    配置后端主机的Health Check

    环境

    Varnish      192.168.198.139
    图片服务端    192.168.198.120
    程序服务端    192.168.198.128
    

    程序服务器

    [root@danran ~]# vim /var/www/html/.healthchk.html
    ok
    

    图片服务器

    [root@centos6 ~]# vim /data/web/image2/.healthchk.html
    oK
    [root@centos6 ~]# vim /data/web/images/.healthchk.html
    ok
    

    Vernish

    [root@danran ~]# vim /etc/varnish/default.vcl
        导入directors模块
        import directors;
    
        定义健康检查的机制,自定义为healthchk
        probe healthchk {
            .url = "/.healthchk.html";\检查的url为.healthchk.html
            .timeout = 2s;  \超时时间为2s
            .interval = 2s;\检查间隔时间
            .window = 8; \基于最近8次的检查判断
            .threshold = 5; \检查最近8次若有5次成功即为健康状态
        }
    
        定义一个app程序后端服务器
        backend appsrv1 {
            .host = "192.168.198.128";
            .port = "80";
            .probe = healthchk; \调用健康检查的机制
        }
    
        定义两个图片服务端
        backend imgsrv1 {
            .host = "192.168.198.120";
            .port = "80";
            .probe = healthchk; \调用健康检查的机制
        }
        backend imgsrv2 {
            .host = "192.168.198.120";
            .port = "8080";
            .probe = healthchk; \调用健康检查的机制
        }
    
        定义一个图片服务器组imgsrvs,并将imgsrv1和imgsrv2两个后端图片服务器添加进imgsrvs组中
        sub vcl_init {
            new imgsrvs =  directors.round_robin();  \指定调度算法为轮询
            imgsrvs.add_backend(imgsrv1);
            imgsrvs.add_backend(imgsrv2);
        }
        
        sub vcl_recv {
            if (req.url ~ "(?i).(jpg|jpeg|png|gif|svg|txt)$") {
                set req.backend_hint = imgsrvs.backend();
            } else {
                set req.backend_hint = appsrv1;
            }
        }
    [root@danran ~]# varnish_reload_vcl    \重新加载/etc/varnish/default.vcl参数文件
    

    Varnish查看后端主机的健康状态

    [root@danran ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 
    backend.list
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8 \Healthy为健康状态,检测了8次,8次成功
    imgsrv1(192.168.198.120,,80)   7      probe      Healthy 8/8
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 8/8
    

    图片服务端故障了一台服务器

    添加一条防火墙规则,禁止8080端口的连接,即等同于imgsrv2服务器的故障
    [root@centos6 ~]# iptables -A INPUT -p tcp --dport 8080 -j REJECT  
    

    Varnish查看后端主机的健康状态

    [root@danran ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 
    backend.list
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      probe      Healthy 8/8
    imgsrv2(192.168.198.120,,8080) 6      probe      Sick 0/8  \检查80次,0次成功,即imgsrv2服务端故障,从而imgsrv2不可用
    
    修复使imgsrv2上线后,imgsrv2恢复正常状态 
    [root@danran ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 
    backend.list
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      probe      Healthy 8/8
    imgsrv2(192.168.198.120,,8080) 6      probe      Sick 4/8  \Sick为失败状态
    backend.list
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      probe      Healthy 8/8
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 5/8 \当检查次数大于等于5次时,即表示该服务端可以正常使用
    

    Varnish手动使某后台服务端下线,即修改服务器健康状态为sick

    [root@Varnish ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082
    backend.set_health imgsrv1 sick
    200 \将imgsrv1服务器的状态手动修改为sick故障状态      
    
    backend.set_healtlist
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      sick       Healthy 8/8 \imgsrv1状态为sick故障状态
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 8/8
    

    将手动修改为sick状态的后台服务器端上线,即将状态修改为health

    [root@Varnish ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082
    
    backend.set_health imgsrv1 healthy
    200 \将imgsrv1服务器的状态手动修改为healthy健康状态,即不管物理后台服务器端是否正常,varnish检测结果都为正常
    
    backend.set_healtlist
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      sick       Healthy 8/8 \imgsrv1状态为sick故障状态
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 8/8
    
    backend.set_healtlist
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      healthy    Healthy 8/8
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 8/8
    

    imgsrv1后台服务器端故障,不能正常使用

    [root@imgsrv1 ~]# iptables -A INPUT -p tcp --dport 80 -j REJECT 
    

    Varnish检测后端服务器的健康状态

    [root@Varnish ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082
    
    backend.list
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      healthy    Sick 0/8
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 8/8
    

    将手动修改为sick状态的后台服务器端上线,即将状态修改为health

    [root@Varnish ~]# varnishadm -S /etc/varnish/secret -T
    
    backend.set_healtlist
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      sick       Healthy 8/8 \imgsrv1状态为sick故障状态
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 8/8
    
    backend.set_health imgsrv1 auto
    200        
    
    backend.set_healtlist
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      probe      Healthy 8/8
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 8/8  
    

    imgsrv1后台服务器端故障,不能正常使用

    [root@imgsrv1 ~]# iptables -A INPUT -p tcp --dport 80 -j REJECT 
    

    Varnish检测后端服务器的健康状态

    [root@Varnish ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082
    
    backend.set_healtlist
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      probe      Sick 0/8
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 8/8
    

    修复imgsrv1,使imgsrv1上线1

    [root@Varnish ~]# varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082
    
    backend.set_healtlist
    200        
    Backend name                   Refs   Admin      Probe
    appsrv1(192.168.198.128,,80)   7      probe      Healthy 8/8
    imgsrv1(192.168.198.120,,80)   7      probe      Healthy 8/8
    imgsrv2(192.168.198.120,,8080) 6      probe      Healthy 8/8
  • 相关阅读:
    tf-idf sklearn
    特征工程——特征预处理
    dict 字典
    特征预处理——特征表达
    特征工程之特征选择
    机器学习技巧学习
    dataframe去重 drop_duplicates
    dataframe 转为list
    XGboost
    StratifiedShuffleSplit()函数 实现对数据集的划分
  • 原文地址:https://www.cnblogs.com/JevonWei/p/7436276.html
Copyright © 2011-2022 走看看