江西企业 网站建设,技术支持 东莞网站建设,前端静态资源如何部署到cdn上,网站建设与推广协议书tomcat 前言
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器#xff0c;属于轻量级应用服务器#xff0c;在中小型系统和并发访问用户不是很多的场合下被普遍使用#xff0c;是开发和调试JSP 程序的首选。对于一个初学者来说#xff0c;可以这样认为#xff0c;当… tomcat 前言
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器属于轻量级应用服务器在中小型系统和并发访问用户不是很多的场合下被普遍使用是开发和调试JSP 程序的首选。对于一个初学者来说可以这样认为当在一台机器上配置好Apache 服务器可利用它响应HTML标准通用标记语言下的一个应用页面的访问请求。实际上Tomcat是Apache 服务器的扩展但运行时它是独立运行的所以当你运行tomcat 时它实际上作为一个与Apache 独立的进程单独运行的。
java 前言
Java具有大部分编程语言所共有的一些特征被特意设计用于互联网的分布式环境。Java具有类似于C语言的形式和感觉但它要比C语言更易于使用而且在编程时彻底采用了一种以对象为导向的方式。
tomcat java下载
tomcat下载java 下载downloaddownloadLinux 各系统下载使用参考
Red HatRocky Linux Oracle Linux AlmaLinux ubuntususelinuxesxiRHEL标准安装系统安装参考YUM参考 MobaXterm 远程连接工具 Red Hat Enterprise 9.0 文档Kickstart 生成器downloaddownloaddownloaddownloaddownloaddownloaddownload参考参考配置参考download参考Kickstart 版本兼容性安装 tomcatjava 创建安装自动化脚本 实现在线下载tomcatjava解压安装tomcat,java环境变量设置端口更改8082开启(Server Status Manager App,Host Manager 用户名密码admin/admin)删除软件包企业微信机器人通知以下基于Redhat系统tomcat 安装位置 /opt/tomcatjava 安装位置/opt/jdkRedhat 9 functions使用需要执行安装yum install initscripts -y curl https://qyapi.weixin.qq.com/cgi-bin/webhook/send?keyXXXXX #更改自己的企业微信机器人地址 curl -o /etc/yum.repos.d/redhat.repo http://mirrors.aliyun.com/repo/Centos-8.repo #阿里在线repoyum install figlet -y #用于将文字转换为放大艺术字使用figlet Mysql显示
vim /tomcat_java_install.sh #!/bin/sh
# -*- coding: utf-8 -*-
# Author: CIASM
# Date: 2023/04/02!
████████╗ ██████╗ ███╗ ███╗ ██████╗ █████╗ ████████╗
╚══██╔══╝██╔═══██╗████╗ ████║██╔════╝██╔══██╗╚══██╔══╝██║ ██║ ██║██╔████╔██║██║ ███████║ ██║ ██║ ██║ ██║██║╚██╔╝██║██║ ██╔══██║ ██║ ██║ ╚██████╔╝██║ ╚═╝ ██║╚██████╗██║ ██║ ██║ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝
!source /etc/rc.d/init.d/functions#tomcat configuration file
server_xml/opt/tomcat/conf/server.xml
tomcat_user_xml/opt/tomcat/conf/tomcat-users.xml
manager_xml/opt/tomcat/conf/Catalina/localhost/manager.xml
context_xml/opt/tomcat/webapps/host-manager/META-INF/context.xml#Define data path variables
data_downloads/data/downloads
drive/opt/tomcat_urlhttps://dlcdn.apache.org/tomcat/tomcat-10/v10.1.7/bin/
tomcat_gzapache-tomcat-10.1.7.tar.gz
tomcat_catalogueapache-tomcat-10.1.7
tomcat_newtomcat
tomcat_PREFIX/opt/tomcatjava_urlhttps://repo.huaweicloud.com/java/jdk/1333/
java_gzjdk-13_linux-x64_bin.tar.gz
JAVA_PREFIX/opt/jdk
java_cataloguejdk-13
java_catalogue_newjdkfunction install_java (){
if [ ! -d ${JAVA_PREFIX} ];then
yum install net-tools wget -y
mkdir -p $data_downloads
wget -N -P $data_downloads $java_url$java_gz
tar -zxf $data_downloads/$java_gz -C $drive
mv $drive/$java_catalogue $drive/$java_catalogue_newif [ $? -eq 0 ];thensed -i $aexport JAVA_HOME/opt/jdk /etc/profilesed -i $aexport PATH$JAVA_HOME/bin:$PATH:$CATALINA_HOME/bin /etc/profilesource /etc/profilejava -version 21 | tee /var/log/java_version.logaction The java Install Sussess... /bin/trueelseaction The java Install Failed... /bin/false exit 1fielseecho -e \033[31mThe java already Install...\033[0m
fi
}function install_tomcat (){
if [ ! -d ${tomcat_PREFIX} ];then
wget -N -P $data_downloads $tomcat_url$tomcat_gz
tar -zxf $data_downloads/$tomcat_gz -C $drive
mv $drive/$tomcat_catalogue $drive/$tomcat_new
useradd -M -d /opt/tomcat tomcat
chown -R tomcat. /opt/tomcat
chmod x /opt/tomcat/bin/*.shif [ $? -eq 0 ];thensed -i $aexport CATALINA_HOME/opt/tomcat /etc/profilesource /etc/profilerm -rf /opt/tomcat/conf/tomcat-users.xmlrm -rf /opt/tomcat/webapps/host-manager/META-INF/context.xmlrm -rf /opt/tomcat/conf/server.xml/opt/tomcat/bin/version.sh | tee /var/log/tomcat_version.logConfigurin_tomcatmanager_xmlaction The tomcat Install Sussess... /bin/trueelseaction The tomcat Install Failed... /bin/false exit 1fielseecho -e \033[31mThe tomcat already Install...\033[0m
fi
}function Configurin_tomcat (){
cat /usr/lib/systemd/system/tomcat.serviceEOF
[Unit]
DescriptionApache Tomcat Web Application Container
Aftersyslog.target network.target mysqld.service tomcat.keygen.service[Service]
TypeforkingEnvironmentJAVA_HOME/opt/jdk
EnvironmentCATALINA_PID/opt/tomcat/temp/tomcat.pid
EnvironmentCATALINA_HOME/opt/tomcat
EnvironmentCATALINA_BASE/opt/tomcat
EnvironmentCATALINA_OPTS-Xms4096M -Xmx4096M -server -XX:UseParallelGC
EnvironmentJAVA_OPTS-Djava.awt.headlesstrue -Djava.security.egdfile:/dev/./urandomExecStart/opt/tomcat/bin/startup.sh
ExecStop/opt/tomcat/bin/shutdown.shUsertomcat
Grouptomcat
Restartalways[Install]
WantedBymulti-user.target
EOFcat $tomcat_user_xmlEOF
?xml version1.0 encodingUTF-8?
!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis 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 withthe License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.
--
tomcat-users xmlnshttp://tomcat.apache.org/xmlxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://tomcat.apache.org/xml tomcat-users.xsdversion1.0
!--By default, no user is included in the manager-gui role requiredto operate the /manager/html web application. If you wish to use this app,you must define such a user - the username and password are arbitrary.Built-in Tomcat manager roles:- manager-gui - allows access to the HTML GUI and the status pages- manager-script - allows access to the HTTP API and the status pages- manager-jmx - allows access to the JMX proxy and the status pages- manager-status - allows access to the status pages onlyThe users below are wrapped in a comment and are therefore ignored. If youwish to configure one or more of these users for use with the manager webapplication, do not forget to remove the !.. .. that surrounds them. Youwill also need to set the passwords to something appropriate.
--
!--user usernameadmin passwordmust-be-changed rolesmanager-gui/user usernamerobot passwordmust-be-changed rolesmanager-script/
--
!--The sample user and role entries below are intended for use with theexamples web application. They are wrapped in a comment and thus are ignoredwhen reading this file. If you wish to configure these users for use with theexamples web application, do not forget to remove the !.. .. that surroundsthem. You will also need to set the passwords to something appropriate.
--
!--role rolenametomcat/role rolenamerole1/user usernametomcat passwordtomcat rolestomcat/user usernameboth passwordtomcat rolestomcat,role1/user usernamerole1 passwordtomcat rolesrole1/
--user usernameadmin passwordadmin rolesmanager-gui,admin-gui/
/tomcat-users
EOFcat $context_xmlEOF
?xml version1.0 encodingUTF-8?
!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis 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 withthe License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.
--
Context privilegedtrue antiResourceLockingfalsedocBase$catalina.home /webapps/managerCookieProcessor classNameorg.apache.tomcat.util.http.Rfc6265CookieProcessorsameSiteCookiesstrict /Valve classNameorg.apache.catalina.valves.RemoteAddrValveallow^.*$ /Manager sessionAttributeValueClassNameFilterjava\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap/
/Context
EOFcat $server_xmlEOF
?xml version1.0 encodingUTF-8?
!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis 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 withthe License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.
--
!-- Note: A Server is not itself a Container, so you may notdefine subcomponents such as Valves at this level.Documentation at /docs/config/server.html--
Server port8005 shutdownSHUTDOWNListener classNameorg.apache.catalina.startup.VersionLoggerListener /!-- Security listener. Documentation at /docs/config/listeners.htmlListener classNameorg.apache.catalina.security.SecurityListener /--!-- APR library loader. Documentation at /docs/apr.html --Listener classNameorg.apache.catalina.core.AprLifecycleListener SSLEngineon /!-- Prevent memory leaks due to use of particular java/javax APIs--Listener classNameorg.apache.catalina.core.JreMemoryLeakPreventionListener /Listener classNameorg.apache.catalina.mbeans.GlobalResourcesLifecycleListener /Listener classNameorg.apache.catalina.core.ThreadLocalLeakPreventionListener /!-- Global JNDI resourcesDocumentation at /docs/jndi-resources-howto.html--GlobalNamingResources!-- Editable user database that can also be used byUserDatabaseRealm to authenticate users--Resource nameUserDatabase authContainertypeorg.apache.catalina.UserDatabasedescriptionUser database that can be updated and savedfactoryorg.apache.catalina.users.MemoryUserDatabaseFactorypathnameconf/tomcat-users.xml //GlobalNamingResources!-- A Service is a collection of one or more Connectors that sharea 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 nameCatalina!--The connectors can use a shared executor, you can define one or more named thread pools--!--Executor nametomcatThreadPool namePrefixcatalina-exec-maxThreads150 minSpareThreads4/--!-- A Connector represents an endpoint by which requests are receivedand responses are returned. Documentation at :HTTP Connector: /docs/config/http.htmlAJP Connector: /docs/config/ajp.htmlDefine a non-SSL/TLS HTTP/1.1 Connector on port 8080--Connector port8082 protocolHTTP/1.1connectionTimeout20000redirectPort8443 /!-- A Connector using the shared thread pool--!--Connector executortomcatThreadPoolport8080 protocolHTTP/1.1connectionTimeout20000redirectPort8443 /--!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2This connector uses the NIO implementation. The defaultSSLImplementation will depend on the presence of the APR/nativelibrary and the useOpenSSL attribute of the AprLifecycleListener.Either JSSE or OpenSSL style configuration may be used regardless ofthe SSLImplementation selected. JSSE style configuration is used below.--!--Connector port8443 protocolorg.apache.coyote.http11.Http11NioProtocolmaxThreads150 SSLEnabledtrueUpgradeProtocol classNameorg.apache.coyote.http2.Http2Protocol /SSLHostConfigCertificate certificateKeystoreFileconf/localhost-rsa.jkstypeRSA //SSLHostConfig/Connector--!-- Define an AJP 1.3 Connector on port 8009 --!--Connector protocolAJP/1.3address::1port8009redirectPort8443 /--!-- An Engine represents the entry point (within Catalina) that processesevery request. The Engine implementation for Tomcat stand aloneanalyzes the HTTP headers included with the request, and passes themon to the appropriate Host (virtual host).Documentation at /docs/config/engine.html --!-- You should set jvmRoute to support load-balancing via AJP ie :Engine nameCatalina defaultHostlocalhost jvmRoutejvm1--Engine nameCatalina defaultHostlocalhost!--For clustering, please take a look at documentation at:/docs/cluster-howto.html (simple how to)/docs/config/cluster.html (reference documentation) --!--Cluster classNameorg.apache.catalina.ha.tcp.SimpleTcpCluster/--!-- Use the LockOutRealm to prevent attempts to guess user passwordsvia a brute-force attack --Realm classNameorg.apache.catalina.realm.LockOutRealm!-- This Realm uses the UserDatabase configured in the global JNDIresources under the key UserDatabase. Any editsthat are performed against this UserDatabase are immediatelyavailable for use by the Realm. --Realm classNameorg.apache.catalina.realm.UserDatabaseRealmresourceNameUserDatabase//RealmHost namelocalhost appBasewebappsunpackWARstrue autoDeploytrue!-- SingleSignOn valve, share authentication between web applicationsDocumentation at: /docs/config/valve.html --!--Valve classNameorg.apache.catalina.authenticator.SingleSignOn /--!-- Access log processes all example.Documentation at: /docs/config/valve.htmlNote: The pattern used is equivalent to using patterncommon --Valve classNameorg.apache.catalina.valves.AccessLogValve directorylogsprefixlocalhost_access_log suffix.txtpattern%h %l %u %t quot;%rquot; %s %b //Host/Engine/Service
/Server
EOFsystemctl daemon-reload systemctl enable --now tomcat
firewall-cmd --zonepublic --add-port8082/tcp --permanent firewall-cmd --reload
}function manager_xml (){
cat $manager_xmlEOF
?xml version1.0 encodingUTF-8?
!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis 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 withthe License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.
--
Context privilegedtrue antiResourceLockingfalsedocBase$catalina.home /webapps/managerCookieProcessor classNameorg.apache.tomcat.util.http.Rfc6265CookieProcessorsameSiteCookiesstrict /Valve classNameorg.apache.catalina.valves.RemoteAddrValveallow^.*$ /Manager sessionAttributeValueClassNameFilterjava\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap/
/Context
EOFsystemctl restart tomcat
rm -rf $data_downloads/*
}function Deployment_completion_notification (){host_IDdmidecode -s system-serial-number | sed -r s/\s//ghost_IPifconfig -a | grep inet | grep -v 127.0.0.1 | awk { print $2} | awk NR1memory_Sizedmidecode -t memory | grep Size | grep -v No | awk {sum$2} END {printf %.0fG\n,sum/1^C4}CPU_Modelcat /proc/cpuinfo | grep model name | awk {print $6} | uniqDisk_sizefdisk -l | grep sda: | awk {print $3$4}redhat_versioncat /etc/redhat-release | grep release | awk {print $6}redhat_corecat /proc/version | grep version | awk {print $3}tomcat_versioncat /var/log/tomcat_version.log | grep Server version | awk {print $4}tomcat_serversystemctl status tomcat | grep Active | awk {print $2}java_versioncat /var/log/java_version.log | sed -e s///g | grep java version | awk {print $3}curl https://qyapi.weixin.qq.com/cgi-bin/webhook/send?keyXXXX \-H Content-Type: application/json \-d {msgtype: markdown,markdown: {content: **system check** font color\info\ complete /font \n **Host IP Address** \n[http://$host_IP](http://$host_IP) \n **Hardware information** \nhostSN:font color\info\ $host_ID /font \nCPU_Model:font color\info\ $CPU_Model /font \nmemory_Size:font color\info\ $memory_Size /font \nDisk_size:font color\info\ $Disk_size /font \nSystem_version:font color\info\ $redhat_version /font \nsystem_core:font color\info\ $redhat_core /font \n **tomcat install** \ntomcat_server:font color\info\ $tomcat_server /font \ntomcat_version:font color\info\ $tomcat_version /font \njava_server:font color\info\ $java_version /font \n,}}
}function main (){
install_java
install_tomcat
Deployment_completion_notification
}main 执行安装
sh /tomcat_java_install.sh
企业微信机器人提醒 访问 http://Ip:8082 Server Status
用户名密码admin/adminManager App
用户名密码admin/adminHost Manager
用户名密码admin/admin