Apache Traffic Server installation configuration

Posted by sendoh07 on Tue, 28 Dec 2021 03:24:38 +0100

 

Introduction

Apache Traffic Server (ATS or TS) is a high-performance and modular HTTP proxy and cache server. Traffic Server was originally a commercial product of Inktomi company, which was acquired by Yahoo in 2003. Since then, Traffic Server has been used in Yahoo for up to 4 years until Yahoo submitted it to Apache Software Foundation in August 2009 (ASF) contributed the source code and became the top level project of ASF in April 2010. Apache Traffic Server is now an open source project with the development language of C + +.

System environment

Operating system: CentOS 7.9 x86_ sixty-four
Application: Apache traffic Server 7.0 0

#Official website
https://trafficserver.apache.org/
Installation environment
yum install 'liblz*' -y
yum install net-tools -y
yum install gcc gcc-c++ glibc-devel -y 
yum install autoconf automake pkgconfig libtool -y 
yum install perl-ExtUtils-MakeMaker perl-URI.noarch -y 
yum install openssl-devel tcl-devel expat-devel -y 
yum install pcre pcre-devel zlib-devel xz-devel -y 
yum install libcap libcap-devel flex hwloc hwloc-devel -y 
yum install lua-devel curl curl-devel sqlite-devel bzip2 -y 
1.install pcre
[root@web_01 pcre-8.36]# wget http://ftp.exim.llorien.org/pcre/pcre-8.36.tar.gz 
[root@web_01 pcre-8.36]# tar xf pcre-8.36.tar.gz   
[root@web_01 pcre-8.36]# cd pcre-8.36 
[root@web_01 pcre-8.36]# ./configure --prefix=/usr/local/trafficserver/pcre 
[root@web_01 pcre-8.36]# make && make instal
2.install trafficserver
[root@web_01 ~]# cd /usr/local/src/
[root@web_01 src]# wget https://mirrors.aliyun.com/apache/trafficserver/trafficserver-7.0.0.tar.bz2
[root@web_01 pcre-8.36]# tar xf trafficserver-7.0.0.tar.bz2 
[root@web_01 pcre-8.36]# cd trafficserver-7.0.0  
[root@web_01 trafficserver-7.0.0]# ./configure --prefix=/usr/local/trafficserver --with-pcre=/usr/local/trafficserver/pcre --enable-example-plugins --enable-experimental-plugins
[root@web_01 trafficserver-7.0.0]# make  && make install
 Note:--enable-example-plugins --enable-experimental-plugins These two instructions are for installation ATS Officially integrated plug-ins
[root@web_01 trafficserver-7.0.0]# cd /usr/local/trafficserver/bin/
[root@web_01 bin]# ./trafficserver start
Starting Apache Traffic Server:                            [  Ok

Traffic Server process management

We can see that the ATS service starts three processes (traffic_cop, traffic_manager and traffic_server) to serve ATS requests, manage, control and monitor the health of the system, as shown in Figure 1 below:

  • traffic_ The server process is the transaction engine of ATS. Responsible for receiving and processing protocol requests and providing resources from local cache or source server.
  • traffic_ The manager process is a tool used to command and control ATS. It is responsible for starting, monitoring and reconfiguring ports, statistical interfaces, cluster management and VIP failover.

    If traffic_ The manager process detected traffic_ If the server process fails, it will not only restart the process immediately, but also maintain a connection queue for all incoming requests. In traffic_ Within a few seconds before the server restarts, all incoming connections will be saved in a queue and processed in the form of FIFO. This connection queue will receive any connections in case of server failure restart.

  • traffic_top process monitoring traffic_server and traffic_ The health of the manager process.

   traffic_ The top process queries the traffic_server and traffic_manager processes periodically (several times per minute) by grabbing the heartbeat request of the composite web page. If a failure event occurs (if no request is received or an incorrect request is received within the time interval), traffic_top restarts the traffic_server and traffic_manager.

Simple configuration

 

#Modify records Config file
#25 lines
CONFIG proxy.config.http.server_ports STRING 80
#Line 29
CONFIG proxy.config.http.insert_response_via_str INT 2
#add to
CONFIG proxy.config.log.custom_logs_enabled INT 1
#add to
CONFIG proxy.config.log.xml_config_file STRING logs_xml.config
#add to
CONFIG proxy.config.diags.show_location INT 1
 
#Modify remap The config file is added as follows:
regex_map http://(.*) http://$1
 
#Modify logs_ xml. The config file is added as follows:
<LogFormat>
  <Name = "ats_access_log"/>
  <Format = "%<cqtd>/%<cqtt> %<cqhm> \"%<cquuc>\" %<pssc> %<ttms> %<cqhl> 
%<psql> %<crc> \"%<chi>\" %<pqsn> \"%<{Referer}cqh>\" \"%<psct>\" \"%<{User-agent}cqh>\"
 %<csssc> %<pqsi>"/>
</LogFormat>
 
<LogObject>
  <Format = "ats_access_log"/>
  <Filename = "access"/>
  <Protocols = "http"/>
  <RollingEnabled = "3"/>
  <RollingIntervalSec = "7200"/>
  <RollingSizeMb = "2048"/>
</LogObject>
 
#Modify storage Config file
var/trafficserver 4G
 
#Restart service
[root@controller bin]# pwd
/usr/local/trafficserver/bin
[root@controller bin]# ./trafficserver restart
#test
[root@controller bin]# curl -vx 127.0.0.1:80 -o /dev/null 'http://news.sohu.com/'
* About to connect() to proxy 127.0.0.1 port 80 (#0)
*   Trying 127.0.0.1...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET http://news.sohu.com/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: news.sohu.com
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 200 OK
< Content-Type: text/html;charset=UTF-8
< Content-Length: 170289
< Server: ATS/7.0.0
< Date: Fri, 01 Dec 2017 03:26:44 GMT
< Cache-Control: max-age=120
< X-From-Sohu: X-SRC-Cached
< FSS-Cache: EXPIRED from 9206494.16415464.10543436
< Accept-Ranges: bytes
< FSS-Proxy: Powered by 3308164.4618894.4645016
< Age: 0
< Proxy-Connection: keep-alive
< Via: http/1.1 controller (ApacheTrafficServer/7.0.0 [cSsSfU])
< 
{ [data not shown]
100  166k  100  166k    0     0   152k      0  0:00:01  0:00:01 --:--:--  152k
* Connection #0 to host 127.0.0.1 left intact

record.conf

This file is the core master configuration file of ATS

Modify and start ATS user

CONFIG proxy.config.admin.user_id STRING webserver 

Change the default port to 80 for reverse proxy

CONFIG proxy.config.http.server_ports STRING 80

Close VIA request to the original server header information

CONFIG proxy.config.http.insert_request_via_str INT 0

Configure cache server response headers

CONFIG proxy.config.http.insert_response_via_str INT 2

Enable all accept encoding header normalization:

CONFIG proxy.config.http.normalize_ae_gzip INT 1

Turn off caching dynamic content

CONFIG proxy.config.http.cache.cache_urls_that_look_dynamic INT 1

To modify the memory cache size, it is recommended to use 1 / 2 or 1 / 3 of physical memory

CONFIG proxy.config.cache.ram_cache.size INT 25297631232

Modify the maximum size of a single cache file

CONFIG proxy.config.cache.ram_cache_cutoff INT 119430400

Modify default cache algorithm

CONFIG proxy.config.cache.ram_cache.algorithm INT 1

Modify the automatic jump address when the host is not configured

proxy.config.header.parse.no_host_url_redirect STRING http://www.wapka.com

Starting from the HTTP WEB UI, add the following two lines at the bottom of the file

CONFIG proxy.config.http_ui_enabled INT 3

CONFIG proxy.config.http.enable_http_info INT 1

cache.conf

This file is used to configure ATS cache aging, etc. Add cache expiration time for each type of file

dest_domain=wapka.com suffix=gif revalidate=6h

dest_domain=wapka.com suffix=jpg revalidate=6h

dest_domain=wapka.com suffix=jpeg revalidate=6h

dest_domain=wapka.com suffix=png revalidate=6h

dest_domain=wapka.com suffix=bmp revalidate=6h

dest_domain=wapka.com suffix=swf revalidate=6h

dest_domain=wapka.com suffix=ico revalidate=6h

dest_domain=wapka.com suffix=js revalidate=6h

dest_domain=wapka.com suffix=css revalidate=6h

dest_domain=wapka.com revalidate=12h

stroage.conf

This file is the setting for file caching. Modify the cache file storage when the system kernel is higher than 2.6 3. Bare equipment can be used

/home5/data 250G

remap.conf

This file is mainly used to configure the host and back to source address

First:

regex_map http://(.*) http://$1

Second:
map http://s1.wapka.com/ http://s.wapka.in/

reverse_map http://s.wapka.in http://s1.wapka.com

Differential jump can also be configured

regex_redirect http://[0-9].wapka.in http://www.wapka.com

You can also configure the anti-theft chain in the format of user request address, return source address, return user address and allowed domain

map_with_referer down0.game.uc.cn/ugameun/(.*)?filename=(.*) http://down0.game.uc.cn/ugameun/$1 http://down0.game.uc.cn/ugameun/$2 *\.haha.cn

Enable HTTP WEB UI

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

 

Daily operation

Start, close and restart traffic_ cop. (it should be understood that the traffic_cop process will affect the other two processes)

bin/trafficserver start

bin/trafficserver stop

bin/trafficserver restart

Start and close traffic_server (traffic_cop needs to be started first for the following operations)

bin/traffic_line -U

bin/traffic_line -S

Restart traffic_manager.

bin/traffic_line -L

Reload profile

bin/traffic_line -x

Clear all caches

bin/traffic_server -Cclear

Clear specified cache

URL=$2

HOST=`echo ${URL} | awk -F"/" '{print $3}'`

URI=`echo ${URL} | cut -d"/" -f4-`

curl -X PURGE -I -H Host:${HOST} http://127.0.0.1/$URI

view log

bin/traffic_logcat var/log/trafficserver/squid.blog

Log analysis

bin/traffic_logstats var/log/trafficserver/squid

docker deployment:

First:

docker run -d --name TrafficServer -p 8080:8080 shaker/trafficserver

Second:

Docker trafficserver: docker configuration for running Apache Traffic Server (ATS)
5.3.0

docker run -d --name trafficserver -p 8080:80 -p 8443:443 -e TRAFFICSERVER_HOST=47.99.57.254 -e TRAFFICSERVER_DEBUG=true eanushan/trafficserver

Topics: Operation & Maintenance Apache server