---
title: "linux下varnish安装及配置使用"
author: "csstome"
date: "2011-08-17T11:02:00Z"
tags: []
slug: "linux-varnish"
draft: false
lastmod: "2011-10-28T08:47:41Z"
id: 1219511
url: "https://csstome.iteye.com/blog/1219511"
---

1、源码下载

下载地址：http://sourceforge.net/projects/varnish/files/ 可以找最新稳定版下载

官网：https://www.varnish-cache.org

2、解压安装

> 注：编译过程可能出现：No package 'libpcre' found 是pcre少了开发包
> 
> 解决办法：yum -y install pcre pcre-devel
> 
> To build Varnish on a Red Hat or Centos system you need the following packages installed:
> 
> - automake
> - autoconf
> - libtool
> - ncurses-devel
> - libxslt
> - groff
> - pcre-devel
> - pkgconfig
> 
> （centos下以上的包必须确保安装 其他系统参见：[https://www.varnish-cache.org/docs/2.1/installation/install.html](https://www.varnish-cache.org/docs/2.1/installation/install.html)）
> 
> yum -y install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig

3、配置参数说明

一般使用varnishd-aaddress:port-baddress:port其他使用默认即可启动(注意:vcl中指定后台服务器的话就不用使用-b参数了)

4、 配置文件说明

> 进入配置文件目录
> 
> cd/usr/local/varnish/etc/varnish
> 
> cp default.vcl varnish.vcl
> 
> vim varnish.vcl（拷贝以下参数）
> 
> 由于版本不同有关配置请参看官网：[https://www.varnish-cache.org/docs/2.1/tutorial/index.html#tutorial-index](https://www.varnish-cache.org/docs/2.1/tutorial/index.html#tutorial-index)（2.1版本配置地址）
> 
> 更多版本配置见：[https://www.varnish-cache.org/docs/](https://www.varnish-cache.org/docs/)
> 
> 参考文章：[http://kerry.blog.51cto.com/172631/402923](http://kerry.blog.51cto.com/172631/402923)
> 
> 启动命令：
> 
> /usr/local/varnish/sbin/varnishd -f /usr/local/varnish/etc/varnish/varnish.vcl -a 0.0.0:800 -s file,/var/vcache/varnish\_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500
> 
> Now you have Varnish running. Let us make sure that it works properly. Use your browser to go to[http://youwebsite:800/](http://192.168.2.2:8080/)- you should now see your web application running there.
> 
> 在你浏览器输入：[http://youwebsite:800/](http://192.168.2.2:8080/)即可
> 
> 本人手头有份pdf手册需要的可以联系我：429240967