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