PowerShell Install Tomcat

news2024/9/22 19:46:11

 

Tomcat 前言

Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求。实际上Tomcat是Apache 服务器的扩展,但运行时它是独立运行的,所以当你运行tomcat 时,它实际上作为一个与Apache 独立的进程单独运行的。

Tomcat dowload 

Tomcatdownload
javadownload
Powershell 使用使用参数参考

前提条件

  • 开启wmi,配置网卡,参考 

一键自动化部署Tomcat

  • 最终实现下载java,tomcat,解压java,tomcat,环境变量,创建系统服务,删除软件包,防火墙配置,重启系统验证是否可开机自启动。
  • 端口 8082
powershell-install-tomcat.ps1
<# Powershell Install tomcat
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+  _____                       _____ _          _ _ +
+ |  __ \                     / ____| |        | | |+
+ | |__) |____      _____ _ _| (___ | |__   ___| | |+
+ |  ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | |  | (_) \ V  V /  __/ |  ____) | | | |  __/ | |+
+ |_|   \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++
                                                                                                              
# Powershell Install tomcat
# .\powershell-install-tomcat.ps1
#> 


$drive="c:\"
$tomcat_url="https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.6/bin/"
$tomcat_zip="apache-tomcat-10.1.6-windows-x64.zip"
$tomcat_site="C:\Program Files\"
$tomcat_new="tomcat"
$tomcat_catalogue="apache-tomcat-10.1.6"

$java_url="https://repo.huaweicloud.com/java/jdk/13+33/"
$java_zip="jdk-13_windows-x64_bin.zip"
$java_site="C:\Program Files\"
$java_new="java"
$java_catalogue="jdk-13"
$java_catalogue_mv="jdk"

Write-Host "download java" -ForegroundColor Green
wget -Uri $java_url$java_zip -UseBasicParsing -OutFile $drive$java_zip

Write-Host "download tomcat" -ForegroundColor Green
wget -Uri $tomcat_url$tomcat_zip -UseBasicParsing -OutFile $drive$tomcat_zip

Write-Host "decompression java" -ForegroundColor Green
New-Item -ItemType Directory $java_site\$java_new
Expand-Archive -Path $drive\$java_zip -DestinationPath $java_site$java_new

Write-Host "Rename the java folder name" -ForegroundColor Green
Rename-Item -Path $java_site$java_new\$java_catalogue -NewName $java_catalogue_mv

Write-Host "decompression tomcat" -ForegroundColor Green
Expand-Archive -Path $drive\$tomcat_zip -DestinationPath $tomcat_site

Write-Host "Rename the tomcat folder name" -ForegroundColor Green
Rename-Item -Path $tomcat_site$tomcat_catalogue -NewName $tomcat_new

Write-Host "Create tomcat & java environment variables" -ForegroundColor Green
$env:CATALINA_HOME += "C:\Program Files\tomcat"
setx CATALINA_HOME $env:CATALINA_HOME /M

$env:JAVA_HOME += "C:\Program Files\java\jdk"
setx JAVA_HOME $env:JAVA_HOME /M

$env:JAVA_TOOL_OPTIONS += "-Dfile.encoding=UTF-8"
setx JAVA_TOOL_OPTIONS $env:JAVA_TOOL_OPTIONS /M

$env:path += ";%CATALINA_HOME%\lib"
$env:path += ";%CATALINA_HOME%\bin"
$env:path += ";C:\Program Files\java\jdk\bin"
$env:path += ";C:\Program Files\tomcat\bin"
$env:path += ";%JAVA_HOME%\bin"
setx PATH $env:path /M

Write-Host "java version check" -ForegroundColor Green
java --version

Write-Host "tomcat version check" -ForegroundColor Green
catalina.bat version

Write-Host "Create a tomcat system service" -ForegroundColor Green
startup.bat
service.bat install Tomcat
sc.exe config Tomcat start= auto

Write-Host "firewall tomcat port" -ForegroundColor Green
New-NetFirewallRule -DisplayName "tomcat-out" -Direction Outbound -profile any -LocalPort 8080 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "tomcat-int" -Direction Inbound -profile any -LocalPort 8080 -Protocol TCP -Action Allow

Write-Host "delete java software package" -ForegroundColor Green
Remove-Item $drive$java_zip -recurse

Write-Host "delete tomcat software package" -ForegroundColor Green
Remove-Item $drive$tomcat_zip -recurse

Write-Host "reboot system" -ForegroundColor Green
Restart-Computer

执行安装

.\powershell-install-tomcat.ps1

输出结果

访问http://YOU_IP:8080

  • curl.exe 127.0.0.1:8080

端口更改默认是8082更改成自己需要的端口,以下更改的是8082,复制一下代码到powerShell 下直接执行就可以,只需要更改

  •   <Connector port="8082" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> #更改此段端口信息
shutdown.bat

Write-Host "tomcat server.xml configuration port" -ForegroundColor Green
$functionText_tomcat_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.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!-- APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--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 :
         HTTP Connector: /docs/config/http.html
         AJP  Connector: /docs/config/ajp.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8082" 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 an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         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">
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!--
    <Connector protocol="AJP/1.3"
               address="::1"
               port="8009"
               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>
  </Service>
</Server>
"@

New-Item "$tomcat_site$tomcat_new\$tomcat_conf\$tomcat_xml" -type file -force -value $functionText_tomcat_xml
Restart-Service Tomcat
New-NetFirewallRule -DisplayName "tomcat-out" -Direction Outbound -profile any -LocalPort 8082 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "tomcat-int" -Direction Inbound -profile any -LocalPort 8082 -Protocol TCP -Action Allow

curl 测试是否更改完成

curl.exe 127.0.0.1:8082

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/377422.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

什么是百分比堆积条形图?

条形图实际上范围很广&#xff0c;它是以横置图形展示数据的一种图表类型。百分比堆积条形图即以堆积条形图的形式来显示多个数据序列&#xff0c;但是每个堆积元素的累积比例始终总计为 100%。它主要用于显示一段时间内的多项数据占比情况。 百分比堆叠条形图将多个数据集的条…

C++修炼之练气期一层——命名空间

目录 1.引例 2.命名空间的定义 3.命名空间的使用 4.命名空间使用注意事项 1.引例 #include <stdio.h> #include <stdlib.h>int rand 10;int main() {printf("%d\n", rand);return 0; } 当我们用C语言写下这样的代码&#xff0c;看着并没有什么语法…

Kubernetes06:Controller (Deployment无状态应用)

Kubernetes06:Controller 1、什么是controller 管理和运行容器的对象&#xff0c;是一个物理概念 在集群上管理和运行容器的对象 2、Pod和Controller之间的关系 Pod是通过controller来实现应用的运维 比如伸缩、滚动升级等等操作Pod和Controller之间通过 label 标签建立关系…

thread.join 是干什么的?原理是什么?

Thread.join 加了join&#xff0c;表示join的线程的修改对于join之外的代码是可见的。 代码示例&#xff1a; public class JoinDemo {private static int i 1000;public static void main(String[] args) {new Thread(()->{i 3000;}).start();System.out.println("…

C++学习笔记-异常处理

一个问题是程序在执行期间产生了一个例外。 C异常是一个特殊的情况在程序运行时&#xff0c;比如试图除以零而引致的响应结果。 异常提供一种方法来从一个程序到另一个程序的一个部分转移控制。 C异常处理建立在三个关键字&#xff1a; try, catch,和 throw。 throw: 程序抛出…

72. import 导入标准模块(os模块)

72. import 导入标准模块(os模块) 文章目录72. import 导入标准模块(os模块)1. 标准模块知识回顾2. os 模块的基本介绍3. import 导入标准模块1. 方法12. 方法21. 导包不同2. 声明不同3. 路径不同4. 概括3. 方法34. 方法44. 调用模块或库中的类、函数、变量5. os模块的路径操作…

Git ---- 国内代码托管中心-码云

Git ---- 国内代码托管中心-码云1. 简介2. 码云账号注册和登录3. 码云创建远程仓库4. IDEA 集成码云1. IDEA 安装码云插件2. IDEA 连接码云5. 码云复制 GitHub 项目1. 简介 众所周知&#xff0c;GitHub 服务器在国外&#xff0c;使用 GitHub 作为项目托管网站&#xff0c;如果…

InnoDB数据页结构__盛放记录的大盒子

一、不同类型的页简介 前边我们简单提了一下页的概念&#xff0c;它是InnoDB管理存储空间的基本单位&#xff0c;一个页的大小一般是16KB。InnoDB为了不同的目的而设计了许多种不同类型的页&#xff0c;比如存放空间头部信息的页&#xff0c;存放Insert Buffer信息的页&#xf…

「TCG 规范解读」TCG 软件栈 TSS (上)

可信计算组织(Ttrusted Computing Group,TCG)是一个非盈利的工业标准组织,它的宗旨是加强在相异计算机平台上的计算环境的安全性。TCG于2003年春成立,并采纳了由可信计算平台联盟(the Trusted Computing Platform Alliance,TCPA)所开发的规范。现在的规范都不是最终稿,都…

谈谈XR关键技术及VR/AR/MR/XR关系

一、先别被VR/AR/MR/XR搞晕&#xff0c;说说区别虚拟现实&#xff08;Virtual Reality&#xff0c;VR&#xff09;、增强现实&#xff08;Augmented Reality&#xff0c;AR&#xff09;等业务以其三维化、自然交互、空间计算等完全不同于当前移动互联网的特性&#xff0c;被认为…

Kylin V10桌面版arm3568 源码安装redis

上传redis-5.0.14.tar.gz到/home/kylin/下载&#xff1b;解压kylinkylin:~/下载$ tar -zxvf redis-5.0.14.tar.gz/opt下新建redis目录&#xff0c;并将上面解压的文件夹移到此处kylinkylin:~/下载$ sudo mv redis-5.0.14 /opt/redis/编译&#xff1a;kylinkylin:/opt/redis/red…

ACP、PMP、NPDP含金量哪个高?

在自个的领域而言&#xff0c;知名度、报考人数相对较高&#xff0c;这里我就说下他们的含金量吧。&#xff08;含资料&#xff09; 【ACP】 项目管理相关的证书 1、增加项目管理能力&#xff0c;并且对你拥有的知识与技能起到了很好的证明。不断提高自己的能力&#xff0c;不…

软件测试之场景法

场景法 1. 概述 1.1 为什么使用场景法设计测试用例 大多数业务软件由后台管理&#xff08;比如&#xff1a;用户管理、角色管理、权限管理等等各种管理&#xff09;和工作流等几个部分组成。终端用户&#xff0c;期望软件能够实现业务需求&#xff0c;而不是简单的功能的组合…

webpack热更新原理(面试大概率会问)

搭建webpack环境 创建一个项目 mkdir dev-erver && cd dev-server npm init -y // 快速创建一个项目配置 npm i webpack webpack-dev-server webpack-cli --save-dev mkdir src // 创建资源目录 mkdir dist // 输出目录 touch webpack.dev.js // 因为是在开发环境需要…

三层架构+MVC

前言图 什么是三层架构 什么是三层架构 什么是系统架构 所谓系统架构是指&#xff0c;整合应用系统程序大的结构。经常提到的系统结构有两种&#xff1a;三层架构与MVC。这两种结构既有区别&#xff0c;又有联系。但这两种结构的使用&#xff0c;均是为了降低系统模块间的耦合…

这七个100%提高Python代码性能的技巧,一定要知道

B站|公众号&#xff1a;啥都会一点的研究生 相关阅读 整理了几个100%会踩的Python细节坑&#xff0c;提前防止脑血栓 整理了十个100%提高效率的Python编程技巧&#xff0c;更上一层楼 Python-列表&#xff0c;从基础到进阶用法大总结&#xff0c;进来查漏补缺 Python-元组&…

Web Spider案例 网洛克 第二题 JJEncode加密 练习(六)

文章目录一、资源推荐二、逆向目标三、抓包分析 & 下断分析逆向3.1 抓包分析3.2 下断分析逆向四、本地JS代码调试 & 完整JS加密代码4.1 本地JS代码调试4.2 完整JS加密代码五、python具体实现总结提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参考 …

跬智信息全新推出云原生数据底座玄武,助力国产化数据服务再次升级

2月28日&#xff0c;跬智信息&#xff08;Kyligence&#xff09;宣布全新推出国产化云原生数据底座开源项目玄武&#xff08;XUANWU&#xff09;&#xff0c;以助力企业加速数据平台上云&#xff0c;并实现国产化升级。玄武&#xff08;XUANWU&#xff09;是在容器化技术上形成…

分层测试(2)单元测试【必备】

1. 什么是单元测试&#xff1f; 对代码中的逻辑隔离的最小代码片段进行测试&#xff0c;验证其逻辑是否符合预期&#xff0c;单元可以是函数&#xff0c;方法&#xff0c;类&#xff0c;功能模块。 2. 单元测试的优点 掌握代码&#xff1a;单元测试允许开发人员了解单元提供…

35岁的测试被裁,公司地位还不如00后...

国内的互联网行业发展较快&#xff0c;所以造成了技术研发类员工工作强度比较大&#xff0c;同时技术的快速更新又需要员工不断的学习新的技术。因此淘汰率也比较高&#xff0c;超过35岁的基层研发类员工&#xff0c;往往因为家庭原因、身体原因&#xff0c;比较难以跟得上工作…