Varnish安装教程

1、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。

2、端口和官网

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

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

3、varnish 特点:

相比squid

1) 缓存方式:

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

2) ACL

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

4、varnish的安装

1)安装依赖包
[root@ chenc01 ~]# yum -y 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
Loaded plugins: fastestmirror
varnishcache_varnish60lts/x86_64/signature                 |  819 B  00:00:00     
varnishcache_varnish60lts/x86_64/signature                 |  951 B  00:00:00 !!! 
varnishcache_varnish60lts-source/signature                 |  819 B  00:00:00     
varnishcache_varnish60lts-source/signature                 |  951 B  00:00:00 !!! 
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
2)上传安装包并解压
[root@ chenc01 ~]# rz -E
rz waiting to receive.
[root@ chenc01 ~]# ls
anaconda-ks.cfg  cpu.sar  nethogs-0.8.5-1.el7.x86_64.rpm  varnish-6.3.2.tgz
# 使用file查看文件
[root@ chenc01 ~]# file varnish-6.3.2.tgz 
varnish-6.3.2.tgz: gzip compressed data, from Unix, last modified: Fri Jan 31 20:27:18 2020, max compression
[root@ chenc01 ~]# gunzip varnish-6.3.2.tgz
# 解压
[root@ chenc01 ~]# tar xf varnish-6.3.2.tar 
[root@ chenc01 ~]# ls
anaconda-ks.cfg  cpu.sar                         varnish-6.3.2
a.sh             nethogs-0.8.5-1.el7.x86_64.rpm  varnish-6.3.2.tar
3)进入目录并编译安装
[root@ chenc01 ~]# cd varnish-6.3.2/
[root@ chenc01 varnish-6.3.2]# ls
aclocal.m4  config.h.in   include  Makefile.am       varnishapi.pc.in
autogen.sh  configure     INSTALL  Makefile.in       varnishapi-uninstalled.pc.in
bin         configure.ac  lib      man               varnish-legacy.m4
build-aux   doc           LICENSE  README.Packaging  varnish.m4
ChangeLog   etc           m4       README.rst
[root@ chenc01 varnish-6.3.2]# ./autogen.sh
[root@ chenc01 varnish-6.3.2]# ./configure && make && make install
[root@ chenc01 varnish-6.3.2]# ldconfig

备注: ldconfig

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

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

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

4)检查版本及启动
[root@ chenc01 varnish-6.3.2]# varnishd -V
varnishd (varnish-4.0.5 revision 07eff4c29)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2014 Varnish Software AS
[root@ chenc01 varnish-6.3.2]# varnishd -a :6081 -T localhost:6802 -b localhost:8080
[root@ chenc01 varnish-6.3.2]# ps -ef |grep varnish
root      43596      1  1 17:47 ?        00:00:00 varnishd -a :6081 -T localhost:6802 -b localhost:8080
nobody    43598  43596  3 17:47 ?        00:00:00 varnishd -a :6081 -T localhost:6802 -b localhost:8080
root      43816  19876  0 17:47 pts/0    00:00:00 grep --color=auto varnish
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值