时间:2023-07-15 04:54:01 | 来源:网站运营
时间:2023-07-15 04:54:01 来源:网站运营
Tomcat详解以及安装使用:[root@localhost ~]# tar xzf jdk-8u211-linux-x64.tar.gz -C /usr/local/[root@localhost ~]# cd /usr/local/[root@localhost local]# mv jdk1.8.0_211/ java #改名字设置环境变量:[root@localhost local]# vim /etc/profile在末尾添加以下参数export JAVA_HOME=/usr/local/java #指定java安装目录export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH #用于指定java系统查找命令的路径export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar #类的路径,在编译运行java程序时,如果有调用到其他类的时候,在classpath中寻找需要的类。检测JDK是否安装成功:[root@localhost local]# source /etc/profile #使配置文件生效[root@localhost local]# java -versionjava version "1.8.0_211"Java(TM) SE Runtime Environment (build 1.8.0_211-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
安装Tomcat[root@localhost ~]# mkdir /data/application -p[root@localhost ~]# cd /usr/src/[root@localhost ~]# yum -y install wget[root@localhost src]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.46/bin/apache-tomcat-8.5.46.tar.gz[root@localhost src]# tar xzf apache-tomcat-8.5.46.tar.gz -C /data/application/[root@localhost src]# cd /data/application/[root@localhost application]# mv apache-tomcat-8.5.46/ tomcat设置环境变量:[root@localhost application]# vim /etc/profileexport TOMCAT_HOME=/data/application/tomcat #指定tomcat的安装目录[root@localhost application]# source /etc/profile查看tomcat是否安装成功:[root@localhost tomcat]# /data/application/tomcat/bin/version.shUsing CATALINA_BASE: /data/application/tomcatUsing CATALINA_HOME: /data/application/tomcatUsing CATALINA_TMPDIR: /data/application/tomcat/tempUsing JRE_HOME: /usr/local/javaUsing CLASSPATH: /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jarServer version: Apache Tomcat/8.5.45Server built: Aug 14 2019 22:21:25 UTCServer number: 8.5.45.0OS Name: LinuxOS Version: 3.10.0-693.el7.x86_64Architecture: amd64JVM Version: 1.8.0_211-b12JVM Vendor: Oracle Corporation
[root@localhost ~]# cd /data/application/tomcat/[root@localhost tomcat]# lsbin conf lib logs README.md RUNNING.txt webappsBUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work[root@localhost tomcat]# yum -y install tree[root@localhost tomcat]# tree -L 1 #1 表示当前目录下第一层目录和文件.├── bin #存放tomcat的管理脚本├── BUILDING.txt├── conf #tomcat的配置文件├── CONTRIBUTING.md├── lib #web应用调用的jar包存放路径├── LICENSE├── logs #tomcat日志存放目录,catalin.out日志为只要输出日志├── NOTICE├── README.md├── RELEASE-NOTES├── RUNNING.txt├── temp #存放临时文件├── webapps #默认网站发布目录└── work #存放编译生产的.java与.class文件7 directories, 7 files
2.webapps目录介绍[root@localhost tomcat]# cd webapps/[root@localhost webapps]# tree -L 1.├── docs #tomcat的帮助文档├── examples #web应用实例├── host-manager #主机管理├── manager #管理└── ROOT #默认站点根目录5 directories, 0 files
3.Tomcat配置文件目录介绍(conf)[root@localhost webapps]# cd ../conf/[root@localhost conf]# tree -L 1.├── Catalina├── catalina.policy├── catalina.properties├── context.xml├── logging.properties├── logs├── server.xml # tomcat 主配置文件├── server.xml.bak├── server.xml.bak2├── tomcat-users.xml # tomcat 管理用户配置文件├── tomcat-users.xsd└── web.xml2 directories, 10 files
4.Tomcat的启动关闭以及端口启动程序 #/data/application/tomcat/bin/startup.sh关闭程序 #/data/application/tomcat/bin/shutdown.sh当然如果你先麻烦可以设置软连接[root@localhost webapps]# ln -s /data/application/tomcat/bin/startup.sh /usr/sbin/tomcatstart[root@localhost webapps]# ln -s /data/application/tomcat/bin/shutdown.sh /usr/sbin/tomcatstop[root@localhost webapps]# tomcatstartUsing CATALINA_BASE: /data/application/tomcatUsing CATALINA_HOME: /data/application/tomcatUsing CATALINA_TMPDIR: /data/application/tomcat/tempUsing JRE_HOME: /usr/local/javaUsing CLASSPATH: /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jarTomcat started.[root@localhost webapps]# tomcatstopUsing CATALINA_BASE: /data/application/tomcatUsing CATALINA_HOME: /data/application/tomcatUsing CATALINA_TMPDIR: /data/application/tomcat/tempUsing JRE_HOME: /usr/local/javaUsing CLASSPATH: /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jar
注意:tomcat未启动的情况下使用shutdown脚本,会有大量的输出信息。端口:[root@localhost ~]#tomcatstart; tail -f /data/application/tomcat/logs/catalina.out #启动并查看日志
<server> #表示一个运行于JVM中的tomcat实例。 <service> #服务。将connector关联至engine,因此一个service内部可以有多个connector,但只能有一个引擎engine。 <connector /> #接收用户请求,类似于httpd的listen配置监听端口的 <engine> #核心容器组件,catalina引擎,负责通过connector接收用户请求,并处理请求,将请求转至对应的虚拟主机host。 <host> #类似于httpd中的虚拟主机, </host> </engine> </service></server>
2.server.xml配置文件注释[root@localhost ~]# cat /data/application/tomcat/conf/server.xml<?xml version='1.0' encoding='utf-8'?><!--<Server>元素代表整个容器,是Tomcat实例的顶层元素.它包含一个<Service>元素.并且它不能做为任何元素的子元素. port指定Tomcat监听shutdown命令端口 shutdown指定终止Tomcat服务器运行时,发给Tomcat服务器的shutdown监听端口的字符串.该属性必须设置--><Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources> <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> <!--service服务组件--> <Service name="Catalina"> <!-- Connector主要参数说明(见下面) --> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <!-- 详情常见(host参数详解)--> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- 详情见扩展(Context参数说明 )--> <Context path="" docBase="" debug=""/> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service></Server>
4.Connector主要参数说明port:指定服务器端要创建的端口号,并在这个端口监听来自客户端的请求。protocol:连接器使用的协议,支持HTTP和AJP。AJP(Apache Jserv Protocol)专用于tomcat与apache建立通信的, 在httpd反向代理用户请求至tomcat时使用(可见Nginx反向代理时不可用AJP协议)。redirectPort:指定服务器正在处理http请求时收到了一个SSL传输请求后重定向的端口号maxThreads:接收最大请求的并发数connectionTimeout 指定超时的时间数(以毫秒为单位)
<Connector port="8080" protocol="HTTP/1.1" host:表示一个虚拟主机name:指定主机名appBase:应用程序基本目录,即存放应用程序的目录.一般为appBase="webapps",相对于CATALINA_HOME而言的,也可以写绝对路径。unpackWARs:如果为true,则tomcat会自动将WAR文件解压,否则不解压,直接从WAR文件中运行应用程序autoDeploy:在tomcat启动时,是否自动部署
你们的评论和点赞是我写文章的最大动力,蟹蟹。
关键词:安装,使用