Tomcat和APR lib:需要不可用的APR /本机库

时间:2016-10-12 12:37:31

标签: java tomcat apr

server.xml中

<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
           connectionTimeout="4000"
           redirectPort="8443" />

Tomcat日志

Oct 12, 2016 3:11:41 PM org.apache.catalina.core.AprLifecycleListener init
SEVERE: An incompatible version 1.1.27 of the APR based Apache Tomcat Native library is installed, while Tomcat requires version 1.1.32
Oct 12, 2016 3:11:41 PM org.apache.catalina.core.StandardService initInternal
SEVERE: Failed to initialize connector [Connector[HTTP/1.1-8080]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-8080]]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:560)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:838)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:642)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:667)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:253)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:427)
Caused by: org.apache.catalina.LifecycleException: The configured protocol [org.apache.coyote.http11.Http11AprProtocol] requires the APR/native library which is not available
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:972)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    ... 12 more

安装了pakets

APR-1.3.9-5.el6_2.x86_64

Tomcat的7.0.70-2.el6.noarch

的OpenSSL 1.0.1e-48.el6_8.3.x86_64

Tomcat的本机1.1.34-1.el6.x86_64

java的1.8.0-的openjdk-1.8.0.101-3.b13.el6_8.x86_64

操作系统:CentOS

如何解决此错误?

2 个答案:

答案 0 :(得分:3)

尝试升级您的库。 将此代码运行到终端:

  

sudo apt-get upgrade libtcnative-1

它应该解决问题。

答案 1 :(得分:1)

在这种情况下,APR库可能缺少tc-native的ssl连接器的库,修复如下:

        . yum install apr-devel openssl-devel
        . download into $CATALINA_HOME/conf/tomcatnative and unpack the file tomcat-native-1.2.23-src.tar.gz
        . goto /native and run a command, this is the syntax
            ./configure --with-apr=$HOME/APR \
                        --with-java-home=$JAVA_HOME \
                        --with-ssl=$HOME/OPENSSL \
                        --prefix=$CATALINA_HOME

            And this is the real command
            ./configure --with-apr=/usr/bin/apr-1-config --with-java-home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64 --with-ssl=/usr/bin --prefix=/opt/tomcat

        . then run 'make && make install'
            (should have 'done' in the result without errors)
            (generated libs of tcnative are found under $CATALINA_HOME/lib)

        . under server.xml make sure below line exists
            <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

        . Edit $CATALINA_HOME/bin/setenv.sh (creating the file if necessary) and add the path to the tc-native libraries to LD_LIBRARY_PATH
            'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib'
            'export LD_LIBRARY_PATH'

    - now start tomcat and test, the following should be seen in logs/catalina.out 
        09-Apr-2020 12:16:07.075 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.23] using APR version [1.4.8].
        09-Apr-2020 12:16:07.075 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
        09-Apr-2020 12:16:07.075 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
        09-Apr-2020 12:16:07.089 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2k-fips  26 Jan 2017]
        09-Apr-2020 12:16:11.235 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
        09-Apr-2020 12:16:11.702 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["https-openssl-apr-8443"]

        . then test https://ip:8443/tx, should be accessible