Tuesday, March 26, 2013

Basic installation of TrafficServer

TrafficServer is quite a piece of software donated by Yahoo! to the Apache software foundation. In a nutshell, is a caching proxy server / accelerator tool for your edge network - with lots of options and capabilities. You can deploy it as:


  • Web Proxy Cache (by default) 
  • Reverse Proxy 
  • Cache Hierarchy 

Using a Web Proxy Cache deployment would be similar to deploy a Squid proxy. Your clients would hit the proxy server, and if there's no cache available the request goes to the server. 

Reverse Proxy deployment is quite interesting, because clients don't hit your web server directly, they will hit the TrafficServer, then traffic server would query everything for them. That's quite useful as you add one more layer between your server and the network, however it will make your web server's access log register only the petitions from TrafficServer - you can make TrafficServer log the petitions for you instead. 

Cache Hierarchy is used for strategic regional cache - kind of set up your own content accelerator for overseas traffic.

It's installation is quite simple, on Debian / Ubunto you can use apt:

$ sudo apt-get install trafficserver

Configuration files are located in the folder /etc/trafficserver, and there's a lot ! going trough the documentation I saw there's many cool features for managing the cache, but that's another level from this kick start. To configure the ports where it will listen we can have a look at records.config:

CONFIG proxy.config.http.server_port INT 8080
CONFIG proxy.config.process_manager.mgmt_port INT 8084
CONFIG proxy.config.admin.autoconf_port INT 8083

For this example we will leave the ports as they are. Now we will configure a reverse proxy, for this example I have:

  • Web Server running TrafficServer, IP 172.16.0.2. Apache server name Nova.mydomain
  • Client, IP 172.16.0.100
First, I will configure the file /etc/trafficserver/remap.config :

$ sudo vim /etc/trafficserver/remap.config

map http://Nova.mydomain http://localhost
reverse_map http://localhost http://Nova.mydomain

If TrafficServer's management daemon is running we can execute the command traffic_line -x to reload the changes. If this command fails, means the management server is not running, so we should start it:

$ sudo /etc/init.d/trafficserver start
$ sudo /etc/init.d/trafficserver status
[ ok ] traffic_server is running.
[ ok ] traffic_manager is running.

If TrafficServer doesn't start, check out the file /etc/default/trafficserver and enable the start of traffic_server and traffic_manager:

 # TM_START=no --> TM_START=yes
 # TS_START=no  --> TS_START=yes

Now, we ensure the client resolves Zealot.com to my webserver IP. If not, we will edit the hosts file:

172.16.0.2     Nova.mydomain

TrafficServer listens on port 8080, so we need to do a redirection with iptables - on a working environment, we would ideally have a router translating that for us.

$ sudo iptables -t nat -I PREROUTING -s 172.16.0.100 -d 172.16.0.2 -p tcp --dport 80 -j REDIRECT --to-port 8080

Now, from the client, every time we try to contact the port 80 it will be redirected to TrafficServer, and it will reverse map the petitions to the localhost using the server name specified in the headers. If we check our access log we can see TrafficServer is requesting our page and not our clients:

$ sudo tail /var/log/apache/access.log
127.0.0.1 - - [24/Mar/2013:14:21:07 +0800] "GET / HTTP/1.1" 200 429 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20120602 Iceweasel/3.5.16 (like Firefox/3.5.16)"
127.0.0.1 - - [24/Mar/2013:14:21:08 +0800] "GET / HTTP/1.1" 200 429 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20120602 Iceweasel/3.5.16 (like Firefox/3.5.16

That's all !

No comments:

Post a Comment