安裝varnish :
yum -y install pcre* ncurses-devel
tar -zxvf varnish-2.1.2.tar.gz
cd varnish-2.1.2
./configure --prefix=/usr/local/varnish/ --enable-dependency-tracking --enable-debugging-symbols --enable-developer-warnings
make && make install
varnishd 工作流程:
varnishd處理http請求的過程,是通過Varnish的相關函數來定義。
當客戶端向varnishd發出請求後,varnish會接收請求,進入Receive狀態,根據vcl函數規則判斷該請求應該進入Pass模式(由後端主機應答後,返回給Client,不緩存,Client每次都是獲取最新內容)還是Pipe模式(將緩存的沒有改變的內容返回給Client),還是進入Lookup(本地查詢,在緩存中查找)。
當進入Lookup狀態後,會在緩存中查找內容,若找到,則進入Hit狀態,若沒找到則進入Miss狀態。
在Pass狀態下,會進入後端請求Fetch狀態。
在Fetch狀態下,從後端獲取數據,並將緩存進行本地存儲。
Deliver狀態下,將獲取的數據返回給Client,完成本次請求。
discard模塊,在緩存數據到期後或緩存空間不夠時,自動調用該模塊。
Receive—————— Pass \ Pipe
| |
| |
| Fetch —————
| ↑ |
| | |
Lookup ——— Miss |
| |
| ↓
Hit ———————————deliver