首页 > 其他分享 >Tomcat

Tomcat

时间:2022-09-27 18:55:30浏览次数:51  
标签:xml Tomcat tomcat root 访问 usr local


目录

简介

  Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求。实际上Tomcat是Apache 服务器的扩展,但运行时它是独立运行的,所以当你运行tomcat 时,它实际上作为一个与Apache 独立的进程单独运行的。
  Tomcat是一个免费的开源的Serlvet容器,用来运行java程序的容器
是开发和调试Servlet(Server Applet)、JSP(Java Server Pages) 程序的首选;
  Tomcat就是传说中的中间件之一,tomcat本身是一个容器,专门用来运行java程序,java语言开发的网页.jsp就应该运行于tomcat中,而tomcat本身的运行也依赖于jdk环境。

常见的中间件:
一般本地开发的话,小项目,或者是个人开发建议使用tomcat;
linux系统建议使用jetty或apache hpppd;
大型的项目就用JBOSS或webloigc;
大项目或者商业项目一般采用:weblgoic/webshere,其他的还有jboss、glasshfish等;
一些示例项目或者小项目常采用jetty;
tomcat , jboss, weblogic, websphere 一般项目tomcat就可以了。

部署tomcat

//关闭防火墙和selinux
[root@tomcat ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@tomcat ~]# setenforce 0
[root@tomcat ~]# systemctl disable --now firewalld.service

//安装java
[root@tomcat ~]# yum -y install java-11-openjdk

//解压tomcat到/usr/local/目录下
[root@tomcat ~]# wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.23/bin/apache-tomcat-10.0.23.tar.gz
[root@tomcat ~]# tar -xf apache-tomcat-10.0.23.tar.gz -C /usr/local/
[root@tomcat ~]# cd /usr/local/
[root@tomcat local]# ln -s apache-tomcat-10.0.23/ tomcat

//自定义一个Hello World的 java的测试网页
[root@tomcat local]# mkdir /usr/local/tomcat/webapps/test
[root@tomcat local]# cd /usr/local/tomcat/webapps/test/
[root@tomcat test]# vim index.jsp
[root@tomcat test]# cat index.jsp 
<html>
<head>
	<title>test page</title>
</head>
<body>
	<%
		out.println("Hello World");
	%>
</body>
</html>

//启动tomcat
[root@tomcat test]# cd /usr/local/tomcat/
[root@tomcat tomcat]# bin/startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@tomcat tomcat]# ss -anlt
State   Recv-Q  Send-Q        Local Address:Port   Peer Address:Port Process 
LISTEN  0       128                 0.0.0.0:22          0.0.0.0:*            
LISTEN  0       128                    [::]:22             [::]:*            
LISTEN  0       1        [::ffff:127.0.0.1]:8005              *:*            
LISTEN  0       100                       *:8080              *:*            

//测试访问
访问tomcat首页:http://192.168.26.138:8080

访问hello world测试页:http://192.168.26.138:8080/test

访问Host Manager界面

//配置tomcat-users.xml文件,在</tomcat-users>行上面添加两行,设置角色,登录用户名和密码,角色名称只能是admin-gui  用户名和密码自定义
[root@tomcat tomcat]# vim /usr/local/tomcat/conf/tomcat-users.xml 
<role rolename="admin-gui"/>
<user username="tomcat" password="123456" roles="admin-gui"/>
</tomcat-users>

//配置host-manager/META-INF/context.xml文件,允许192.168.26.0/24网段访问,在allow字段后添加
[root@tomcat tomcat]# vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml 
[root@tomcat tomcat]# cat /usr/local/tomcat/webapps/host-manager/META-INF/context.xml 
<?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.
-->
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="192\.168\.26\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>


//重启服务,先关服务,再启服务
[root@tomcat tomcat]# /usr/local/tomcat/bin/catalina.sh stop
[root@tomcat tomcat]# /usr/local/tomcat/bin/catalina.sh start

//登录网页测试登录Host Manager  输入对应的用户名和密码
用户名为tomcat,密码为123456

访问Server Status界面

//编辑tomcat-users.xml
[root@tomcat tomcat]# vim /usr/local/tomcat/conf/tomcat-users.xml 
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="123456" roles="admin-gui,manager-gui"/>
</tomcat-users>
 

//编辑manager/META-INF/context.xml,在allow字段添加允许192.168.26.0/24网段访问
[root@tomcat tomcat]# vim /usr/local/tomcat/webapps/manager/META-INF/context.xml 
[root@tomcat tomcat]# cat /usr/local/tomcat/webapps/manager/META-INF/context.xml 
<?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.
-->
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="192\.168\.26\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

//重启服务,先关服务,再启服务
[root@tomcat tomcat]# /usr/local/tomcat/bin/catalina.sh stop
[root@tomcat tomcat]# /usr/local/tomcat/bin/catalina.sh start

//登录网页,访问Server Status,用户名tomcat  密码123456
//访问Manager App的时候就不需要密码了,因为访问了Server Status界面,所以不用输入密码

标签:xml,Tomcat,tomcat,root,访问,usr,local
From: https://www.cnblogs.com/z696/p/16735575.html

相关文章

  • Tomcat 执行 startup.bat 出现乱码
    中文乱码中文乱码一定是编码方式不一致导致的,并且不会影响服务的启动!那么为什么还要修改呢?因为,强迫症!!! 解决方法修改logging.properties文件(D:\ProgramFiles(x8......
  • tomcat 配置https (单向认证)
    1.单向认证,就是传输的数据加密过了,但是不会校验客户端的来源2.双向认证,如果客户端浏览器没有导入客户端证书,是访问不了web系统的,找不到地址如果只是加密,单向就行如果想要......
  • Tomcat10升级后启动报错
    10的版本更新导致原有的jar不兼容官方给出了更新工具https://tomcat.apache.org/download-migration.cgi直接下载到本地解压打开lib文件夹,将要升级的war包放到该目录......
  • 第十九章 Centos7下Docker安装Tomcat
    一、查找Tomcat镜像[root@staging~]#dockersearchtomcat二、拉取Tomcat镜像[root@staging~]#dockerpulltomcat三、运行Tomcat#在/root目录下创建tomcat......
  • tomcat 访问日志转json
    一、安装jdk、tomcatcat install_tomcat.sh #!/bin/bashJDK_FILE="jdk-8u341-linux-x64.tar.gz"#JDK_FILE="jdk-8u281-linux-x64.tar.gz"TOMCAT_FILE="apache-tomc......
  • tomcat官网查找旧版本
    1、进入tongcat官网2、点击边栏的 3、这里有各种版本总包 4、这里有版本的细分 5、 6、找到适合自己的包 ......
  • Windows配置tomcat环境
    Tomcat(Catalina):WEB服务器(实现了JAVAEE中Servlet+JSP两个核心规范)一、官网下载安装包:https://tomcat.apache.org/二、使用下载好的安装包(apache-tomcat.zip)直接解压到文件......
  • tomcat连接池的“bug”
    Tomcat连接池是从Tomcat7开始重新编写的高并发连接池,用以取代以前Tomcat中使用的DBCP1连接池,它可以配置在Tomcat中使用,也可以单独使用。 【注意的地方】:在w......
  • tomcat webapp下的图片txt无法访问
     找到配置文件如下conf/web.xml-->tomcat的Web配置文件<Hostname="localhost"appBase="webapps" unpackWARs="true"autoDeploy="true"><ContextdocBase="E:\To......
  • Mac配置Tomcat详细版[转]
    Mac下安装Tomcat简单实用教程(实测已安装完成)1.先搜索Tomcat找到它的官网,正常在第一个:2.点击进入网站,如果进不去换个浏览器进行,下载Zip包:3.在Filder的当前用户下新建一......