Linux installation jdk, tomcat

Preface

First check whether jdk is installed

java -jar ## 查看是否安装jdk
java -version  ## 查看版本
getconf LONG_BIT ## 检察linux的位数  64

File suffix meaning:

(1)bin代表二进制class文件(由java文件编译而成),src代表源码(java源码),源码source比binary大一些,一般正常使用下载bin类型即可,如果要学习源码下载src类型。
(2).tar.gz是linux的压缩包,.zip是windows的压缩包
	因此:
		bin.tar.gz是适用于linux、MacOsX系统的二进制文件
		bin.zip是适用于windows的二进制文件
		src.tar.gz是linux下的源码
		src.zip是windows的源码

java jdk domestic download mirror address and installation
download address
(1) TUNA mirror https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/
(2) HUAWEI mirror https://repo.huaweicloud.com/java/jdk/
(3) injdk https://www.injdk.cn/

1. Install jdk on Linux

Official website address: https://www.oracle.com/java/technologies/downloads/#java8, but you need to register and log in

# jdk1.8下载需要登陆oracle账号解决
# 解决:从网上找到一个Oracle账号和密码,直接登录使用下载即可
账号:[email protected]
密码:Oracle123

账号:[email protected]
密码:Oracle123

1. jdk installation and configuration process

  1. Upload jdk-8u371-linux-x64.tar.gz to linux
在/usr/java下
mkdir java # 创建java文件夹,将安装包拖动到/usr/java
  1. Unzip the downloaded jdk
tar -zxvf jdk-8u371-linux-x64.tar.gz 

After successful decompression, you will get the folder jdk1.8.0_371
Insert image description here

  1. Edit the configuration file and configure environment variables
vim /etc/profile   ## 配置环境变量

Add the following to the last line

export JAVA_HOME=/usr/java/jdk1.8.0_371 # (安装jdk的目录,可以先去该目录下使用 pwd 命令查看)
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar

Insert image description here

  1. Refresh configuration file
[root@centos7 java]# source /etc/profile

Restart command: sudo shutdown -r now

  1. Check whether JDK installation is successful
java -version

Insert image description here

You can see that the jdk environment has been successfully installed on linux.

2. Check the jdk installation path in linux

echo $JAVA_HOME ## 能定位JDK的安装路径的前提是配置了环境变量$JAVA_HOME
which java ## 查看jdk的执行路径
whereis java ## 
rpm -qa | grep java ## 如果JDK是源码安装,那么rpm -qa | grep java命令也是定位不到的jdk的安装路径的

2. Install tomcat on Linux

To run tomcat, you need to install jdk first

1. Tomcat installation and configuration process

  1. Download Apache tomcat
    official website: https://tomcat.apache.org/
    Insert image description here
    The file name I downloaded is: apache-tomcat-9.0.74.tar.gz

  2. Upload to server and decompress tomcat

# 放在/usr/src下
tar -zxvf apache-tomcat-9.0.74.tar.gz   # 解压文件

Get the folder apache-tomcat-9.0.74
Insert image description here

  1. Start normally.
    Enter the bin directory of tomcat and ./startup.sh will start normally.
    Insert image description here

2. Open the port for external access, restart the firewall, and view the logs

View log

# 运行/apache-tomcat-9.0.74/logs下的catalina.out 查看
tail -f catalina.out 

Insert image description here
Open port 8080 and restart the firewall

firewall-cmd --add-port=8080/tcp --permanent  # 永久开启8080端口
firewall-cmd --reload # 重启防火墙

3. Modify the default port of tomcat

After opening /tomcat/conf/server.xml
Insert image description here
, modify the port
Insert image description here
Insert image description here
and start tomcat

3. Access through browser in window system

Because the default port of tomcat is 8080, enter http://ip:8080 in the browser and you will see the following interface, indicating success.
Insert image description here

4. If the deployed front end gets 404 as soon as it is refreshed, what is the solution?

Create a new WEB-INF folder under the dist directory and add the web.xml file in it

Insert image description here

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
        http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
        version="3.1" metadata-complete="true">
     <display-name>Router for Tomcat</display-name>
     <error-page>
        <error-code>404</error-code>
        <location>/index.html</location>
    </error-page>
</web-app>

Guess you like

Origin blog.csdn.net/wang13679201813/article/details/130614158