1. APR 설치

이후에 설명하게 되는 각종 컴파일 작업을 위하여 APR(Apache Portable Runtime)을 반드시 설치해야 한다.

CentOS 의 경우 yum install apr-util-devel 로 설치하면 의존성 패키지까지 자동으로 설치가 된다. 단, 2013년 7월 현재 CentOS에서 yum 으로 설치하는 apr 버전은 1.3.9인데 Apache HTP Server 2.4.x 버전의 경우 apr 1.4 이상을 요구한다. 만일 Apache HTTP Server 2.4.x 버전을 사용할 계획이라면 apr 1.4 이상을 수동 설치 (소스 컴파일) 해야 한다.

소스 파일은 apr.apache.org 에서 다운로드 한다. 2013년 7월 기준 최신버전은 다음과 같다.

  • apr-1.4.8.tar.gz
  • apr-util-1.5.2.tar.gz

1-1. apr-1.4.8.tar.gz 설치

$ gzip -d apr-1.4.8.tar.gz
$ tar -xvf apr-1.4.8.tar
$ cd apr-1.4.8
$ ./configure --prefix=/sw/apr148 (설치를 원하는 디렉토리 기재)
$ make
$ make install

1-2. apr-util-1.5.2.tar.gz 설치

$ gzip -d apr-util-1.5.2.tar.gz
$ tar -xvf apr-util-1.5.2.tar
$ cd apr-util-1.5.2
$ ./configure --prefix=/sw/aprutil152 --with-apr=/sw/apr148/bin/apr-1-config
$ make
$ make install

1-3. 설치 확인

$ ls -tlr /sw/apr148
total 16
drwxr-xr-x 3 root root 4096 Jul 23 11:11 include
drwxr-xr-x 2 root root 4096 Jul 23 11:11 build-1
drwxr-xr-x 3 root root 4096 Jul 23 11:19 lib
drwxr-xr-x 2 root root 4096 Jul 23 11:19 bin

2. APR 기반의 Tomcat Native Library 설치

 Tomcat Native Library 는 성능 향상에 도움을 준다. 특히 Tomcat 에서 SSL 처리를 하는 아키텍처에서는 필수적이라고 할 수 있다. (Oracle WebLogic 에서 Performance Pack 을 설치하여 Native I/O 를 enable 하는 것과 비슷함)

일반적인 경우, 즉 APR 을 사용하지 않는 경우 connector class 는 다음과 같다.

  • HTTP/1.1 : org.apache.coyote.htttp11.Http11Protocol
  • AJP/1.3 : org.apache.coyote.http11.AjpProtocol

APR 사용시에는 connector class 가 다음과 같이 변경된다.

  • HTTP/1.1 : org.apache.coyote.htttp11.Http11AprProtocol
  • AJP/1.3 : org.apache.coyote.http11.AjpAprProtocol

Tomcat default 로는 다음 기동 로그와 같이 Native Library 설정이 되어 있지 않다. Windows 서버의 경우도 동일하다.

Native Library 소스 파일은 bin 디렉토리 하위에 위치해 있다. 설치 절차는 다음과 같다.

$ gzip -d tomcat-native.tar.gz
$ tar -xvf tomcat-native.tar
$ cd tomcat-native-1.1.27-src
$ cd jni/native
$ ./configure \
--with-java-home=/usr/lib/jvm/java-1.7.0-openjdk.x86_64 \
--with-apr=/sw/apache/apr148/bin/apr-1-config \
--with-ssl \
--prefix=/sw/tomcat/tct7042/domains/sarcDomain/sarcTomcat
$ make
$ make install

다음과 같은 메시지가 나오면 make install 까지 완료된 것이다.

----------------------------------------------------------------------
Libraries have been installed in:
   /sw/tomcat/tct7042/domains/sarcDomain/sarcTomcat/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

위와 같은 과정을 마치면 ${INST_HOME}/lib 디렉토리 내부에 관련 파일이 생성된다.


3. 적용

3-1. export 

3-2. 로그 확인

3-2-1. 적용 전

09-Jan-2018 10:35:56.644 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]

3-2-2. 적용 후

09-Jan-2018 10:37:15.778 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.5.2].
09-Jan-2018 10:37:15.778 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
09-Jan-2018 10:37:15.778 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
09-Jan-2018 10:37:15.787 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2k-fips  26 Jan 2017]

4. APR 기능

위와 같이 설치가 되고 나면 Tomcat connector 는 자동으로 APR 을 사용하게 된다. APR 설정 후 Tomcat 에서는 다음과 같은 기능이 가능해진다.

  • Secure session ID 생성
  • Tomcat status 애플리케이션에서 OS 레벨에서 수집된 메모리와 CPU 사용률 통계 확인

Connector 설정은 일반 설정과 유사하나 일부 추가되는 것이 있다.


5.  업데이트

2018년 현재 yum으로 설치 시 apr 1.5 이상이 잘 설치된다.

(1/9): apr-util-1.5.4-6.18.amzn1.x86_64.rpm | 99 kB 00:00:00
(2/9): apr-1.5.2-5.13.amzn1.x86_64.rpm | 118 kB 00:00:00
(3/9): apr-devel-1.5.2-5.13.amzn1.x86_64.rpm | 210 kB 00:00:00
(4/9): db4-devel-4.7.25-18.11.amzn1.x86_64.rpm | 7.0 MB 00:00:00

다음과 같은 곳에 설치되니 참고하기 바란다.

./usr/lib64/apr-util-1
./usr/lib64/pkgconfig/apr-util-1.pc
./usr/lib64/pkgconfig/apr-1.pc
./usr/lib64/apr-1
./usr/lib64/apr-1/build/apr_rules.mk
./usr/bin/apropos
./usr/bin/apr-1-config

또한 Tomcat Native 컴파일 시을 위한 configure 시에 단지 --with-apr 옵션만 주면 알아서 인식한다.

checking for APR... yes
configure: APR 1.5.2 detected.