標籤:
零.前言
1.官網 http://trafficserver.apache.org/
2.國內社區 https://blog.zymlinux.net
3.簡潔明了的配置:http://blog.csdn.net/tiantiandjava/article/details/50327855一.ats安裝
1.安裝依賴包
#yum install pkgconfig libtool gcc make openssl tcl expat pcre pcre-devel libcap flex hwloc lua curses curl tcl-devel
2.下載安裝包
下載trafficserver-5.3.2
#wget http://apache.fayea.com/trafficserver/trafficserver-5.3.2.tar.bz2
3.安裝ats
#tar xvf trafficserver-5.3.2.tar.bz2#cd trafficserver-5.3.2#./configure --prefix=/usr/local/ats#make && make install
二.配置
1.ats的設定檔都在安裝目錄下的etc/trafficserver,此處為/usr/local/ats/etc/trafficserver2.重要設定檔:
(1).records.config 主要設定檔,配置ats的各項參數
安裝完後該項保持預設配置(2).remap.config 配置訪問網域名稱和源
如,在該檔案最後增加
map http://domain.com http://113.107.101.126:8111/
前者為綁定網域名稱,後者為源(3).storage.config 配置磁碟緩衝
在其最後增加
/ats_cache 20G
該配置是將磁碟緩衝緩衝在/ats_cache目錄下,大小為20G(4).cache.config 緩衝配置
該檔案決定了ats對緩衝的配置
如
url_regex=192.168.2.105:8112/news.php\?id=.* ttl-in-cache=2h cache-responses-to-cookies=4
cache-responses-to-cookies取值介紹
0 不緩衝任何帶cookie的原始伺服器返回結果
1 緩衝任何結果
2 只緩衝圖片類型的結果
3 緩衝除了text類型的所有結果
4 緩衝所有的非text類型的返回結果,以及不帶 Set-Cookie 頭或帶 Cache-Control: public的text類型的原始伺服器返回結果以上url正則表示緩衝源網址為192.168.2.105:8112/news.php?id=任意結果的相應資料,緩衝兩小時,前提是該網址不帶有Set-Cookie(5).logs_xml.config 配置日誌 三.常用配置1.配置http ui(1).在recoreds.config最後增加
CONFIG proxy.config.http_ui_enabled INT 3CONFIG proxy.config.http.enable_http_info INT 1
(2).在remap.config中增加
map http://localhost/cache-internal/ http://{cache-internal}map http://localhost/cache/ http://{cache} @action=allow @src_ip=127.0.0.1map http://localhost/stat/ http://{stat} @action=allow @src_ip=127.0.0.1map http://localhost/test/ http://{test} @action=allow @src_ip=127.0.0.1map http://localhost/hostdb/ http://{hostdb} @action=allow @src_ip=127.0.0.1map http://localhost/net/ http://{net} @action=allow @src_ip=127.0.0.1map http://localhost/http/ http://{http} @action=allow @src_ip=127.0.0.1
(3).通過以上配置,即可通過http協議來訪問http ui2.配置日誌
(1).ats預設的日誌是squid格式並不符合要求
(2).配置自訂日誌
a.在logs_xml.config中增加
<LogFormat><Name = "access"/><Format = "%<chi> %<cqtq> %<ttms> %<{X-Forwarded-For}cqh> %<crc>/%<pssc> %<pscl> %<cqhm> %<cquuc> %<cqhv> %<phr>/%<pqsi> %<psct> \"%<{Referer}cqh>\" \"%<{User-Agent}cqh>\" %<shn> %<sscl>"/></LogFormat><LogObject><Format = "access"/><Filename = "access"/></LogObject>
*format每項代表的意思,可以通過 https://docs.trafficserver.apache.org/en/5.3.x/admin/working-log-files.en.html 來查看b.修改或增加records.config中的如下配置
CONFIG proxy.config.log.squid_log_enabled INT 0CONFIG proxy.config.log.custom_logs_enabled INT 1
c.重載配置,後面會介紹
3.配置via標示,來快速確認檔案快取狀態
a.
CONFIG proxy.config.http.insert_response_via_str INT 2
b.然後查看頭部,可以看到
Via:http/1.1 localhost.localdomain (ApacheTrafficServer/5.3.2 [cRs f ])c.查看[cRs f ],可以通過網址
http://trafficserver.apache.org/tools/via#cSsSfD
來查看
也可以通過命令來解釋,後面會介紹
四.常用命令1.命令通常在安裝目錄下的bin目錄下,本文為/usr/local/ats/bin/
2./usr/local/ats/bin/trafficserver start #啟動
/usr/local/ats/bin/trafficserver stop #停止
/usr/local/ats/bin/trafficserver restart #停止3.重載配置
/usr/local/ats/bin/traffic_ctl config reload4.查看squid日誌
/usr/local/ats/bin/traffic_logcat filename #查看squid日誌5./usr/local/ats/bin/traffic_logstats #查看狀態
Apache Traffic Server(ats)