web缓存值varnish使用

具体的介绍到官网 https://www.varnish-software.com/static/book 

一、简介

   Varnish is a reverse HTTP proxy, sometimes referred to as a HTTP accelerator or a web accelerator. It is designed for modern hardware, modern operating systems and modern work loads.

   Varnish is designed for hardware that you buy today, not the hardware you bought 15 years ago. Varnish is designed to run on 64-bit architectures and will scale almost proportional to the number of CPU cores you have available. Though CPU-power is rarely a problem.

   所以它是为64位操作系统打造的,服务于现在高性能的服务器。

  Varnish does not keep track of whether your cache is on disk or in memory. Instead, Varnish will request a large chump of memory and leave it to the operating system to figure out where that memory really is. The operating system can generally do a better job than a user-space program.

  它把一部分功能交给了处理能力更强的操作系统,由操作系统来维护缓存,这样系能更能提高

 

二、下载安装

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

      tar -xzvf 

      ./configure  报错 error: Package requirements (libpcre) were not met

      但是我rpm -qa | grep pcre是有东西的

      export PKG_CONFIG=/usr/local/lib/pkgconfig/还是不行,报错 The pkg-config script could not be found or is too old. 

      既然这么麻烦,我就不用PK_CONFIG了,

     export PCRE_LIBS=/usr/lib64/

     export PCRE_CFLAGS=/usr/lib64/

     ./configure --prefix=/usr/loca/varnish

    但是make的时候出错 :undefined reference to `pcre_free

     好吧,尼玛的我重新安装pkg-config

     wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.27.1.tar.gz

     tar -xzvf 

     ./configure --with-libiconv=gnu

     make && maike install

     然后 调用./pkg-config又报错: error while loading shared libraries: libiconv.so.2:

       libiconv.so.2在/usr/local/lib目录下

       vim /etc/ld.so.conf,增加一行/usr/local/lib

      ldconfig,再运行pkg-config就不报错了

     再次进入varnish的安装目录,这次configure make make install都不报错了。尼玛的坑爹货。早知道这么麻烦我直接 yum install varnish一句搞定

 

 

三、运行 

      vim /usr/local/varnish/etc/varnish/default.把

  backend default {
    .host = "127.0.0.1";
    .port = "8080";
  }前面的注释去掉

      chown www:www -R /usr/local/varnish/var/varnish/

  /usr/local/varnish/sbin/varnishd -P /var/run/varnish.pid -a :80 -f /usr/local/varnish/etc/varnish/default.vcl -T 127.0.0.1:6082 -t 120 -w 50,1000,120 -u www -g www -s file,/usr/local/varnish/var/varnish/varnish_storage.bin,1G

    

四、配合nginx

      1、把nginx监听的端口从80改成上面的8080

      2、重启nginx服务,然后开启varnish服务即可

  

五、重启varnish

     /usr/local/varnish/bin/varnishadm

     vcl.load reload01 /usr/local/varnish/etc/varnish/default.vcl

     vcl.use reload01

    这样就重启了。更改了default.vcl以后可以这样简单的重新加载配置

 

六、一些配置 

        未完待续

七、一些小注意事项

     1、如果http的请求中带有cookie,默认情况下varnish是不会缓存的。如果想对cookie做一些筛选,可以参照https://www.varnish-cache.org/trac/wiki/VCLExampleRemovingSomeCookies

 

 

posted on 2013-07-01 17:38  xiaorao  阅读(306)  评论(0编辑  收藏  举报

导航