Varnish Cache 3.0.0安装

来源:互联网 发布:城市电话区号查询软件 编辑:程序博客网 时间:2024/04/30 12:27

 https://www.varnish-cache.org/installation/redhat

 

 

Installation on RedHat

 

先按需要的模块

在安装软件包之前首先看看主机上的

automake

autoconf

libtool

ncurses-devel

libxslt

groff

pcre-devel

pkgconfig软件包是否已经安装 如果没有那么就要首先安装,我直接用yum安装的。

#yum install -y automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig 

 

Varnish is distributed in the EPEL (Extra Packages for Enterprise Linux) package repositories. However, while EPEL allows new versions to be distributed, it does not allow for backwards-incompatible changes. Therefore, new major versions will not hit EPEL and it is therefore not necessarily up to date. If you require a newer major version than what is available in EPEL, you should use the repository provided by varnish-cache.org.

To use the varnish-cache.org repository, run

rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm

and then run

yum install varnish

The --no-signature is only needed on initial installation, since the Varnish GPG key is not yet in the yum keyring

 

安装安成后我们的配置文件在 /usr/local/etc/varnish/default.vcl 下

好了接下来就开始我们的配置之旅吧。

首先将下面这些开始的注释去掉,并将8080改为80

# backend default {

#     .host = "127.0.0.1";

#     .port = "8080";

# }

 backend default {

     .host = "127.0.0.1";

     .port = "80";

 }

现在,这块配置定义了一个 varnish默认访问的后端服务器,当varnish 需要从后端

服务器获取内容的时候,它就会访问自己(127.0.0.1)的80端口。 Varnish 可以定义多个后端服务器而且您可以通过定义多个后端服务器达到负载均衡的目的。 

现在我们完成了基本的 varnish 配置,我们可以在 8080 端口上启动 varnish,并做一些基本的测试。 

下面我们启动varnish。

[root@db varnish]# varnishd -f /etc/varnish/default.vcl -s malloc,1G  -T 127.0.0.1:2000 -a 0.0.0.0:8080

会出现下面的内容说明启动成功了。

storage_malloc: max size 1024 MB.

Creating new SHMFILE

其中-f指定varnish的配置文件

–s 选项用来确定varnish使用的存储类型和存储容量

-T指定监听本地端口

-a 0.0.0.0:8080

用来制定 varnish 监听所有 IP 发给 8080 端口的 http 请求,如果在生产环境下,您应该让varnish监听80,这也是默认的。

我们在浏览器里输入http://192.168.0.131:8080/可以看到web程序正在运行。

为了让我们知道varnish到底做了什么,那么我们就来设置日志吧。

Varnish一个特别的优点就是它如何记录数据的。使用内存段代替普通的日志文件,当内存段使用完以后,又从头开始,覆盖最旧的记录。这样就可以非常快的记录数据,,并且不需要磁盘空间。 缺点就是您没有把数据写到磁盘上,可能会消失。在命令行执行

#varnishlog

将会得到一些信息。

如果varnish一切运行 OK,我们就可以把它调整到80端口上。 

首先关闭varnish

[root@db ~]# pkill varnished

然后停止您的 web服务器,修改web服务器配置,把 web服务器修改成监听8080

端口,然后修改varnish 的default.vcl和改变默认的后端服务器端口为8080. 先重启web服务器然后重新启动varnish

 

原创粉丝点击