1. 程式人生 > >解決Linux下Tomcat由於Tomcat Native問題啟動報錯

解決Linux下Tomcat由於Tomcat Native問題啟動報錯

omact服務啟動報錯日誌如下資訊: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: $JAVA_HOME/jre/lib/amd64/server:$JAVA_HOME/jre/lib/amd64:$JAVA_HOME/jre/../lib/amd64:/usr/java/packages/lib/amd64:/lib:/usr/lib
是由於缺少apr的支援: 
Tomcat Native 是利用 APR 來提升Tomcat效能的本地API
Tomcat Native 這個專案可以讓 Tomcat 使用 Apache 的 apr 包來處理包括檔案和網路IO操作,以提升效能。
以下是tomcat官網說明:

Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies. The Apache Portable Runtime is a highly portable library that is at the heart of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functionality (such as sendfile, epoll and OpenSSL), OS level functionality (random number generation, system status, etc), and native process handling (shared memory, NT pipes and Unix sockets).

解決方案:

安裝apr-devel

#yum install apr-devel

進入tomcat安裝目錄

#cd $CATALINA_HOME/bin

解壓檔案到當前目錄

#tar zxf tomcat-native.tar.gz

進入native原始碼目錄
#cd $CATALINA_HOME/bin/tomcat-native-1.1.27-src/jni/native

配置編譯資訊
#./configure --with-apr=/usr/bin/apr-1-config --with-java-home=$JAVA_HOME --prefix=$CATALINA_HOME

編譯
make && make install
安裝成功如下提示:
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/apr/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.

新增配置:

tomcat安裝目錄bin下建立setenv.sh檔案:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
    export LD_LIBRARY_PATH

tomcat啟動後檢視日誌 apr已載入上
2013-6-8 14:31:05 org.apache.catalina.core.AprLifecycleListener init
資訊: Loaded APR based Apache Tomcat Native library 1.1.23 using APR version 1.3.9.
2013-6-8 14:31:05 org.apache.catalina.core.AprLifecycleListener init
資訊: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].

如果還是報錯則進入到.libs/libs目錄(這裡32位和64位有區別)

ls -al:

libtcnative-1.a

libtcnative-1.la -> ../libtcnative-1.la

libtcnative-1.lai

libtcnative-1.so -> libtcnative-1.so.0.1.27

libtcnative-1.so.0 -> libtcnative-1.so.0.1.27

libtcnative-1.so.0.1.27

裡面有幾個連結檔案,把

libtcnative-1.a

libtcnative-1.lai

libtcnative-1.so.0.1.27

和libtcnative-1.la連結指向的檔案(上一級目錄的libtcnative-1.la)拷貝到$JAVA_HOME/jre/lib/amd64(i386-32位系統)/server下即可。



如果windows下報錯是拷貝幾個dll檔案至windows/system32下,apache官網有。