Varnish Cache 3.0.0安装

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

Installation on RedHat

先按需要的模块

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

automake

autoconf

libtool

ncurses-devel

libxslt

groff

pcre-devel

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

#yuminstall-yautomakeautoconflibtoolncurses-devellibxsltgroffpcre-develpkgconfig

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

#backenddefault{

#.host="127.0.0.1";

#.port="8080";

#}

backenddefault{

.host="127.0.0.1";

.port="80";

}

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

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

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

下面我们启动varnish。

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

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

storage_malloc:maxsize1024MB.

CreatingnewSHMFILE

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

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

-T指定监听本地端口

-a0.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~]#pkillvarnished

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值