tomcat服务器的配置与故障排除

大家好,今天分享tomcat 服务器

Tomcat 服务器是一个免费的开放源代码的Web 应用服务器

这是tomcat官网,点一下就可以了

下面再Windows 环境下,进行安装与配置

我使用的是这个版本:(下载下来之后,需要解压一下)

在这里插入图片描述

打开tomcat。可以看见里面的文件

在这里插入图片描述
bin: 这是运行它的脚本文件
conf : 这是tomcat 的配置文件
lib : 这里是它的jar包
logs : 这里是它的日志文件
webapps:这是存放网站的资源
work : 这里是它的工作文件

在这里提一下,Windows下的tomcat服务,解压之后就可以使用

但是可以会遇见启动时闪退的问题

在这里插入图片描述

点开这个文件

在这里插入图片描述
注意这两个文件

打开startup.bat (下面就是它的启动文件)
在这里插入图片描述

我们需要再这个startup,bat 这个文件当中加上(在这个文件的最前面)

SET JAVA_HOME= C:\Users\Administrator\.jdks\corretto-1.8.0_312(java jdk目录)
SET JRE_HOME=C:\Users\Administrator\.jdks\corretto-1.8.0_312\jre
SET CATALINA_HOME=E:\apache-tomcat-9.0.24-windows-x86\apache-tomcat-9.0.24      #   这是tomcat的安装目录(因各人而异)

截图是这样的
在这里插入图片描述
记得保存

打开shutdown.bat这个文件

在这个文件的第一行加上

SET JAVA_HOME= C:\Users\Administrator\.jdks\corretto-1.8.0_312
SET JRE_HOME=C:\Users\Administrator\.jdks\corretto-1.8.0_312\jre
SET CATALINA_HOME=E:\apache-tomcat-9.0.24-windows-x86\apache-tomcat-9.0.24

记得保存

点击startup.bat这个文件
可以dos窗口会有前台形式的运行进程(这是正常的)

在这里插入图片描述
如果我们刚刚不配置对应的环境变量,这个地方会闪退的

那样会导致启动失败

我们已经成功启动了tomcat 服务器

我们现在使用浏览器访问tomcat服务器 (http://localhost:8080/)
在这里插入图片描述

在我们进行网页访问的时候,startup.bat 文件的前台进程不可以断掉

否则浏览器的访问将出现问题:

这是关掉

在这里插入图片描述

再次运行:

在这里插入图片描述

这样就访问正常

在这里插入图片描述
也可以通过shutdown.bat 这个文件来关闭服务器

在这里插入图片描述

在这里插入图片描述
再次使用startup.bat 这个文件 来启动tomcat服务器

现在可以正常访问

在这里插入图片描述

在这里插入图片描述

这个文件是tomcat服务器非常重要的配置文件

在这里插入图片描述

这就是这个配置文件里所有的东西

<?xml version="1.0" encoding="UTF-8"?>
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
    maxThreads="150" minSpareThreads="4"/>
-->


<!-- A "Connector" represents an endpoint by which requests are received
     and responses are returned. Documentation at :
     Java HTTP Connector: /docs/config/http.html
     Java AJP  Connector: /docs/config/ajp.html
     APR (HTTP/AJP) Connector: /docs/apr.html
     Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
           port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
-->
<!-- Define a 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.Http11NioProtocol"
           maxThreads="150" SSLEnabled="true">
    <SSLHostConfig>
        <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                     type="RSA" />
    </SSLHostConfig>
</Connector>
-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
     This connector uses the APR/native implementation which always uses
     OpenSSL for TLS.
     Either JSSE or OpenSSL style configuration may be used. OpenSSL style
     configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
           maxThreads="150" SSLEnabled="true" >
    <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
    <SSLHostConfig>
        <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                     certificateFile="conf/localhost-rsa-cert.pem"
                     certificateChainFile="conf/localhost-rsa-chain.pem"
                     type="RSA" />
    </SSLHostConfig>
</Connector>
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


<!-- An Engine represents the entry point (within Catalina) that processes
     every request.  The Engine implementation for Tomcat stand alone
     analyzes the HTTP headers included with the request, and passes them
     on to the appropriate Host (virtual host).
     Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">

  <!--For clustering, please take a look at documentation at:
      /docs/cluster-howto.html  (simple how to)
      /docs/config/cluster.html (reference documentation) -->
  <!--
  <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  -->

  <!-- Use the LockOutRealm to prevent attempts to guess user passwords
       via a brute-force attack -->
  <Realm className="org.apache.catalina.realm.LockOutRealm">
    <!-- This Realm uses the UserDatabase configured in the global JNDI
         resources under the key "UserDatabase".  Any edits
         that are performed against this UserDatabase are immediately
         available for use by the Realm.  -->
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
           resourceName="UserDatabase"/>
  </Realm>

  <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>
</Engine>

这是我们默认指定的端口

在这里插入图片描述

这一行要注意一下

在这里插入图片描述

这里有5个web应用,我们要注意ROOT 这个文件

在这里插入图片描述

这就是首页的网页资源

在这里插入图片描述

注意这个文件

在这里插入图片描述

这就是index.jsp 的全部代码:
<%–

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.
--%>
<%@ page session="false" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "https://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");
%>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title><%=request.getServletContext().getServerInfo() %></title>
        <link href="favicon.ico" rel="icon" type="image/x-icon" />
        <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <link href="tomcat.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
        <div id="wrapper">
            <div id="navigation" class="curved container">
                <span id="nav-home"><a href="${tomcatUrl}">Home</a></span>
                <span id="nav-hosts"><a 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

思诚代码块

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值