• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path 问题解决记录

开发技术 开发技术 4小时前 3次浏览

1.问题

启动Tomcat之后,在浏览器输入IP后显示503,查看catalina.log发现报错:
The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path 问题解决记录

2.问题定位:缺少 tomcat-native library

就是说 缺少Tomcat Native librayr的支持, 因此需要安装 Tomcat Native library。
安装参考 Tomcat-APR/tomcat-native-1.2.23-src源码安装和配置 和 The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path
当然二者都是参考官网 来安装 tomcat-native库:

3.安装tomcat-native 步骤

安装环境:

  • Linux版本:CentOS Linux release 7.9.2009
  • apache-tomcat-9.0.41
  • openjdk version “1.8.0_292”

3.1 确认gcc、apr、apr-devel、apr-util 以及 JDK是否已经安装过,没有就需要安装

# 1.确认 gcc, 若已安装就会显示安装的版本
rpm -qa gcc
# gcc-4.8.5-28.el7_5.1.x86_64
#没有就安装

yum install gcc
# 2.确认 apr, 没有就 yum install gcc
rpm -qa apr
# 3.确认 apr-devel,没有就 yum install apr-devel
rpm -qa apr-devel
# 4.确认 apr-util, 没有就 yum install apr-util
rpm -qa apr-util
# 5. 确认 JDK,没有就 yum install -y java-1.8.0-openjdk
which java 
java -version

3.2. 源码安装tomcat-native-1.2.23

下载地址:官网

下载到 /opt 目录下,tar zxvf tomcat-native-1.2.23-src.tar.gz 解压 ,进入 tomcat-native-1.2.23-src/native ,然后参考官方给的模板执行:

./configure --with-apr=/usr/bin/apr-1-config 
            --with-java-home=/home/jfclere/JAVA/jdk1.7.0_80/ 
            --with-ssl=yes 
            --prefix=$CATALINA_HOME
  • –with-java-home:jdk的安装目录,笔者是 yum install -y java-1.8.0-openjdk 安装的,因此是 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64
  • –prefix:Tomcat安装目录
## 笔者的命令
./configure --with-apr=/usr/bin/apr-1-config 
            --with-java-home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64 
            --with-ssl=yes 
            --prefix=/usr/local/apache-tomcat-9.0.41

然后 编译安装 make && make install 成功后会看到如下的内容:

Libraries have been installed in:
   /usr/local/apache-tomcat-9.0.41/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'

即库已经安装到之前 --prefix指定目录下的 lib子目录中,同时还需要以下操作:

修改 /usr/local/apache-tomcat-9.0.41/bin/catalina.sh ,在 文件末尾添加

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apache-tomcat-9.0.41/lib
export LD_LIBRARY_PATH

再在 /usr/local/apache-tomcat-9.0.41/conf/server.xml 配置 Tomcat Connector,将 protocol修改成如下内容:

<Connector port="80" protocol="org.apache.coyote.http11.Http11NioProtocol"
               connectionTimeout="20000"
               redirectPort="8443" />

重启Tomcat服务器 问题就解决了
The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path 问题解决记录


喜欢 (0)