Varnish Cache 3.0.0安装
?https://www.varnish-cache.org/installation/redhat
?
?
Installation on RedHat
?
先按需要的模塊
在安裝軟件包之前首先看看主機(jī)上的
automake
autoconf
libtool
ncurses-devel
libxslt
groff
pcre-devel
pkgconfig軟件包是否已經(jīng)安裝?如果沒(méi)有那么就要首先安裝,我直接用yum安裝的。
#yum?install?-y?automake?autoconf?libtool?ncurses-devel?libxslt?groff?pcre-devel?pkgconfig?
?
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?下
好了接下來(lái)就開(kāi)始我們的配置之旅吧。
首先將下面這些開(kāi)始的注釋去掉,并將8080改為80
#?backend?default?{
#?????.host?=?"127.0.0.1";
#?????.port?=?"8080";
#?}
?backend?default?{
?????.host?=?"127.0.0.1";
?????.port?=?"80";
?}
現(xiàn)在,這塊配置定義了一個(gè)?varnish默認(rèn)訪(fǎng)問(wèn)的后端服務(wù)器,當(dāng)varnish?需要從后端
服務(wù)器獲取內(nèi)容的時(shí)候,它就會(huì)訪(fǎng)問(wèn)自己(127.0.0.1)的80端口。?Varnish?可以定義多個(gè)后端服務(wù)器而且您可以通過(guò)定義多個(gè)后端服務(wù)器達(dá)到負(fù)載均衡的目的。?
現(xiàn)在我們完成了基本的?varnish?配置,我們可以在?8080?端口上啟動(dòng)?varnish,并做一些基本的測(cè)試。?
下面我們啟動(dòng)varnish。
[root@db?varnish]#?varnishd -f /etc/varnish/default.vcl -s malloc,1G? -T 127.0.0.1:2000 -a 0.0.0.0:8080
會(huì)出現(xiàn)下面的內(nèi)容說(shuō)明啟動(dòng)成功了。
storage_malloc:?max?size?1024?MB.
Creating?new?SHMFILE
其中-f指定varnish的配置文件
–s?選項(xiàng)用來(lái)確定varnish使用的存儲(chǔ)類(lèi)型和存儲(chǔ)容量
-T指定監(jiān)聽(tīng)本地端口
-a?0.0.0.0:8080
用來(lái)制定?varnish?監(jiān)聽(tīng)所有?IP?發(fā)給?8080?端口的?http?請(qǐng)求,如果在生產(chǎn)環(huán)境下,您應(yīng)該讓varnish監(jiān)聽(tīng)80,這也是默認(rèn)的。
我們?cè)跒g覽器里輸入http://192.168.0.131:8080/可以看到web程序正在運(yùn)行。
為了讓我們知道varnish到底做了什么,那么我們就來(lái)設(shè)置日志吧。
Varnish一個(gè)特別的優(yōu)點(diǎn)就是它如何記錄數(shù)據(jù)的。使用內(nèi)存段代替普通的日志文件,當(dāng)內(nèi)存段使用完以后,又從頭開(kāi)始,覆蓋最舊的記錄。這樣就可以非常快的記錄數(shù)據(jù),,并且不需要磁盤(pán)空間。 缺點(diǎn)就是您沒(méi)有把數(shù)據(jù)寫(xiě)到磁盤(pán)上,可能會(huì)消失。在命令行執(zhí)行
#varnishlog
將會(huì)得到一些信息。
如果varnish一切運(yùn)行?OK,我們就可以把它調(diào)整到80端口上。?
首先關(guān)閉varnish
[root@db?~]#?pkill?varnished
然后停止您的?web服務(wù)器,修改web服務(wù)器配置,把?web服務(wù)器修改成監(jiān)聽(tīng)8080
端口,然后修改varnish?的default.vcl和改變默認(rèn)的后端服務(wù)器端口為8080.?先重啟web服務(wù)器然后重新啟動(dòng)varnish
?
總結(jié)
以上是生活随笔為你收集整理的Varnish Cache 3.0.0安装的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 手机红米8多少钱
- 下一篇: 功夫派 传奇盗墓笔记万千稀有任务