IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    apache traffic server 简称ats 入坑(一)开始使用

    linuxphp@qq.com(keminar)发表于 2015-10-16 23:09:00
    love 0
    贵贵的博客 ( http://blog.linuxphp.org/ ) :

    安装就系统常见三步,configure && make && make install 简单之极。

    安装后坑才刚刚开始,这个软件国内外介绍都极其少,虽然开源软件官方文档不错,阿里也有一些介绍,但真的就仅此而已了。

    先说下此软件最重要的几个配置records.config, remap.config, cache.config, logs_xml.config

    下面说下学习过程中遇到的种种。

    1.理解remap.config,配置了此项才能通过ats访问到网站

    regex_map http://(.*)/ http://example-in.com/

    第一个地址是用户访问的地址,第二个地址就源服务器的地址

     

    2.先要能通过其访问网站内容,结果遭遇DNS问题

    错误:Description: Unable to locate the server requested --- the server does not have a DNS entry. Perhaps there is a misspelling in the server name, or the server no longer exists. Double-check the name and try again.

    原因:remap.config里面使用了本地解析域名,ats不会读取/etc/hosts

    解决方法:

    需要在用dnsmasq配置个小DNS服务器,然后修改配置文件(etc/trafficserver/records.config)

    CONFIG proxy.config.dns.nameservers STRING 192.168.x.x

    也可以通过ip访问实际地址(etc/trafficserver/remap.config)

    regex_map http://(.*)/ http://127.0.0.1/

    通过IP访问需要设置请求源服务器时带上host信息(etc/trafficserver/records.config)

    CONFIG proxy.config.url_remap.pristine_host_hdr INT 1

     

    3.能访问了就要检查能否命中缓存,打开age和via头

    打开VIA输出(etc/trafficserver/records.config)

    CONFIG proxy.config.http.insert_response_via_str INT 2 

    打开age输出(etc/trafficserver/records.config)

    CONFIG proxy.config.http.insert_age_in_response INT 1

    via 查询地址,可以查询是否cache命中

    http://trafficserver.apache.org/tools/via.html

    age是从0增加的,数值是几就代表几秒。ats可以通过它判断是否新鲜(过期)然后请求源服务器

     

    4.通过via头部信息看到没有缓存每次都是miss,原因就是我没有输出相关的头部信息,这里设置全缓存

    不考虑header全cache(etc/trafficserver/records.config)

    CONFIG proxy.config.http.cache.required_headers INT 0

    说明 http://blog.zymlinux.net/index.php/archives/1090

     

    5.到这里应该可以缓存到内容了。先附加两个相关其它配置。缓存失效期下一篇再讲解

    #缓存任何结果(带不带cookie)(etc/trafficserver/records.config)
    CONFIG proxy.config.http.cache.cache_responses_to_cookies INT 1
    
    #缓存带问号在网址(etc/trafficserver/records.config)
    CONFIG proxy.config.http.cache.cache_urls_that_look_dynamic INT 1
    
    #忽略客户端no-cache(etc/trafficserver/records.config)
    CONFIG proxy.config.http.cache.ignore_client_no_cache INT 1
    CONFIG proxy.config.http.cache.ims_on_client_no_cache INT 1

    说明:http://blog.sina.com.cn/s/blog_67b570090101clrg.html

    6.自定义ATS via 名字

    CONFIG proxy.config.proxy_name STRING cache
    CONFIG proxy.config.http.response_via_str STRING mycdn


沪ICP备19023445号-2号
友情链接