zoukankan      html  css  js  c++  java
  • varnish实现缓存加速

    varnish实现缓存加速

    一、采用varnish为nginx实现缓存加速
    1、实验环境:
    (1)一台varnish缓存服务器,一台nginx服务器
    (2)关闭防火墙和selinux
    2.配置varnish
    (1)修改varnish配置文件:
    varnish实现缓存加速

    创建目录:mkdir -pv /data/varnish/cache
    修改属主:chown varnish.varnish /data/varnish/cache

    varnish实现缓存加速
    (2)测试:
    varnish实现缓存加速
    varnish实现缓存加速
    二、varnish实现动静分离
    (1)varnish配置:
    varnish实现缓存加速
    (2)测试:
    varnish实现缓存加速
    varnish实现缓存加速
    (3)附件内容设置多个组,并做负载:

    示例:
        import directors
    
        backend imgsrv1 {
            .host = "192.168.10.11";
            .port = "80";
        }
    
        backend imgsrv2 {
            .host = "192.168.10.12";
            .port = "80";
        }   
    
        backend appsrv1 {
            .host = "192.168.10.21";
            .port = "80";
        }
    
        backend appsrv2 {
            .host = "192.168.10.22";
            .port = "80";
        }
    
        sub vcl_init {
            new imgsrvs = directors.random();
            imgsrvs.add_backend(imgsrv1,10);
            imgsrvs.add_backend(imgsrv2,20);
    
            new staticsrvs = directors.round_robin();
            appsrvs.add_backend(appsrv1);
            appsrvs.add_backend(appsrv2);
    
            new appsrvs = directors.hash();
            appsrvs.add_backend(appsrv1,1);
            appsrvs.add_backend(appsrv2,1);     
        }
    
        sub vcl_recv {
            if (req.url ~ "(?i).(css|js)$" {
                set req.backend_hint = staticsrvs.backend();
            }       
            if (req.url ~ "(?i).(jpg|jpeg|png|gif)$" {
                set req.backend_hint = imgsrvs.backend();
            } else {        
                set req.backend_hint = appsrvs.backend(req.http.cookie);
            }
        }
    

    安全检测:

    .probe:定义健康状态检测方法;
                    .url:检测时要请求的URL,默认为”/"; 
                      .request:发出的具体请求;
                        .request = 
                            "GET /.healthtest.html HTTP/1.1"
                            "Host: www.ww.com"
                            "Connection: close"
                    .window:基于最近的多少次检查来判断其健康状态; 
                    .threshold:最近.window中定义的这么次检查中至有.threshhold定义的次数是成功的;成功阈值;
                    .interval:检测频度; 
                    .timeout:超时时长;
                    .expected_response:期望的响应码,默认为200;
    
                健康状态检测的配置方式:
                    probe PB_NAME  { }
                         backend NAME = {
                        .probe = PB_NAME;
                        ...
                         }
  • 相关阅读:
    asp.net mvc本地程序集和GAC的程序集冲突解决方法
    SolrCloud-如何在.NET程序中使用
    Application Initialization Module for IIS 7.5
    CentOS 6.5/6.6 安装mysql 5.7 最完整版教程
    NHibernate one-to-one
    “Invalid maximum heap size” when running Maven
    初涉RxAndroid结合Glide实现多图片载入操作
    【案例分析】Linux下怎样查看port占用情况
    js学习之--Bootstrap Modals(模态框)
    sdut2852 小鑫去爬山9dp入门)
  • 原文地址:https://www.cnblogs.com/aiaitie/p/12010084.html
Copyright © 2011-2022 走看看