Nov 29, 2012

How to set up Apache Traffic Server on Ubuntu 10.04

Background

Note : This blog post of mine is for general reference and I don't provide any sort of expert advice here. Yeah you can contact me through comment below for any queries and I will try to answer those. 

I was discussing with my friend regarding one of his problem related to multiple Word Press (on different domain) hosting on same server and single static IP Address. Well at the time of our discussion he had configured two domain name based virtual host on Apache Httpd server installed on the physical box running Ubuntu 10.04 LTS. 

As he started talking about the problems which he was facing as traffic on both of his websites are increasing, I realized he need to upgrade his System to handle high traffics.

Well For solving his problem up to an extend we had decided to use web accelerator like Varnish or Squid in front of Apache Httpd. Both of the web cache proxy is here for a while and proven with good track record. While researching onto Web Accelerator I encountered the Apache Traffic Server, which has become top level project on Apache in span of 2 years. Well I had gone through the benchmark results for all the three and found Apache Traffic Server to leading the chart. (See the reference section for detail)

Well I was very excited to bootstrap Apache Traffic Server to work as cache proxy for two domain name based Virtual Host hosted on single IP. Please read further to know more about the installation, basic configuration, logging and cache optimization. I guess its really an interesting stuff. 

Intro - Apache Traffic Server 

Apache Traffic Server is a reverse proxy, cache proxy and forward proxy. Web proxy caching enables you to store copies of frequently-accessed web objects (such as documents, images, and articles) and then serve this information to users on demand. It improves performance and frees up Internet bandwidth for other tasks. 

Official website for Apache Traffic Server is http://trafficserver.apache.org

Similar products: Varnish (https://www.varnish-cache.org)

Installation

Installation of Apache Traffic Server is bit tricky on Ubuntu due to absence of standard apt-get easy installer package. Well but its not that difficult though. I am writing down step by step process for easy understandability.
  1. Download latest tar.bz2 from apache website and put that on ubuntu server any directory.
  2. CD to directory where you had kept the downloaded and then uploaded tar.bz2 file
  3. $ tar xf trafficserver-x.y.z.tar.bz2
  4. $ cd trafficserver-x.y.z
  5. sudo apt-get install g++ libssl-dev tcl-dev libexpat1-dev libpcre3-dev libcap-dev libcap2  (Dependency packages need to be install, it will be used for making the package on current system)
  6.  ./configure           
  7. $ make    (This will build with a destination prefix of /usr/local.)
  8. $ sudo make install   (This finished the installation)

Server Level Configuration

  1. After successful installation, open ld.so.conf ($ sudo nano /etc/ld.so.conf) and add following line .include /usr/local/libexec/trafficserver
  2. Run the following command:  sudo ldconfig

Start and stop

To start Traffic Server manually, issue the following command, passing in the attribute start. This command starts all the processes that work together to process Traffic Server requests as well as manage, control, and monitor the health of the Traffic Server system.
$ sudo trafficserver start/stop
All the configuration parameter related to cache are located in /usr/local/etc/trafficserver/records.config file after making any configuration changes do run command traffic_line -x to apply the configuration changes.

Installation Directories

When we install traffic server, we had not provide the installation directories for config files and executable. These stuffs has been placed with default conventions.

All configurations files : 
  1. /usr/local/etc/trafficserver/
All executables :
  1.  /usr/local/libexec/trafficserver

Important Configuration Files & Usage

$ sudo nano /usr/local/etc/trafficserver/records.config

For changing default port as well as connection time out etc. related data.

Don't forget to execute following command in case of minor rule change:
$ sudo traffic_line -x

In case of severe change like port etc please make sure you had restarted the server:
$ sudo trafficserver restart

For Configuring the mapping 
$ sudo nano /usr/local/etc/trafficserver/remap.config

In the above file, we can provide as many map, reverse map, redirect, reverse redirect configurations.


Apache Virtual Host Specific Configuration

Step 1: $ sudo nano  /usr/local/etc/trafficserver/records.config
In the file make following changes so config read like below
CONFIG proxy.config.reverse_proxy.enabled INT 1
CONFIG proxy.config.url_remap.pristine_host_hdr INT 1 (It make sure host name in http header doesn't change)
CONFIG proxy.configurl_remap.remap_required INT 1

Step 2: $ sudo traffic_line -x

Step 3: $ sudo nano  /usr/local/etc/trafficserver/remap.config

map http://www.abc.com/ http://www.abc.com:8090/

reverse_map http://www.abc.com:8090/ http://www.abc.com/


map http://www.xyz.com/ http://www.xyz.com:8090/

reverse_map http://www.xyz.com:8090/ http://www.xyz.com/


Note: Apache Httpd is running on port 8090

Step 2: $ sudo traffic_line -x

Above configuration is sufficient for setting the initial reverse proxy to listen on default port and serve the request based on domain name from provider (Apache)

In coming blocks we will configure and talk about the Caching and Logging for better performance and management.


Cache Configuration

CONFIG proxy.config.cache.ram_cache.size INT -1 (default value 1 MB per 1 GB Disk Space, alternatively you can set 20971520 (20 MB)) 

Monitoring Traffic & Log File

Log file location - var/log/trafficserver


Reference

No comments:

Post a Comment