首页 > 系统相关 >centos环境tomcat配置SSL

centos环境tomcat配置SSL

时间:2023-08-04 21:12:59浏览次数:49  
标签:java tomcat centos -- SSL usr HOME native

环境: centos7.9 tomcat9 jdk1.8

一.阿里云申请 免费SSL

按照官网的方法并未成功启动!

443 80端口加入安全组
阿里云申请免费ssl 下载后解压将localhost-rsa.pfx上传至tomcat 的 /usr/local/tomcat/apache-tomcat-9/conf/ 下

下载私钥key/公钥pem

配置service.xml
修改 redirectPort="443"
            <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443"
               maxParameterCount="1000"
               />
新增 Connector 可以将xxx.pfx文件 修改为localhost-rsa.pfx
    <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true"
               maxParameterCount="1000"
               >
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="/usr/local/tomcat/apache-tomcat-9/conf/localhost-rsa.pfx"
                         certificateKeystorePassword="密码"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!-- APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
            <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443"
               maxParameterCount="1000"
               />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080"  protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               maxParameterCount="1000"
               />
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    
    <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true"
               maxParameterCount="1000"
               >
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="/usr/local/tomcat/apache-tomcat-9/conf/localhost-rsa.pfx"
                         certificateKeystorePassword="n3ng517h"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the APR/native implementation which always uses
         OpenSSL for TLS.
         Either JSSE or OpenSSL style configuration may be used. OpenSSL style
         configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true"
               maxParameterCount="1000"
               >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                         certificateFile="conf/localhost-rsa-cert.pem"
                         certificateChainFile="conf/localhost-rsa-chain.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    
    <!--<Connector protocol="AJP/1.3"
               address="::1"
               port="8009"
               redirectPort="443"
               maxParameterCount="1000"
               /> -->
    

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

		    <Context path="" docBase="/usr/local/tomcat/apache-tomcat-9/webapps/blog"/>

      </Host>
    </Engine>
  </Service>
</Server>

二.下载安装JDK,yum安装后面依赖缺少时还要重新配置环境变量

(1)查看是否已安装jdk JDK1.8 验证6BA16928.png mx1f

rpm -qa | grep jdk

(2)查看jdk版本

java -version

(3)删除所有旧版本jdk
  1. 删除java的安装目录
#卸载所有openjdk相关文件输入
yum -y remove java-1.8.0-openjdk*

#卸载tzdata-java
yum -y remove tzdata-java.noarch  
  1. vi /etc/profile 删除关于java的配置
  2. source /etc/profile 立刻生效; java -version 此时查不到
  3. 下载后解压 配置jdk 环境 在 /etc/ 下修改profile 将如下粘贴到最后
export JAVA_HOME=/usr/local/java/jdk8
export JRE_HOME=/usr/local/java/jdk8/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin

一些问题

1.Failed to initialize component [Connector[HTTP/1.1-443]] ;

  • 检查上述文件的por是否正确
  • 查看catalina.2023-08-03.log 日志信息,例如: 命名写错了FileNotFoundException该正后就行了

2.The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib/am

原因:缺少依赖 需要配置安装依赖 可参考

1、安装 openssl

yum install apr-devel openssl-devel

2、安装 tomcat-native

tomcat-native 下载解压安装。tomcat-native-1.2.23-src.tar.gz

# 解压
tar xzcf tomcat-native-1.2.23-src.tar

# 进入/native下
cd tomcat-native-1.2.23-src/native

# 安装  
./configure 

# 安装
make && make install

3、配置 tomcat 的 setenv.sh 文件

在tomcat安装目录的bin /usr/local/tomcat/apache-tomcat-9/bin/ 下setenv.sh 文件则新建一个

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib

4. minio无法使用 Unsupported or unrecognized SSL message

无解决 准备换阿里云存储或者其他 OSS云存储

标签:java,tomcat,centos,--,SSL,usr,HOME,native
From: https://www.cnblogs.com/july7/p/17607035.html

相关文章

  • CentOS7虚拟机网络无法连接问题 --- network.service failed---已解决,亲测有效
    问题描述昨天虚拟机用的好好的,今天虚拟机网络突然挂掉了,FinalShell无法连接,Radis无法使用了,自己尝试无果后,把问题抛给了同事,同事用三个命令行就解决了,现在对问题进行记录,方便以后查阅。问题排查首先,我打开命令窗口,在命令行输入ifconfig指令,发现IP地址直接不见了。什么情况?然后,我打......
  • Aapache Tomcat AJP 文件包含漏洞(CVE-2020-1938)
    AapacheTomcatAJP文件包含漏洞(CVE-2020-1938)【项目中遇到过】1.背景简述java是目前WEB开发中主流的编程语言,而Tomcat是当前流行的Java中间件服务器之一。Ghostcat(幽灵猫)是由长亭科技安全研究员发现的存在于Tomcat中的安全漏洞,由于TomcatAJP协议设计上存在缺陷,攻击者通......
  • centos7 Cannot retrieve metalink for repository: epel/x86_64. Please verify its
     备份原始的EPEL存储库配置文件(可选):在更改前,建议您先备份原始的EPEL存储库配置文件,以便在需要时恢复到默认设置。在终端中执行以下命令备份:sudocp/etc/yum.repos.d/epel.repo/etc/yum.repos.d/epel.repo.backup编辑EPEL存储库配置文件:使用文本编辑器(例如nano......
  • 如何在 CentOS 7 安装 TCP BBR 拥塞算法
    TCPBBR介绍首先对TCPBBR做个介绍。TCPBBR(全称BottleneckBandwidthandRound-trippropagationtime)是由Google设计,于2016年发布的拥塞算法。之前大部分拥塞算法是基于丢包作为判断降低传输速率的信号,而BBR则基于模型主动探测。该算法使用网络最近出站数据分组当时的最......
  • Java17与相关框架支持版本SpringBoot、IDEA、Tomcat等
    相关框架需要的最低版本NameVersionJava17+SpringFramework6.0SpringBoot3.0Tomcat10.1Maven3.6.3+Gradle7.x(7.5orlater)and8.xUndertow2.3IntelliJIDEA2021.2+SpringFrameworkSpringFrameworkOverview::SpringFrame......
  • Linux(Centos7.6)Nginx安装
    简介Nginx(enginex)是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx可以托管用户编写的WEB应用程序成为可访问的网页服务,同时也可以作为流量代理服务器,控制流量的中转。Nginx在WEB开发领域,基本上也是必备组件之一了。————————————......
  • CentOS7 安装部署 OceanBase 数据库
    OceanBase是由蚂蚁集团完全自主研发的国产原生分布式数据库,本文以x86架构的CentOSLinux7.9主机作为环境对该数据库的安装部署进行介绍。背景OceanBase数据库自V4.0.0开始提供统一的安装包all-in-onepackage。您可以通过这个统一的安装包一次性完成OBD、OceanBase......
  • 阿里云平台WoSign SSL证书应用案例
    沃通CA与阿里云达成合作并在阿里云平台上线WoSign品牌SSL证书。自上线以来,WoSignSSL证书成为阿里云“数字证书管理服务”热销证书产品,获得阿里云平台客户认可,助力阿里云平台政府、金融、教育、供应链、游戏等各类行业客户实现网站系统数据传输安全。WoSignSSL证书,行业客户信赖之......
  • nginx使用openssl自签名,实现https登录
    1.确认nginx是否已安装SSL模块查验方法:进入sbin目录,执行以下语句,显示结果如标记所示则表示安装成功./nginx-V 2.确认系统以安装SSL工具,开始制作证书选择一个存放证书的路径,执行以下语句即可:(1)生成密钥,得到文件private.keyopensslgenpkey-algorithmRSA-outprivate.ke......
  • centos7安装k3s
    1、关闭selinux(每台服务器)sed-i'/SELINUX/s/enforcing/disabled/'/etc/selinux/configsetenforce02、关闭交换分区(每台服务器)vim/etc/fstab找到swap一行注释掉swapoff-a3、关闭防火墙(每台服务器)systemctlstopfirewalldsystemctldisablefirewalld4、设置三台服务器主机......