文章目录


varnish的介绍

百度百科的概念:

Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang (http://www.vg.no) 使用3台Varnish代替了原来的12台squid,性能居然比以前更好。

Varnish 的作者Poul-Henning Kamp是FreeBSD的内核开发者之一,他认为现在的计算机比起1975年已经复杂许多。在1975年时,储存媒介只有两种:内存与硬盘。但现在计算 机系统的内存除了主存外,还包括了cpu内的L1、L2,甚至有L3快取。硬盘上也有自己的快取装置,因此squid cache自行处理物件替换的架构不可能得知这些情况而做到最佳化,但操作系统可以得知这些情况,所以这部份的工作应该交给操作系统处理,这就是 Varnish cache设计架构。

varnish项目是2006年发布的第一个版本0.9.距今已经八年多了,此文档之前也提过varnish还不稳定,那是2007年时候编写的,经过varnish开发团队和网友们的辛苦耕耘,现在的varnish已经很健壮。很多门户网站已经部署了varnish,并且反应都很好,甚至反应比squid还稳定,且效率更高,资源占用更少。相信在反向代理,web加速方面,varnish已经有足够能力代替squid。

端口和官网

varnish 的监听端口是6081 squid 的端口号3128

varnish 官网:
varnish官方网站
varish官方文档-6.3

varnish 特点:

相比squid

1) 缓存方式:
varnish可以基于内存缓存,也可以在磁盘上缓存,可以利用虚拟内存缓存,支持设置0-60S精确缓存时间。
而squid 是将元数据缓存在内存,存储缓存在硬盘

2) ACL
varnish 配置是通过VAL语言来完成的,配置要先转换成C代码,所以使用 VCL所写的配置要先转换C语言代码,因此要依赖于GCC临时编译VCL配置,编译完成后才能运行

varnish缓存数据的原理

varnish的安装_varnish

varnish的安装

1. 安装依赖包

yum install autoconf.noarch automake.noarch jemalloc-devel.x86_64 libedit-devel.x86_64 libtool.x86_64 ncurses-devel.x86_64 pcre-devel.x86_64 pkgconfig.x86_64 python-docutils.noarch python-sphinx.noarch graphviz.x86_64 -y

2. 上传安装包并解压

[root@xinsz08-62 桌面]# lsnethogs-0.8.5-1.el7.x86_64.rpm
 varnish-6.2.3.tgz

使用file查看文件

[root@xinsz08-62 桌面]# file varnish-6.2.3.tgz varnish-6.2.3.tgz: gzip compressed data, from Unix, last modified: Fri Jan 31 20:18:02 2020, max compression

[root@xinsz08-62 ~]# file varnish-6.2.3.tgz varnish-6.2.3.tgz: gzip compressed data, from Unix, last modified: Fri Jan 31 20:18:02 2020, max compression[root@xinsz08-62 ~]# gunzip varnish-6.2.3.tgz [root@xinsz08-62 ~]# ls     
  varnish-6.2.3.tar

解压:

[root@xinsz08-62 ~]# tar xf varnish-6.2.3.tar [root@xinsz08-62 ~]# ls
  varnish-6.2.3      
  varnish-6.2.3.tar

3. 进入目录并编译安装

[root@xinsz08-62 ~]# cd varnish-6.2.3/[root@xinsz08-62 varnish-6.2.3]# lsaclocal.m4   configure     lib          README.Packaging
autogen.sh   configure.ac  LICENSE      README.rst
bin          doc           m4           varnishapi.pc.in
build-aux    etc           Makefile.am  varnishapi-uninstalled.pc.in
ChangeLog    include       Makefile.in  varnish-legacy.m4
config.h.in  INSTALL       man          varnish.m4[root@xinsz08-62 varnish-6.2.3]#

编译安装

[root@xinsz08-62 varnish-6.2.3]# ./autogen.sh [root@xinsz08-62 varnish-6.2.3]# ./configure && make && make install [root@xinsz08-62 varnish-6.2.3]# ldconfig

备注: ldconfig

ldconfig命令的用途:
在默认搜寻目录/lib和/usr/lib以及动态库配置文件/etc/ld.so.conf内所列的目录下,搜索出可共享的动态链接库(格式如lib*.so*),进而创建出动态装入程序(ld.so)所需的连接和缓存文件。

缓存文件默认为/etc/ld.so.cache,此文件保存已排好序的动态链接库名字列表,为了让动态链接库为系统所共享,需运行动态链接库的管理命令ldconfig,此执行程序存放在/sbin目录下。

简而言之: ldconfig是一个动态链接库管理命令,其目的为了让动态链接库为系统所共享,而当用户安装了一个新的动态链接库时,就需要手工运行这个命令。

4. 检查版本及启动

[root@xinsz08-62 varnish-6.2.3]# varnishd -Vvarnishd (varnish-6.2.3 revision 84d239c93e756ae255b6abb459c1052a36a409e9)Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2019 Varnish Software AS

启动[root@xinsz08-62 varnish-6.2.3]# varnishd -a :6081 -T localhost:6802 -b localhost:8080# [root@xinsz08-62 ~]# ps -ef |grep varnishroot      39814      1  0 11:35 ?        00:00:00 varnishd -a :6081 -T localhost:6082 -b localhost:8080
root      39825  39814  0 11:35 ?        00:00:00 varnishd -a :6081 -T localhost:6082 -b localhost:8080
root      43050  41288  0 12:05 pts/5    00:00:00 grep --color=auto varnish