最新动态 > 详情

centeos8 安装jdk1.8+tomcat9或者说是解决centos8安装tomcat后修改jre_home,tomcat安装后无法启动的问题

发布时间:2020-08-02 14:33:59


1.rpm -qa | grep java  查看一下有无系统自带jdk
2.yum search java 看看安装哪些版本
3.yum install -y java  执行安装
4.java -version 查看自动安装的版本(我这里查看了是 1.8.0_262),此时有版本号,但是javac命令无效
5.yum install -y java-1.8.0-openjdk-devel.x86_64  这里从刚刚查看的java版本中找到带【devel】的对应版本的jdk安装一次
[root@localhost bin]# yum install -y java-11-openjdk-devel.x86_64

[root@localhost bin]# java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
[root@localhost bin]# javac
用法: javac <options> <source files>

打印JAVA_HOME路径

[root@localhost bin]# echo $JAVA_HOME
/usr/java/jdk1.8.0_65

[root@localhost bin]# vi ~/.bashrc
[root@localhost bin]# echo export JAVA_HOME=/usr/lib/jvm/java/ >> ~/.bashrc
[root@localhost bin]# vi ~/.bashrc

[root@localhost bin]# source ~/.bashrc

[root@localhost bin]# echo $JAVA_HOME
/usr/lib/jvm/java/
[root@localhost bin]# java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)


6.cd /usr/local/
7.下载tomcat: wget https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz
解压 重命名文件夹
mv apache-tomcat-9.0.37 tomcat9

8.cd tomcat/bin/
./start.sh
出现
[root@localhost bin]# ./startup.sh
Using CATALINA_BASE:   /usr/local/tomcat9
Using CATALINA_HOME:   /usr/local/tomcat9
Using CATALINA_TMPDIR: /usr/local/tomcat9/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_65/jre
Using CLASSPATH:       /usr/local/tomcat9/bin/bootstrap.jar:/usr/local/tomcat9/bin/tomcat-juli.jar
Tomcat started.

注意jre_home 对应版本号不一样

需要修改jre_home路径
自动安装的jdk,需要查找路径

[root@localhost bin]# whereis java
java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java /usr/share/man/man1/java.1.gz

[root@localhost bin]# ls -lrt /usr/bin/java
lrwxrwxrwx 1 root root 22 8月   2 14:11 /usr/bin/java -> /etc/alternatives/java
[root@localhost bin]# ls -lrt /etc/alternatives/java
lrwxrwxrwx 1 root root 73 8月   2 14:11 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el8_2.x86_64/jre/bin/java
[root@localhost bin]#

此时可以把jdk安装路径确定下来了/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el8_2.x86_64/

此时可以看一下/etc/profile文件末是否有java相关配置
JAVA_HOME=/usr/local/jdk1.8.0_241 (此项实际不存在,居然没有报错)
JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el8_2.x86_64/jre
CLASSPATH=.:$JAVA_HOME/lib:/dt.jar:$JAVA_HOME/lib/tools.jar

PATH=$PATH:$JAVA_HOME/bin


[root@localhost bin]# ls
bootstrap.jar       ciphers.bat                   configtest.bat  digest.sh         setclasspath.sh  startup.sh            tool-wrapper.sh
catalina.bat        ciphers.sh                    configtest.sh   makebase.bat      shutdown.bat     tomcat-juli.jar       version.bat
catalina.sh         commons-daemon.jar            daemon.sh       makebase.sh       shutdown.sh      tomcat-native.tar.gz  version.sh
catalina-tasks.xml  commons-daemon-native.tar.gz  digest.bat      setclasspath.bat  startup.bat      tool-wrapper.bat
[root@localhost bin]# vi catalina.sh
/#OS specific
在这后面加入

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el8_2.x86_64/(注意这里的路径为实际jdk安装路径)

JRE_HOME=$JAVA_HOME/jre

:wq

再次启动tomcat
[root@localhost bin]# ./startup.sh
Using CATALINA_BASE:   /usr/local/tomcat9
Using CATALINA_HOME:   /usr/local/tomcat9
Using CATALINA_TMPDIR: /usr/local/tomcat9/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el8_2.x86_64/jre
Using CLASSPATH:       /usr/local/tomcat9/bin/bootstrap.jar:/usr/local/tomcat9/bin/tomcat-juli.jar
Tomcat started.

这里不需要修改tomcat默认端口,所以直接访问,成功
http://192.168.3.213:8080/(本地虚拟机地址)

上一篇: php mosquitto(mqtt)完整简洁版

下一篇:CentOS8 RabbitMQ安装笔记