vanish可以让用户自己选择缓存数据是存于内存还是硬盘,存于内存一般基于二八法则即常访问的数据是磁盘存储的总数据五分之一,因此内存也应该是硬盘文件大概
五分之一。如果有多台vanish则,总内存满足即可,由前端代理服务器实现负载调度。最后由于缓存需要平凡的刷新,因此内存也不要过大,否则会浪费在内存调度算法上。
一般7500转每分的磁盘只能完成每秒80左右的随机io,为了增加磁盘io,则可以做raind0,固态硬盘擦写十万次,是指写满整个磁盘才算一次。
      缓存的保持有两种方式为文档请求机制和时间过期机制,时间过期是指包含在客户端头部包括exprire(http1.0中)指缓存过期的绝对时间,cache-control(http1.1)

指缓存过期的相对时间。cache-control中有很多控制机制,其中用的最多的max-age,相对时间一般为具体值如200是,当expire和cache-control同时存在时,以cache-conrol

为中。

Vanish缓存的保持有三种方法.file Malloc persistent等,前两种在服务器重启后缓

存数据会丢失。vanish系统配置文件为/etc/sysconfig/vanish

1.首先去官网下载

wget http://repo.varnish-cache.org/source/varnish-4.1.2.tar.gz

2.解压缩 安装所需其他库文件

tar zxf  varnish-4.1.2.tar.gz

编译安装过程可能会缺少以下包  libedit-devel  pcre-devel  ncurses-devel

yum -y install libedit-devel

yum -y install pcre-devel

yum -y install ncurses-devel

./configure --prefix=/usr/local/varnish  \

--bindir=/usr/local/varnish/bin   \

--sbindir=/usr/local/varnish/sbin

3.安装

make && make install

4.生成配置文件

cp etc/example.vcl /usr/local/varnish/default.vcl

5.启动

sbin/varnishd -f var/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:80

6.使用yum安装varnish-4.0.3 另外也可以yum安装,由于varnish存在于epel源中因此

yum install epel-release

yum clean all

yum list repo    更新并查看epel源是否已经存在
  rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-4.0.el7.rpm
  yum install varnish

yum 安装后varnish的配置文件为/etc/varnish/varnish.params  其中定义了varnish的默认acl为/etc/varnish/default.acl

systemctl start varnishd.service                                启动varnish

varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 登录varnish的管理接口 默认的 varnish的管理端口为6082

使用以下命令编译修改的vcl

再使用如下命令启用编译后的vcl

默认的如果没有default的backend 则会使用第一个定义的backend 否则会使用defaultbackend

在使用varnishstat查看varnish的命中情况时 报错

使用ps -ef | grep varnishd 查看_.vsm文件所在

使用 lsof -p 3031 查看

创建varnishstat 所需的文件

因此可以正常运行varnishstat了

注意:缓存一般由键-值组成,当设定cookie后 缓存就会由键-值-cookies 组成 只有相同用户请求相同资源才会命中,因此为了提高命中率。必须在vcl_recv中移除cookie,

且在vcl_fetch 中

acl 4.0 语法讲解

vcl 4.0;                         //4.0定义必须声明
import directors;           //4.0定义必须声明
backend web1 {
  .host = "172.16.1.2";
  .port = "80";
 
}

backend web2 {
   .host = "172.16.1.3";
   .port = "80";
   .probe = {
     .url = "/index.html";
     .window = 5;
     .threshold = 2;
     .interval = 3s;
   }
}
sub vcl_init {  //3.0中无,4.0中在使用director做负载均衡时必须使用此指令
#  new round_robin_director = directors.round_robin();
   new random_director = directors.random();
   random_director.add_backend(web1, 10);
   random_director.add_backend(web2, 5);

}
#directors websrvs random {      //3.0中定义方式
#   {
#     .backend = web1;
#     .weight = 2;
#   }
#   {
#     .backend = web2;
#     .weight = 1;
#   }
#
#}

acl purgers {
 "127.0.0.1";
 "172.16.0.0"/16;
}

sub vcl_recv {
 
# set req.backend = webservs;     //3.0中定义方式
   set req.backend_hint = random_director.backend();
# if (req.url ~ "\.(jpg|png|css)$") {
#   set req.backend = web1;
# } else {
#
#   set req.backend = web2;
#}
 
 if (req.method == "PURGE") {
   if (!client.ip ~ purgers){
#   error is used 3.0,now is replaced by synth
#      error 405 "method not allow";
       return(synth(405,"method not allowed"));
   }
   return (purge);
 }

if (req.url ~ "test.html") {  //若请求的为test.html则不查询缓存

return(pass);

}
  return(hash);  //3.0中return(lookup),4.0中返回return(hash)而在vcl_hash中才返回lookup

}

#sub vcl_hit {     //3.0中定义方式,4.0中 purge 只能使用在vcl_recv中,且只能return
#  if (req.method == "PURGE"){
#      return (purge);
#    error 200 "Purged OK";  //3.0中定义方式,4.0中使用synth输入错误信息
#     return(synth(200,"purged OK"));
#  }

#}

sub vcl_miss {
  if (req.method == "PURGE"){
#      purge;                               //4.0中purge只能用在vcl_recv中,且只能return(purge)
#      error  404 "not in cache";
       return(synth(404,"not in cache"));
   }

}

sub vcl_pass {
   if (req.method == "PURGE"){
#     error 502 "purged on a passed object";
      return(synth(502,"purged on a passed object"));
   }

}

#sub vcl_fetch {    vcl_feth is used in varnish 3.0, now 4.0 is replaced by vcl_backend_response
 sub vcl_backend_response {

if (bereq.url ~ "\.(jpg|gif|png)$") {
    set beresp.ttl = 3600s;
  }
  if (bereq.url ~ "\.(css|js|html)$") {
    set beresp.ttl = 1200s;
  }

}

sub vcl_deliver{   //vcl_deliver即最终返回给用户时修改response中的信息

if (obj.hits > 0) {

set resp.http.X-Cache = "hit from " + server.ip;
  } else {

set resp.http.X-Cache = "miss";
  }

}

HTTP缓存详细查看

http://www.cnblogs.com/_franky/archive/2011/11/23/2260109.html

编译安装 varnish-4.1.2和yum 安装 varnish-4.0.3的更多相关文章

  1. CentOS 6.9安装MySQL 5.6 (使用yum安装)

    CentOS 6.9安装MySQL 5.6 (使用yum安装) 移除CentOS默认的mysql-libs [root@test01 srv]# whereis mysqlmysql: /usr/li ...

  2. Centos 6.9 安装xtrabackup-2.4.8 通用包,yum安装,全量备份,增量备份

    xtrabackup-2.4.8的安装及使用 Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备 ...

  3. CentOS7下安装Mysql失败经历--CentOS7使用yum安装和卸载Mysql过程

    起因 自己租用的BandwagonVPS上安装了个CentOS7,然后开始安装各种软件,结果yum安装MySQL发现MySQL在yum源中的Mysql不对劲,于是自己百度搜索安装方法. 终于我搜到了这 ...

  4. centos7用rpm安装mysql5.7【初始用yum安装发现下载非常慢,就考虑本地用迅雷下载rpm方式安装】

    1.下载 4个rpm包 mysql-community-client-5.7.26-1.el7.x86_64.rpmmysql-community-common-5.7.26-1.el7.x86_64 ...

  5. 在CentOS上安装Java开发环境:使用yum安装jdk

    请参考百度经验:http://jingyan.baidu.com/article/4853e1e51d0c101909f72607.html 如果您阅读过此文章有所收获,请为我顶一个,如果文章中有错误 ...

  6. yum安装mariadb-galera同步

    节点             ip地址      hostname                            系统版本   程序版本 node1 10.4.90.90 mysql1 db1 ...

  7. yum安装tomcat

    http://www.cnblogs.com/liaolongjun/p/5638740.html http://www.awspack.com/os/linux/yum-install-tomcat ...

  8. CentOS下yum安装FFmpeg

    一.yum安装FFmpeg 1.    最偷懒的方式就是yum安装了,自动解决依赖.不过CentOS系统默认无FFmpeg源,企业版 Linux 附加软件包EPEL源也不包含,需要手动添加yum源配置 ...

  9. CentOS7 yum 安装git

    1.查看系统是否已经安装git git --version 2.CentOS7 yum 安装git yum install -y git 3.安装成功 4.卸载git yum remove git

  10. postgresql数据库的yum安装方法

    实验环境>>>>>>>>>>>>>>>>>>操作系统:CentOS release 6.3 ...

随机推荐

  1. 调戏OpenShift:一个免费能干的云平台

    一.前因后果 以前为了搞微信的公众号,在新浪sae那里申请了一个服务器,一开始还挺好的 ,有免费的云豆送,但是一直运行应用也要消费云豆,搞得云豆也所剩无几了.作为一名屌丝,日常吃土,就单纯想玩一玩微信 ...

  2. smarty使用

    smarty-牛刀小试 smarty 初识 官网 http://www.smarty.net/ Smarty is a template engine for PHP(PHP模板引擎) smarty使 ...

  3. 织梦DedeCMS

    DedeAMPZ服务器套件 http://dedeampz.dedecms.com/ DedeCMS  PHP开源网站管理系统  CMS系统 http://www.dedecms.com/produc ...

  4. 【codeforces 749E】 Inversions After Shuffle

    http://codeforces.com/problemset/problem/749/E (题目链接) 题意 给出一个1~n的排列,从中等概率的选取一个连续段,设其长度为l.对连续段重新进行等概率 ...

  5. bzoj3157国王奇遇记(秦九韶算法+矩乘)&&bzoj233AC达成

    bz第233题,用一种233333333的做法过掉了(为啥我YY出一个算法来就是全网最慢的啊...) 题意:求sigma{(i^m)*(m^i),1<=i<=n},n<=10^9,m ...

  6. Redis集群研究和实践(基于redis 3.0.5)

    前言 redis 是我们目前大规模使用的缓存中间件,由于它强大高效而又便捷的功能,得到了广泛的使用.现在的2.x的稳定版本是2.8.19,也是我们项目中普遍用到的版本. redis在年初发布了3.0. ...

  7. SHELL编写NGINX服务控制脚本

    使用源码包安装的Nginx没办法使用"service nginx start"或"/etc/init.d/nginx start"进行操作和控制,所以写了以下的 ...

  8. iOS - drawRect致内存增加

    GPU VS CPU iOS - 软件绘图 自定义"斑马线背景"View,重写drawRect绘制斑马线: ⚠️ 仅仅添加这一个View,内存就比正常增加了3-5M之间. 测试源代 ...

  9. AnjularJS系列3 —— 数据的双向绑定

    第三篇,双向的数据绑定 数据绑定是AnguarJS的特性之一,避免书写大量的初始代码从而节约开发时间 数据绑定指令提供了你的Model投射到view的方法.这些投射可以无缝的,毫不影响的应用到web应 ...

  10. String、StringBuffer与StringBuilder之间区别

    关于这三个类在字符串处理中的位置不言而喻,那么他们到底有什么优缺点,到底什么时候该用谁呢?下面我们从以下几点说明一下 1.三者在执行速度方面的比较:StringBuilder >  String ...