Server/WebServer

Apache Traffic Server (ATS)

Jacob_baek 2014. 4. 29. 16:24

ATS는?

고성능 웹 proxy / cahce 서버


특징

- 멀티스레드 서버

- 이벤트 드리븐 매커니즘


설치 방법

on CentOS

- yum install openssl-devel tcl-devel expat-devel pcre-devel

- wget http://mirror.apache-kr.org/trafficserver/trafficserver-4.2.0.tar.bz2

- wget http://www.apache.org/dyn/closer.cgi/trafficserver/trafficserver-4.2.0.tar.bz2

- 참고사이트 : https://cwiki.apache.org/confluence/display/TS/CentOS

# configure --prefix=/usr/local/ats (설치 디렉토리 지정)

# make; make install


대표적 config 설명

[records.config]

CONFIG proxy.config.http.server_ports STRING 80

CONFIG proxy.config.cache.ram_cache.size INT 10G

CONFIG proxy.config.log.logfile_dir STRING /var/log/ats

CONFIG proxy.config.proxy_name STRING servername.example.com

CONFIG proxy.config.url_remap.remap_required INT 1                         # 1이 enable

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

CONFIG proxy.config.http.normalize_ae_gzip INT 1

CONFIG proxy.config.diags.debug.enabled INT 1                               # Debug 상세 출력(traffic.out)


[storage.config]

/path/to/cache 20G

/dev/sdb


[remap.config]

map http://www.example.com/ http://origin.example.com/

reverse_map http://origin.example.com/ http://www.example.com/


bin/trafficserver [start] 수행시 출력되는 process 설명

Process

traffic_cop : watchdog process

traffic_manager : allows live configuration of the server

traffic_server : the proxy process itself



Plugin Development 관련

Plugin 개발 (sample)

# tsxs -o hello-world.so -c hello-world.c (실행한 현재 디렉토리에 .so파일이 생성)

# sudo tsxs -o hello-world.so -i

위와 같이 수행하게되면 hello-world.so 파일이 libexec/trafficserver/ 하위에 생성된다.(실제 심볼릭 링크)

이후 아래 동적 라이브러리를 추가한다.

/usr/local/ats/etc/trafficserver/plugin.config (insert plugin)

hello-world.so

# /usr/local/ats/bin/traffic_server 

위와 같이 수행하면 실행결과가 출력된다.


일예로 stats_over_http.so 를 plugin.config에 추가하고 URL/_stats 를 browser에 입력하면 stat정보가 출력된다.


Custom Plugin 개발을 위해서는 TSPluginInit가 꼭 포함되어야 한다.

다음과 같은 sample code를 참조한다.

#include <stdio.h>
#include <ts/ts.h>
int check_ts_version() {
    const char *ts_version = TSTrafficServerVersionGet();
    int result = 0;

    if (ts_version) {
        int major_ts_version = 0;
        int minor_ts_version = 0;
        int patch_ts_version = 0;

        if (sscanf(ts_version, "%d.%d.%d", &major_ts_version,
           &minor_ts_version, &patch_ts_version) != 3) {
            return 0;
        }

        /* We need at least Traffic Server 2.0 */
        if (major_ts_version() >= 2) {
            result = 1;
        }
    }
    return result;
}

void TSPluginInit (int argc, const char *argv[]) {
    TSPluginRegistrationInfo info;

    info.plugin_name = "hello-world";
    info.vendor_name = "MyCompany";
    info.support_email = "ts-api-support@MyCompany.com";

    if (!TSPluginRegister (TS_SDK_VERSION_3_0 , &info)) {
        TSError ("Plugin registration failed. \n");
    }

    if (!check_ts_version()) {
        TSError ("Plugin requires Traffic Server 2.0 or later\n");
        return;
    }
    TSDebug ("debug-hello", "Hello World!\n");
}

참고 : http://docs.trafficserver.apache.org/en/latest/sdk/getting-started/plugin-registration-and-version-checking.en.html


위 소스코드와 같이 TSPluginInit을 호출하고 그에 따른 Custom Plugin을 호출하게 한다.


관련 예제소스는 trafficserver 소스내 example 디렉토리를 참조하면 된다.


map을 통해 reverse_proxy 된 페이지를 chrome debuging을 통해 확인해본 결과 다음과 같이 header에 Server : ATS/4.2.0이 출력되었다.



traffic_line command를 이용한 stat 확인

/usr/local/ats/bin/traffic_line -r proxy.node.cache_hit_ratio_avg_10s            # 10초간 캐쉬 히트

/usr/local/ats/bin/traffic_line -r proxy.node.current_client_connections        # 연결된 client 수

/usr/local/ats/bin/traffic_line -r proxy.node.current_server_connections       # 

/usr/local/ats/bin/traffic_line -r proxy.process.cache.volume_0.bytes_total   # 디스크 총량

/usr/local/ats/bin/traffic_line -r proxy.process.cache.volume_0.bytes_used  # 디스크 사용량


TSHttpHookAdd()함수 사용 예제

하나의 예제로 TSHttpHookAdd()함수를 이용하여 Session monitoring을 수행하는 방법을 설명한다.


기본개념

Transaction : request, response등을 개별적으로 지시하는 단어

Session : Transaction의 모음을 일컫음

Continuation : 



참고사이트

- http://docs.trafficserver.apache.org/en/latest/index.html (영문) 위 내용이 상세히 기록되어 있다.

http://labs.omniti.com/people/mark/ats_sa/slides.html ppt 로 상세히 설명되어 있다.

http://tecadmin.net/setup-apache-traffic-server-as-reverse-proxy-on-linux/