久久精品水蜜桃av综合天堂,久久精品丝袜高跟鞋,精品国产肉丝袜久久,国产一区二区三区色噜噜,黑人video粗暴亚裔
站長百科 | 數(shù)字化技能提升教程 數(shù)字化時(shí)代生存寶典
首頁
數(shù)字化百科
電子書
建站程序
開發(fā)
服務(wù)器
辦公軟件
開發(fā)教程
服務(wù)器教程
軟件使用教程
運(yùn)營教程
熱門電子書
WordPress教程
寶塔面板教程
CSS教程
Shopify教程
導(dǎo)航
程序頻道
推廣頻道
網(wǎng)賺頻道
人物頻道
網(wǎng)站程序
網(wǎng)頁制作
云計(jì)算
服務(wù)器
CMS
論壇
網(wǎng)店
虛擬主機(jī)
cPanel
網(wǎng)址導(dǎo)航
WIKI使用導(dǎo)航
WIKI首頁
最新資訊
網(wǎng)站程序
站長人物
頁面分類
使用幫助
編輯測試
創(chuàng)建條目
網(wǎng)站地圖
站長百科導(dǎo)航
站長百科
主機(jī)偵探
IDCtalk云說
跨境電商導(dǎo)航
WordPress啦
站長專題
網(wǎng)站推廣
網(wǎng)站程序
網(wǎng)站賺錢
虛擬主機(jī)
cPanel
網(wǎng)址導(dǎo)航專題
云計(jì)算
微博營銷
虛擬主機(jī)管理系統(tǒng)
開放平臺(tái)
WIKI程序與應(yīng)用
美國十大主機(jī)
編輯“
Varnish
”(章節(jié))
人物百科
|
營銷百科
|
網(wǎng)賺百科
|
站長工具
|
網(wǎng)站程序
|
域名主機(jī)
|
互聯(lián)網(wǎng)公司
|
分類索引
跳轉(zhuǎn)至:
導(dǎo)航
、?
搜索
警告:
您沒有登錄。如果您做出任意編輯,您的IP地址將會(huì)公開可見。如果您
登錄
或
創(chuàng)建
一個(gè)賬戶,您的編輯將歸屬于您的用戶名,且將享受其他好處。
反垃圾檢查。
不要
加入這個(gè)!
==Varnish教程== 安裝配置 在我看來,使用Varnish代替Squid的理由有三點(diǎn): 1、Varnish采用了“Visual Page Cache”技術(shù),在內(nèi)存的利用上,Varnish比Squid具有優(yōu)勢,它避免了Squid頻繁在內(nèi)存、磁盤中交換文件,性能要比Squid高。 2、Varnish的穩(wěn)定性還不錯(cuò),我管理的一臺(tái)圖片服務(wù)器運(yùn)行Varnish已經(jīng)有一個(gè)月,沒有發(fā)生過故障,而進(jìn)行相同工作的Squid服務(wù)器就倒過幾次。 3、通過Varnish管理端口,可以使用正則表達(dá)式快速、批量地清除部分緩存,這一點(diǎn)是Squid不能具備的 下面來安裝Varnish網(wǎng)站緩存加速器(Linux系統(tǒng)): 1、創(chuàng)建www用戶和組,以及Varnish緩存文件存放目錄(/var/vcache): /usr/sbin/groupadd www -g 48 /usr/sbin/useradd -u 48 -g www www mkdir -p /var/vcache chmod +w /var/vcache chown -R www:www /var/vcache 2、創(chuàng)建Varnish日志目錄(/var/logs/): mkdir -p /var/logs chmod +w /var/logs chown -R www:www /var/logs 3、編譯安裝varnish: wget http://blog.s135.com/soft/linux/varnish/varnish-1.1.2.tar.gz tar zxvf varnish-1.1.2.tar.gz cd varnish-1.1.2 ./configure --prefix=/usr/local/varnish make && make install 4、創(chuàng)建Varnish配置文件: vi /usr/local/varnish/vcl.conf 輸入以下內(nèi)容: 引用 backend myblogserver { set backend.host = "192.168.0.5"; set backend.port = "80"; } acl purge { "localhost"; "127.0.0.1"; "192.168.1.0"/24; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge) { error 405 "Not allowed."; } lookup; } if (req.http.host ~ "^blog.s135.com") { set req.backend = myblogserver; if (req.request != "GET" && req.request != "HEAD") { pipe; } else { lookup; } } else { error 404 "Zhang Yan Cache Server"; lookup; } } sub vcl_hit { if (req.request == "PURGE") { set obj.ttl = 0s; error 200 "Purged."; } } sub vcl_miss { if (req.request == "PURGE") { error 404 "Not in cache."; } } sub vcl_fetch { if (req.request == "GET" && req.url ~ "\.(txt|js)$") { set obj.ttl = 3600s; } else { set obj.ttl = 30d; } } 這里,我對這段配置文件解釋一下: (1)、Varnish通過反向代理請求后端IP為192.168.0.5,端口為80的web服務(wù)器; (2)、Varnish允許localhost、127.0.0.1、192.168.0.***三個(gè)來源IP通過PURGE方法清除緩存; (3)、Varnish對域名為blog.s135.com的請求進(jìn)行處理,非blog.s135.com域名的請求則返回“Zhang Yan Cache Server”; (4)、Varnish對HTTP協(xié)議中的GET、HEAD請求進(jìn)行緩存,對POST請求透過,讓其直接訪問后端Web服務(wù)器。之所以這樣配置,是因?yàn)镻OST請求一般是發(fā)送數(shù)據(jù)給服務(wù)器的,需要服務(wù)器接收、處理,所以不緩存; (5)、Varnish對以.txt和.js結(jié)尾的URL緩存時(shí)間設(shè)置1小時(shí),對其他的URL緩存時(shí)間設(shè)置為30天。 5、啟動(dòng)Varnish ulimit -SHn 51200 /usr/local/varnish/sbin/varnishd -n /var/vcache -f /usr/local/varnish/vcl.conf -a 0.0.0.0:80 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p client_http11=on 6、啟動(dòng)varnishncsa用來將Varnish訪問日志寫入日志文件: /usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/logs/varnish.log & 7、配置開機(jī)自動(dòng)啟動(dòng)Varnish vi /etc/rc.local 在末尾增加以下內(nèi)容: 引用 ulimit -SHn 51200 /usr/local/varnish/sbin/varnishd -n /var/vcache -f /usr/local/varnish/vcl.conf -a 0.0.0.0:80 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p client_http11=on /usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/logs/youvideo.log & 8、優(yōu)化Linux內(nèi)核參數(shù) vi /etc/sysctl.conf 在末尾增加以下內(nèi)容: 引用 net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 300 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.ip_local_port_range = 5000 65000 再看看如何管理Varnish: 1、查看Varnish服務(wù)器連接數(shù)與命中率: /usr/local/varnish/bin/varnishstat 2、通過Varnish管理端口進(jìn)行管理: 用help看看可以使用哪些Varnish命令: /usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 help 引用 Available commands: ping [timestamp] status start stop stats vcl.load vcl.inline vcl.use vcl.discard vcl.list vcl.show param.show [-l] [] param.set help [command] url.purge dump.pool 3、通過Varnish管理端口,使用正則表達(dá)式批量清除緩存: (1)、例:清除類似http://blog.s135.com/a/zhangyan.html的URL地址): /usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 url.purge /a/ (2)、例:清除類似http://blog.s135.com/tech的URL地址: /usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 url.purge w*$ (3)、例:清除所有緩存: /usr/local/varnish/bin/varnishadm -T 127.0.0.1:3500 url.purge *$ 4、一個(gè)清除Squid緩存的PHP函數(shù)(清除Varnish緩存同樣可以使用該函數(shù),無需作任何修改,十分方便): view plaincopy to clipboardprint? <?php function purge($ip, $url) { $errstr = ''; $errno = ''; $fp = fsockopen ($ip, 80, $errno, $errstr, 2); if (!$fp) { return false; } else { $out = "PURGE $url HTTP/1.1\r\n"; $out .= "Host:blog.s135.com\r\n"; $out .= "Connection: close\r\n\r\n"; fputs ($fp, $out); $out = fgets($fp , 4096); fclose ($fp); return true; } } purge("192.168.0.4", "/index.php"); ?> <?php function purge($ip, $url) { $errstr = ''; $errno = ''; $fp = fsockopen ($ip, 80, $errno, $errstr, 2); if (!$fp) { return false; } else { $out = "PURGE $url HTTP/1.1\r\n"; $out .= "Host:blog.s135.com\r\n"; $out .= "Connection: close\r\n\r\n"; fputs ($fp, $out); $out = fgets($fp , 4096); fclose ($fp); return true; } } purge("192.168.0.4", "/index.php"); ?> 附1:Varnish官方網(wǎng)站:http://www.varnish-cache.org/ 附2:2007年12月10日,我寫了一個(gè)每天0點(diǎn)運(yùn)行,按天切割Varnish日志,生成一個(gè)壓縮文件,同時(shí)刪除上個(gè)月舊日志的腳本(/var/logs/cutlog.sh): /var/logs/cutlog.sh文件內(nèi)容如下: 引用 #!/bin/sh # This file run at 00:00 date=$(date -d "yesterday" +"%Y-%m-%d") pkill -9 varnishncsa mv /var/logs/youvideo.log /var/logs/${date}.log /usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/logs/youvideo.log & mkdir -p /var/logs/youvideo/ gzip -c /var/logs/${date}.log > /var/logs/youvideo/${date}.log.gz rm -f /var/logs/${date}.log rm -f /var/logs/youvideo/$(date -d "-1 month" +"%Y-%m*").log.gz 設(shè)置在每天00:00定時(shí)執(zhí)行: /usr/bin/crontab -e 或者 vi /var/spool/cron/root 輸入以下內(nèi)容: 引用 0 0 * * * /bin/sh /var/logs/cutlog.sh
摘要:
請注意,您對站長百科的所有貢獻(xiàn)都可能被其他貢獻(xiàn)者編輯,修改或刪除。如果您不希望您的文字被任意修改和再散布,請不要提交。
您同時(shí)也要向我們保證您所提交的內(nèi)容是您自己所作,或得自一個(gè)不受版權(quán)保護(hù)或相似自由的來源(參閱
Wordpress-mediawiki:版權(quán)
的細(xì)節(jié))。
未經(jīng)許可,請勿提交受版權(quán)保護(hù)的作品!
取消
編輯幫助
(在新窗口中打開)
取自“
http://kktzf.com.cn/wiki/Varnish
”