dryu999 发表于 2018-10-19 07:46:41

Apache Traffic Server 5.3.2及6.2.1的使用初探索

转载  a、打开 record.config 文件,修改或者添加如下内容:
  LOCAL proxy.local.cluster.type INT 1
  CONFIG proxy.config.proxy_name STRING MyCluster
  CONFIG proxy.config.cluster.ethernet_interface STRING eth0
  b、集群需要满足下面的条件:
  1、集群中的机子配置要相同
  2、集群中的机子要使用相同版本的ATS
  3、集群中的机子需要在同一个ip段
  4、集群中名称必须相同proxy.config.proxy_name
  c、重新启动 ATS ,或者使用下面的两条命令:
  traffic_line -x
  traffic_line -L
  d、使用 traffic_line -r proxy.process.cluster.nodes查看集群中的机子数量
六、防盗链配置
  a、打开 record.config 文件,修改或者添加如下内容:
  CONFIG proxy.config.http.referer_filter INT 1
  b、打开 remap.config 添加如下内容:
  map_with_referer http://www.ats200.com/ http://www.test200.com/http://127.0.0.1/error.html ~* .*\.bzq\.com
  格式为:
  map_with_referer client-URL origin-server-URL redirect-URLregex1
  其中, ~* 表示Referer头是可选的(没有Referer头正常访问)
  上边配置的意思是:
  1、请求头中没有Referer头的可以正常访问
  2、请求头中有Referer头,并且Referer头字段的内容是 .*\.bzq\.com的才可以正常访问
  3、不符合上边两条规则的,会自动跳转到 http://127.0.0.1/error.html页面
七、DNS 解析服务器指定
  a、打开 record.config 文件,修改或者添加如下内容:
  CINFIG proxy.config.dns.splitDNS.enabled 1
  b、打开 splitdns.config 文件,加入如下内容:
  dest_domain=www.ats100.com named="192.168.210.2"
  c、上边配置的意思就是域名 www.ats100.com 在 192.168.210.2 域名解析服务器上解析
八、ui界面检查缓存状态:
  1. 主配置文件records.config
  加入:CONFIG proxy.config.http_ui_enabled INT 3
  CONFIG proxy.config.http.enable_http_info INT 1 (可选项)
  remap.config:
  map http://www.test100.com/ http://www.test100.com/
  map http://www.ui.com/ http://{cache} @action=allow@src_ip=192.168.153.1
  测试:
  map http://192.168.180.195/cache-internal/http://{cache-internal}
  maphttp://192.168.180.195/cache/ http://{cache}
  maphttp://192.168.180.195/stat/ http://{stat}
  maphttp://192.168.180.195/test/ http://{test}
  maphttp://192.168.180.195/hostdb/ http://{hostdb}
  maphttp://192.168.180.195/net/ http://{net}
  map http://192.168.180.195/http/ http://{http}
  iparent.config:
  dest_domain=www.test100.com parent="192.168.215.3:80"round_robin=strict
  注意:这里如果在remap里map的映射设置的是ip,在使用ui工具时查询时必须输入ip+path来查询,因为缓存时以ip加文件名为key缓存的,
  2.打开浏览器,配置好host (www.ui.com)
  访问www.ui.com,会出现
  Lookup url
  Delete url
  Regex lookup
  Regex delete
  Regex invalidate
  3.先访问test100让其缓存,然后点击各个可查看缓存信息,Lookup url 输入url:http://www.test100.com/test2.html,即可查看信息
  点击delete url 可以删除该缓存中的 url
九、加入lua,配置响应头信息:
  1.修改配置文件plugin.config
  加入:background_fetch.so
  2.修改配置文件remap.config
  map http://www.test100.com/ http://www.test100.com/@plugin=/usr/local/ats/libexec/trafficserver/tslua.so@pparam=/usr/local/ats/lua_ats/test_hdr.lua
  注意:@plugin 这里需要加载tslua.so库, @pparam 这里是编写的lua脚本。
  3.脚本如下(下面是测试的脚本):
  function send_response()
  ts.client_response.header['Host'] =ts.ctx['hdr']
  ts.client_response.header['request-get-method']= ts.ctx['re']
  ts.client_response.header['Uri'] =ts.ctx['uri']
  ts.client_response.header['server'] =ts.ctx['ser']
  local cache_status = ts.http.get_cache_lookup_status()
  if cache_status == TS_LUA_CACHE_LOOKUP_MISS then
  ts.client_response.header['cache-lookup'] ='MISS'
  elseif cache_status == TS_LUA_CACHE_LOOKUP_HIT_STALE then
  ts.client_response.header['cache-lookup'] ='HIT_STALE'
  elseif cache_status == TS_LUA_CACHE_LOOKUP_HIT_FRESH then
  ts.client_response.header['cache-lookup'] ='HIT_FRESH'
  elseif cache_status == TS_LUA_CACHE_LOOKUP_SKIPPED then
  ts.client_response.header['cache-lookup'] ='HIT_SKIPPED'
  end
  return 0
  end
  function do_remap()
  ts.ctx['hdr'] ='www.test100.com'
  ts.ctx['ser'] = 'wang'
  ts.ctx['re'] = ts.client_request.get_method()
  ts.ctx['uri'] = ts.client_request.get_uri()
  ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response)
  return 0
  end
  开启DEBUG
  traffic_ctl config setproxy.config.diags.debug.enabled 1
  然后去日志diags.log或者traffic.out查看有无匹配http_match的日志
  cache_heuristic_min_lifetime=3600导致cache.config的超时配置无效,群里表示是个BUG需反馈

页: [1]
查看完整版本: Apache Traffic Server 5.3.2及6.2.1的使用初探索