centos 安装java + tomcat

2023-12-24 17:33:20

centos 安装java + tomcat

tomcat支持jsp,apache2支持php

1, 查看是否已经安装java并卸载
yum list installed | grep 'java\|jdk\|gcj\|jre'

yum remove -y 
2,安装JAVA-JDK
lscpu | grep Architecture # 查看系统架构, x86_64

yum list |grep jdk | grep x86_64

yum install java-1.8.0-openjdk-devel.x86_64

which java # /usr/bin/java
ls -lr /usr/bin/java #  /usr/bin/java -> /etc/alternatives/java
ls -lr  /etc/alternatives/java # /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64/jre/bin/java


echo export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64 >> /etc/profile
echo export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64/jre >> /etc/profile
echo export CLASSPATH=$JAVA_HOME/lib >> /etc/profile
3,配置tomcat

进入tomcat官方地址:https://tomcat.apache.org/ 在左边选择版本,在右边core下面选择下载tar.gz文件。

或者直接:

cd /usr/local
wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.97/bin/apache-tomcat-8.5.97.tar.gz
tar -xvf apache-tomcat-8.5.97.tar.gz
rm -rf apache-tomcat-8.5.97.tar.gz
ln -s apache-tomcat-8.5.97 tomcat
systemctl stop firewalld # 关闭防火墙

tomcat启动/停止

sh /usr/local/tomcat/startup.sh # 启动tomcat
ss -antl # 查看8080端口是否启动 浏览器访问http://ip:8080

sh /usr/local/tomcat/shutdown.sh # 关闭tomcat
4,tomcat配置https

生成证书

# 输入密钥比如123456,一路回车就可以
keytool -genkey -v -alias tomcat -keyalg RSA -validity 365 -keystore /usr/local/tomcat/conf/tomcat.keystore

编辑tomcat配置

vim /usr/local/tomcat/conf/server.xml
# 找到这一段
<!-- 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="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" 
               keystoreFile="conf/tomcat.keystore" keystorePass="123456"/>

重新启动

sh /usr/local/tomcat/shutdown.sh # 关闭tomcat
sh /usr/local/tomcat/startup.sh # 启动tomcat
ss -antl # 查看8443是否开启,访问https://ip:8443

文章来源:https://blog.csdn.net/Akun_2217/article/details/135183859
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。