一:varnish部署前准备:

1.1相关软件以及系统,web服务

系统要求:Centos 6(以上) (64位)

相关中间件:varnish-4.0.2

1.2相关系统依赖包安装检查准备

1.2.1 检查系统自带nginx是否安装

rpm -qa | grep varnish

如有安装,请使用以下命令卸载相关程序

yum remove varnish -y

1.2.2 安装编译nginx需要的依赖包

 yum install libtool ncurses-devel pcre-devel ibedit-devel pkgconfig python-docutils python-sphinx automake autoconf  -y

1.2.3 安装好相关web服务

 安装Apache,nginx,tomcat等都行,本文档的web安装在本地,使用的nginx web 端口为:8080

二:varnish 部署安装

2.1 下载varnish安装包

如有所示为varnish的官网:https://www.varnish-cache.org/releases,选择对应的varnish版本,本文档用的版本是varnish4.0.2

cd /usr/local/src
wget https://repo.varnish-cache.org/source/varnish-4.0.2.tar.gz

2.2 编译安装varnish

cd /usr/local/src
tar zxvf varnish-4.0.2.tar.gz
./configure CPPFLAGS="-I$PATH_TO_LIBEDIT/include" LDFLAGS="-L$PATH_TO_LIBEDIT/lib" \
--prefix=/usr/local/varnish4.0.2 
make && make install

2.3 配置varnish的启动脚本

echo "/usr/local/varnish4.0.2/sbin/varnishd -P /var/run/varnish.pid -f /usr/local/varnish4.0.2/etc/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:80" > /usr/local/varnish4.0.2/sbin/varnishd.sh

2.4 将varnish以开机服务的形式启动,并加入系统服务

2.4.1 编辑/etc/init.d/varnishd

vim /etc/init.d/varnishd

2.4.2 在/etc/init.d/varnishd添加以下内容

#!/bin/sh
#chkconfig:345 85 15 
#description: varnish cache server
# varnish
# Copyright (C) 2001-2014 varnish cache
#
SERVICE="varnish server"
DAEMON=/usr/local/varnish4.0.2/sbin/varnishd.sh
PIDFILE=/var/run/varnish.pid case $1 in
  'start')
    if [ -x ${DAEMON} ]
    then
      $DAEMON
      # Error checking here would be good...
      echo "${SERVICE} started success ! "
    else
      echo "Can't find file ${DAEMON}."
      echo "${SERVICE} NOT started."
    fi
  ;;
  'stop')
    if [ -s ${PIDFILE} ]
    then
      if kill `cat ${PIDFILE}` >/dev/null 2>&1
      then
        echo "${SERVICE} shutdown success !"
        rm -f ${PIDFILE}
      fi
    fi
  ;;
  'restart')
    $0 stop
    sleep 10
    $0 start
  ;;
  *)
    echo "Usage: $0 start|stop|restart"
    ;;
esac

2.4.3 编辑/usr/local/varnish4.0.2/etc/default.vcl添加以下内容

vcl 4.0;
backend webserver {
    .host = "127.0.0.1";
    .port = "8080";         //等同于后端web server
    .connect_timeout = 4s;  
    .first_byte_timeout = 5s;  
    .between_bytes_timeout = 20s;  
}

2.4.4启动varnishd 服务

service varnishd start

三:varnish验证测试

启动web服务

service nginx start

使用系统自带的命令curl -I localhost 如下所示:

HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Mon, 04 Jan 2016 07:50:09 GMT
Content-Type: text/html
Last-Modified: Mon, 31 Aug 2015 03:55:55 GMT
ETag: "55e3d04b-264"
X-Varnish: 112 131182
Age: 80
Via: 1.1 varnish-v4
Content-Length: 612
Connection: keep-alive

本文如上红色部分,当X-varnish 后面出现两组数据的时候,说明缓存成功,这时我们在关掉web服务,数据会从varnish缓存里读取,如下

关闭web服务

service nginx stop

重新curl -I localhost 如果命中缓存,则如下所示:

HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Mon, 04 Jan 2016 07:53:47 GMT
Content-Type: text/html
Last-Modified: Mon, 31 Aug 2015 03:55:55 GMT
ETag: "55e3d04b-264"
X-Varnish: 110 131182
Age: 8
Via: 1.1 varnish-v4
Content-Length: 612
Connection: keep-alive

当没有从缓存里命中时,会出现以下提示(没有命中缓存,则X-varnish后面数字为单组数字):

HTTP/1.1 503 Backend fetch failed
Date: Mon, 04 Jan 2016 07:55:59 GMT
Server: Varnish
Content-Type: text/html; charset=utf-8
Retry-After: 5
X-Varnish: 98457
Age: 0
Via: 1.1 varnish-v4
Content-Length: 282
Connection: keep-alive

至此整个varnish的部署安装基本就OK了

Linux平台部署varnish 高性能缓存服务器的更多相关文章

  1. Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关

    什么是Jexus Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关,以支持ASP.NET.ASP.NET CORE.PHP为特色,同时具备反向代理.入侵检测等重要功能.可以这样说,J ...

  2. 一、Linux平台部署ASP.NET、ASP.NET CORE、PHP

    一.什么是Jexus Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关服务器,以支持ASP.NET.ASP.NET CORE.PHP为特色,同时具备反向代理.入侵检测等重要功能.可以 ...

  3. 高性能缓存服务器Varnish

    一.Varnish概述 Varnish是一款高性能的.开源的反向代理服务器和缓存服务器,计算机系统的除了有内存外,还有CPU的L1.L2,甚至L3级别的缓存,Varnish的设计架构就是利用操作系统的 ...

  4. Linux下使用Magent+Memcached缓存服务器集群部署

    1.编译安装libevent  cd /root/soft_hhf/  wget http://cloud.github.com/downloads/libevent/libevent/libeven ...

  5. Linux平台下快速搭建FTP服务器

      FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为"文传协议".用于Internet上的控制文件的双向传输.同时,它也是一个应用程序 ...

  6. Linux平台部署.Net Core SDK

    根据微软MSDN,.Net Core无论是1.x还是2.0都只支持64位系统. 准备 以下是.NetCore支持的系统版本 以下 Linux 64 位(x86_64 或 amd64)发行版本/版本支持 ...

  7. varnish代理缓存服务器的安装与使用

    1. 下载解压 cd /usr/local/src/ wget https://codeload.github.com/varnishcache/varnish-cache/zip/master ch ...

  8. 1 Linux平台下快速搭建FTP服务器 win7下如何建立ftp服务器

    百度经验连接(亲测可用) http://jingyan.baidu.com/article/380abd0a77ae041d90192cf4.html win7下如何建立ftp服务器 http://j ...

  9. Varnish http缓存服务器

    http://blog.51cto.com/hexiaoshuai/1909183 https://jefferywang.gitbooks.io/varnish_4_1_doc_zh/content ...

随机推荐

  1. MVVM设计模式《网摘》

    MVVM模式能够帮你把你程序的业务与展现逻辑从用户界面干净地分离开.保持程序逻辑与界面分离能够帮助解决很多开发以及设计问题,能够使你的程序能更容易的测试,维护与升级.它也能很大程度的增加代码重用性,并 ...

  2. Codeforces Round #271 (Div. 2)

    A. Keyboard 题意:一个人打字,可能会左偏一位,可能会右偏一位,给出一串字符,求它本来的串 和紫书的破损的键盘一样 #include<iostream> #include< ...

  3. 对于随机变量的标准差standard deviation、样本标准差sample standard deviation、标准误差standard error的解释

    参考:http://blog.csdn.net/ysuncn/article/details/1749729

  4. noip2002提高组题解

    再次280滚粗.今天早上有点事情,所以做题的时候一直心不在焉,应该是三天以来状态最差的一次,所以这个分数也还算满意了.状态真的太重要了. 第一题:均分纸牌 贪心.(昨天看BYVoid的noip2001 ...

  5. BZOJ3540: [Usaco2014 Open]Fair Photography

    3540: [Usaco2014 Open]Fair Photography Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 72  Solved: 29 ...

  6. 【转】iOS开发UITableViewCell的选中时的颜色设置

    原文网址:http://mobile.51cto.com/hot-404900.htm 1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSe ...

  7. 使用rsync同步Linux数据到Windows

    windows: win7,cwrsyncserver 4.1.0 linux:ubuntu 14.04,rsync 3.1.0 networks:使用360wifi [Windows端] 是否使用管 ...

  8. innodb buffer pool

    add page to flush list buffer pool中的page,有三种状态: l  free:      当前page未被使用 l  clean:    当前page被使用,对应于数 ...

  9. java web 学习十四(JSP原理)

    一.什么是JSP? JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. JSP这门技术的最大的特点在于,写jsp就像在写h ...

  10. SQL注入中利用XP_cmdshell提权的用法(转)

    先来介绍一下子服务器的基本情况,windows 2000 adv server 中文版,据称 打过了sp3,asp+iis+mssql .首先扫描了一下子端口,呵呵,开始的一般步骤. 端口21开放: ...