首页 > 编程语言 >Tomcat与JavaWeb开发

Tomcat与JavaWeb开发

时间:2023-08-24 22:12:48浏览次数:57  
标签:opt bin Aug JavaWeb tomcat 22 开发 Tomcat root

安装Tomcat&JDK

安装时候选择tomcat软件版本要与程序开发使用的版本一致。jdk版本要进行与tomcat保持一致。

准备2个linux虚拟机,
一个运行nginx进行负载均衡
一个用来运行tomcat

第一步:安装JDK

JDK官网地址:
https://www.oracle.com/java/technologies/downloads/
##下载JDK软件包并解压缩
https://download.oracle.com/java/20/latest/jdk-20_linux-x64_bin.tar.gz
[root@tomcat ~]# ls
2023             jdk-20_linux-x64_bin.tar.gz  nginx-1.22.1.tar.gz  nginx-1.23.4.tar.gz
anaconda-ks.cfg  nginx-1.22.1                 nginx-1.23.4
[root@tomcat ~]# mkdir /opt/jdk
[root@tomcat ~]# tar -zxvf jdk-20_linux-x64_bin.tar.gz -O /opt/
[root@tomcat ~]# cd /opt/
[root@tomcat opt]# ls
jdk-20.0.2  nginx  rh  website
##创建软连接
[root@tomcat jdk-20.0.2]# ln -s /opt/jdk-20.0.2/ /opt/jdk
##配置JAVA环境变量,进入/etc/profile增加如下信息
[root@tomcat ~]# sed -i.ori '$a export JAVA_HOME=/opt/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profile
[root@tomcat ~]# tail -3 /etc/profile
export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
##读取/etc/profile环境配置
[root@tomcat ~]# source /etc/profile
[root@tomcat ~]# echo $PATH
/opt/jdk/bin:/opt/jdk/jre/bin:/home/Nginx-1.23.4/sbin:/op/bin:/op/jre/bin:/home/Nginx-1.23.4/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/binnexport
## JDK配置检查
[root@tomcat ~]# java -version
java version "20.0.2" 2023-07-18
Java(TM) SE Runtime Environment (build 20.0.2+9-78)
Java HotSpot(TM) 64-Bit Server VM (build 20.0.2+9-78, mixed mode, sharing)

第二步:部署Tomcat

##下载tomcat软件包并解压缩
[root@tomcat ~]# tar -zxvf apache-tomcat-10.1.12.tar.gz -C /opt/
[root@tomcat ~]# cd /opt/
[root@tomcat opt]# ls
apache-tomcat-10.1.12  jdk  jdk-20.0.2  nginx  rh  website
[root@tomcat opt]# ln -s apache-tomcat-10.1.12/ /opt/tomcat
##设置环境变量
[root@tomcat bin]# sed -i.ori.backup '$a TOMCAT=/opt/tomcat' /etc/profile
[root@tomcat bin]# tail -1 /etc/profile
TOMCAT=/opt/tomcat
[root@tomcat bin]# source /etc/profile
##部分页面在初始化后是无法访问的,增加对应的权限
[root@tomcat bin]# ll /opt/jdk/ /opt/tomcat/
/opt/jdk/:
total 24
drwxr-xr-x  2 root  root  4096 Aug 22 01:16 bin
drwxr-xr-x  5 root  root   123 Aug 22 01:16 conf
drwxr-xr-x  3 root  root   132 Aug 22 01:16 include
drwxr-xr-x  2 root  root  4096 Aug 22 01:16 jmods
drwxr-xr-x 72 root  root  4096 Aug 22 01:16 legal
drwxr-xr-x  5 root  root  4096 Aug 22 01:16 lib
lrwxrwxrwx  1 10668 10668   23 Jun 14 06:22 LICENSE -> legal/java.base/LICENSE
drwxr-xr-x  3 root  root    18 Aug 22 01:16 man
-rw-r--r--  1 10668 10668  290 Jun 14 06:22 README
-rw-r--r--  1 10668 10668 1269 Jun 14 06:22 release

/opt/tomcat/:
total 128
drwxr-x--- 2 root root  4096 Aug 22 01:58 bin
-rw-r----- 1 root root 20123 Aug  8 15:16 BUILDING.txt
drwx------ 2 root root   238 Aug  8 15:16 conf
-rw-r----- 1 root root  6210 Aug  8 15:16 CONTRIBUTING.md
drwxr-x--- 2 root root  4096 Aug 22 01:58 lib
-rw-r----- 1 root root 60393 Aug  8 15:16 LICENSE
drwxr-x--- 2 root root     6 Aug  8 15:16 logs
-rw-r----- 1 root root  2333 Aug  8 15:16 NOTICE
-rw-r----- 1 root root  3398 Aug  8 15:16 README.md
-rw-r----- 1 root root  6776 Aug  8 15:16 RELEASE-NOTES
-rw-r----- 1 root root 16076 Aug  8 15:16 RUNNING.txt
drwxr-x--- 2 root root    30 Aug 22 01:58 temp
drwxr-x--- 7 root root    81 Aug  8 15:16 webapps
drwxr-x--- 2 root root     6 Aug  8 15:16 work
##检查tomcat是否正确安装
[root@tomcat bin]# /opt/tomcat/bin/version.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /opt/jdk
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Server version: Apache Tomcat/10.1.12
Server built:   Aug 8 2023 19:16:13 UTC
Server number:  10.1.12.0
OS Name:        Linux
OS Version:     3.10.0-1160.el7.x86_64
Architecture:   amd64
JVM Version:    20.0.2+9-78
JVM Vendor:     Oracle Corporation

Tomcat目录介绍

[root@tomcat ~]# tree /opt/tomcat/ -L 1
/opt/tomcat/
├── bin     # 存放tomcat管理脚本
├── BUILDING.txt
├── conf    # tomcat 配置文件存放目录
├── CONTRIBUTING.md
├── lib    # web应用调用的jar包存放路径
├── LICENSE
├── logs    # tomcat 日志存放目录,catalina.out 为主要输出日志
├── NOTICE
├── README.md
├── RELEASE-NOTES
├── RUNNING.txt
├── temp    # 存放临时文件
├── webapps    # web程序存放目录
└── work    # 存放编译产生的.java 与 .class文件

webapps目录介绍

[root@tomcat ~]# tree  /opt/tomcat/webapps/ -L 1
/opt/tomcat/webapps/
├── docs    # tomcat 帮助文档
├── examples    # web应用实例
├── host-manager    # 主机管理
├── manager    # 管理
└── ROOT    # 默认站点根目录

Tomcat配置文件

[root@tomcat ~]# tree /opt/tomcat/conf/
/opt/tomcat/conf/
├── catalina.policy
├── catalina.properties
├── context.xml
├── jaspic-providers.xml
├── jaspic-providers.xsd
├── logging.properties
├── server.xml    # tomcat主配置
├── tomcat-users.xml    # tomcat管理用户配置
├── tomcat-users.xsd
└── web.xml

Tomcat启停管理

[root@tomcat ~]# /opt/tomcat/bin/startup.sh 
[root@tomcat ~]# /opt/tomcat/bin/shutdown.sh 

启动tomcat访问

[root@tomcat ~]# /opt/tomcat/bin/startup.sh 
Using CATALINA_BASE:   /opt/tomcat
Using CATALINA_HOME:   /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME:        /opt/jdk
Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@tomcat ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      690/rpcbind         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      962/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1124/master         
tcp6       0      0 :::111                  :::*                    LISTEN      690/rpcbind         
tcp6       0      0 :::8080                 :::*                    LISTEN      1725/java           
tcp6       0      0 :::21                   :::*                    LISTEN      971/vsftpd          
tcp6       0      0 :::22                   :::*                    LISTEN      962/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1124/master         
udp        0      0 0.0.0.0:111             0.0.0.0:*                           690/rpcbind         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           700/chronyd         
udp        0      0 0.0.0.0:846             0.0.0.0:*                           690/rpcbind         
udp6       0      0 :::111                  :::*                                690/rpcbind         
udp6       0      0 ::1:323                 :::*                                700/chronyd         
udp6       0      0 :::846                  :::*                                690/rpcbind 

 检查日志

[root@tomcat ~]# tail -f /opt/tomcat/logs/catalina.out 
22-Aug-2023 02:23:45.294 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-10.1.12/webapps/docs]
22-Aug-2023 02:23:45.319 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-10.1.12/webapps/docs] has finished in [25] ms
22-Aug-2023 02:23:45.319 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-10.1.12/webapps/examples]
22-Aug-2023 02:23:45.619 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-10.1.12/webapps/examples] has finished in [300] ms
22-Aug-2023 02:23:45.620 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-10.1.12/webapps/host-manager]
22-Aug-2023 02:23:45.636 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-10.1.12/webapps/host-manager] has finished in [16] ms
22-Aug-2023 02:23:45.636 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-10.1.12/webapps/manager]
22-Aug-2023 02:23:45.661 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-10.1.12/webapps/manager] has finished in [25] ms
22-Aug-2023 02:23:45.678 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
22-Aug-2023 02:23:45.748 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [912] milliseconds

管理页面入口:默认无法访问,需要在conf/tomcat-user.xml添加标签,$CATALINA_HOME/webapps/manager/META-INF/context.xml 和$CATALINA_HOME/webapps/host-manager/META-INF/context.xml 这两个文件,全部修改 RemoteAddrValve 的值:

服务状态页面(Server Status)、管理登录(Manager App)修改如下内容:

##修改管理登录的web页面,允许所有主机访问
[root@tomcat ~]# cat /opt/tomcat/webapps/manager/META-INF/context.xml <Context antiResourceLocking="false" privileged="true" > <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" sameSiteCookies="strict" /> <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|\d+\.\d+\.\d+\.\d+" /> ##添加|\d+\.\d+\.\d+\.\d+表示允许所有主机访问 <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>

##/conf/tomcat-users.xml 添加管理用户登录的标签(用户名、密码)
[root@tomcat ~]# cat /opt/tomcat/conf/tomcat-users.xml
 <role rolename="manager"/>  
  <role rolename="manager-gui"/>   
  <role rolename="manager-jmx"/>  
  <role rolename="manager-status"/>  
  <role rolename="manager-script"/>  
  <user username="admin" password="admin" roles="manager,manager-gui,manager-jmx,manager-status,manager-script"/>

查看Server Status服务器状态

 查看管理者页面

 主机管理者页面(host-manager):

##修改/webapps/host-manager/META-INF/context.xml,允许所有主机访问
[root@tomcat ~]# cat /opt/tomcat/webapps/host-manager/META-INF/context.xml 
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|\d+\.\d+\.\d+\.\d+" />    ##添加|\d+\.\d+\.\d+\.\d+
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

##添加登录host-manager的用户名、密码
  <role rolename="admin-gui"/>
  <role rolename="admin-script"/>
  <user username="tomcat" password="123456" roles="admin-gui,admin-script"/>

 

标签:opt,bin,Aug,JavaWeb,tomcat,22,开发,Tomcat,root
From: https://www.cnblogs.com/junwured/p/17648478.html

相关文章

  • Python全栈开发从入门到入土
    Python全栈开发从入门到入土持续更新中~~~希望大家多多支持!【Python基础从入坑到放弃】【一】Python基础入门【一】计算机基础编程语言的介绍什么是语言什么是编程语言为什么会出现编程语言什么是编程为什么要有编程计算机组成原理计算机的五大组成部分......
  • Apipost:提升API开发效率的利器
    在数字化时代,API已经成为企业和开发者实现业务互通的关键工具。然而,API的开发、调试、文档编写以及测试等工作繁琐且复杂。Apipost为这一问题提供了完美的解决方案。Apipost是一款专为API开发人员设计的协同研发平台,旨在简化API的生命周期管理。Apipost提供了丰富的功能,让开发人......
  • 米尔基于瑞萨RZ/G2L开发板在工控领域的应用-基于SOEM的EtherCAT主站
    本篇测评由优秀测评者“qinyunti”提供。前言本文介绍【米尔MYD-YG2LX开发板】在工控领域的应用,实现基于SOEM的EtherCAT主站。开发环境基于WSL2。 下载代码gitclone ‍https://github.com/OpenEtherCATsociety/SOEM‍ PC端编译cdSOEM/exportCC=gccmkdirbuild_pcc......
  • 迅为RK3568开发板GPIO之外接模块
     在迅为RK3568开发板上有一组GPIO,可以用来外接各种外设模块,从面实现一系列好玩的功能,一起来看看各个模块合集吧    RFID模块:工作电流:13—20mA/直流3.3V空闲电流:10-13mA/直流3.3V休眠电流:<80UA峰值电流:<30mA工作频率:13.56MHz支持的卡类型:mifare1 S50.mifare1 S70.mif......
  • iOS开发Swift-控制流
    1.For-In循环//集合循环letnames=["a","b","c"]fornameinnames{print("Hello,\(name)!")}//次数循环forindexin1...5{print("Hello!+\(index)")}//不需要值时可以使用_来忽略此值for_in1...5{pri......
  • 搭建CAD二次开发
    1.AutoCad下载地址AutoCad201632位:https://pan.baidu.com/s/1JFZxqnyUQ3Pxh2hX_ClRKQ?pwd=wkfmAutoCad201664位:https://pan.baidu.com/s/1MRmtp6wcu7zjc-9zPstgFg?pwd=c4fjVisualStudio2015下载地址链接:https://pan.baidu.com/s/1uE_Fc4P2LEwPeK6QtAvg3Q?pwd=691e2.新......
  • java开发中常见的String对象
    String对象加载场内存方式有两种,一种是直接使用“”号创建的加载内存时会会把该字符串直接加载到字符常量中去,并且后文中出现相同使用“”号定义的常量时不会再在内存中创建直接使用第一次创建的字符串,另一种直接使用构造器创建的会创建出一个新的字符串,String常见构造器有String(b......
  • 微信开发之一键发布群公告的技术实现
    简要描述:设置群公告请求URL:http://域名地址/setChatRoomAnnouncement请求方式:POST请求头Headers:Content-Type:application/jsonAuthorization:login接口返回参数:参数名必选类型说明wId是String登录实例标识chatRoomId是String群号content是St......
  • Electron,VUEJS3,Vite,TypesSript 开发环境配置
    Electron,VUEJS3,Vite,TypesSript开发环境配置项目早期是vue3+vite开发的,后期由于运营需求,要修改为Win安装包。方案还是比较多的:1.WPF-Webview由于目前只需要兼容win,所以可以选择WPF,但WPF需要WebView的,还需要本地架设服务。整体部署比较复杂以及需要熟悉C#与WPF相关开发。2.......
  • Android开发 Jetpack Compose 动画
    前言  此篇博客讲解JetpackCompose的动画实现  官网地址:https://developer.android.google.cn/jetpack/compose/animation?hl=zh-cn AnimatedVisibility-隐藏显示动画默认效果效果图代码@ComposablefunAPage(){valimageVisible=remember{mu......