Apache Traffic Server(ats)


零.前言
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/trafficserver

2.重要配置文件:
(1).records.config 主要配置文件,配置ats的各項參數
安裝完后該項保持默認配置

(2).remap.config 配置訪問域名和源
如,在該文件最后增加

map http://domain.com http://113.7.1.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

 

dest_ip=127.0.0.1 suffix=gif ttl-in-cache=60d
dest_ip=127.0.0.1 suffix=jpg ttl-in-cache=60d
dest_ip=127.0.0.1 suffix=jpeg ttl-in-cache=60d
dest_ip=127.0.0.1 suffix=png ttl-in-cache=60d
dest_ip=127.0.0.1 suffix=bmp ttl-in-cache=60d
dest_ip=127.0.0.1 suffix=swf ttl-in-cache=60d
dest_ip=127.0.0.1 suffix=ico ttl-in-cache=60d
dest_ip=127.0.0.1 suffix=js ttl-in-cache=60d
dest_ip=127.0.0.1 suffix=css ttl-in-cache=60d

 以上將標示緩存127.0.0.1的靜態文件,緩存60天

(5).logs_xml.config 配置日志

 

三.常用配置

1.配置http ui

(1).在recoreds.config最后增加

CONFIG proxy.config.http_ui_enabled INT 3
CONFIG 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.1
map http://localhost/stat/ http://{stat} @action=allow @src_ip=127.0.0.1
map http://localhost/test/ http://{test} @action=allow @src_ip=127.0.0.1
map http://localhost/hostdb/ http://{hostdb} @action=allow @src_ip=127.0.0.1
map http://localhost/net/ http://{net} @action=allow @src_ip=127.0.0.1
map http://localhost/http/ http://{http} @action=allow @src_ip=127.0.0.1

  

(3).通過以上配置,即可通過http協議來訪問http ui

2.配置日志
(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 0
CONFIG 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 reload

4.查看squid日志
/usr/local/ats/bin/traffic_logcat filename #查看squid日志

5./usr/local/ats/bin/traffic_logstats #查看狀態

6./usr/local/ats/bin/traffic_via [cRs f ] #查看via頭狀態


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM