获取安装包
[root@centos6-1 ~]# cd /export/servers/
[root@centos6-1 servers]# wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz
解压安装包
[root@centos6-1 servers]# tar -zvxf apache-tomcat-8.0.53.tar.gz
启动Tomcat
前提配置好Java环境
[root@centos6-1 servers]# cd apache-tomcat-8.0.53/bin/
[root@centos6-1 bin]# ./startup.sh
Using CATALINA_BASE: /export/servers/apache-tomcat-8.0.53
Using CATALINA_HOME: /export/servers/apache-tomcat-8.0.53
Using CATALINA_TMPDIR: /export/servers/apache-tomcat-8.0.53/temp
Using JRE_HOME: /export/servers/jdk1.8.0_65/jre
Using CLASSPATH: /export/servers/apache-tomcat-8.0.53/bin/bootstrap.jar:/export/servers/apache-tomcat-8.0.53/bin/tomcat-juli.jar
Tomcat started.
查看Tomcat进程
[root@centos6-1 bin]# jps
88057 Jps
88012 Bootstrap
[root@centos6-1 bin]# ps -ef|grep java
root 88012 1 2 08:23 pts/0 00:00:04 /export/servers/jdk1.8.0_65/jre/bin/java -Djava.util.logging.config.file=/export/servers/apache-tomcat-8.0.53/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /export/servers/apache-tomcat-8.0.53/bin/bootstrap.jar:/export/servers/apache-tomcat-8.0.53/bin/tomcat-juli.jar -Dcatalina.base=/export/servers/apache-tomcat-8.0.53 -Dcatalina.home=/export/servers/apache-tomcat-8.0.53 -Djava.io.tmpdir=/export/servers/apache-tomcat-8.0.53/temp org.apache.catalina.startup.Bootstrap start
root 88074 87966 0 08:26 pts/0 00:00:00 grep java
[root@centos6-1 bin]#
浏览器访问Tomcat
192.168.214.150为博主虚拟机ip
8080为Tomcat默认端口,可配置
访问的是Tomcat内置的ROOT项目
可以看到tomcat正常运行
部署项目到Tomcat
使用SpringBoot构建的appdemo项目部署,构建过程详见:大型网站分布式架构(一)—— SpringBoot构建项目1.修改pom文件
改为war包
tomcat依赖
注销热部署依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zaomianbao</groupId>
<artifactId>appdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<!--<packaging>jar</packaging>-->
<name>appdemo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2.打包项目
窗口右侧点击"Maven Projects"–>点击appdemo下lifecycle下的package即可
显示BUILD SUCCESS代表打包成功,打包成功后会在项目target目录下生成一个项目war包:appdemo-0.0.1-SNAPSHOT.war
3.将war包部署到Tomcat
首先关闭Tomcat
[root@centos6-1 ~]# cd /export/servers/apache-tomcat-8.0.53/bin/
[root@centos6-1 bin]# jps
88113 Jps
88012 Bootstrap
[root@centos6-1 bin]# ./shutdown.sh
Using CATALINA_BASE: /export/servers/apache-tomcat-8.0.53
Using CATALINA_HOME: /export/servers/apache-tomcat-8.0.53
Using CATALINA_TMPDIR: /export/servers/apache-tomcat-8.0.53/temp
Using JRE_HOME: /export/servers/jdk1.8.0_65/jre
Using CLASSPATH: /export/servers/apache-tomcat-8.0.53/bin/bootstrap.jar:/export/servers/apache-tomcat-8.0.53/bin/tomcat-juli.jar
[root@centos6-1 bin]# jps
88150 Jps
[root@centos6-1 bin]#
将项目war包上传至Tomcat的webapp目录下
[root@centos6-1 ~]# cd /export/servers/apache-tomcat-8.0.53/webapps/
[root@centos6-1 webapps]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring appdemo-0.0.1-SNAPSHOT.war...
100% 17269 KB 17269 KB/sec 00:00:01 0 Errors
[root@centos6-1 webapps]# ll
total 17292
-rw-r--r--. 1 root root 17684349 Aug 22 2018 appdemo-0.0.1-SNAPSHOT.war
drwxr-xr-x. 14 root root 4096 Aug 20 08:19 docs
drwxr-xr-x. 6 root root 4096 Aug 20 08:19 examples
drwxr-xr-x. 5 root root 4096 Aug 20 08:19 host-manager
drwxr-xr-x. 5 root root 4096 Aug 20 08:19 manager
drwxr-xr-x. 3 root root 4096 Aug 20 08:19 ROOT
[root@centos6-1 webapps]#
这里使用的是lrzsz工具上传,详见:三种方式实现Linux的文件上传下载:https://blog.csdn.net/weixin_37490221/article/details/80844825
启动Tomcat
[root@centos6-1 webapps]# cd /export/servers/apache-tomcat-8.0.53/bin/
[root@centos6-1 bin]# ./startup.sh
Using CATALINA_BASE: /export/servers/apache-tomcat-8.0.53
Using CATALINA_HOME: /export/servers/apache-tomcat-8.0.53
Using CATALINA_TMPDIR: /export/servers/apache-tomcat-8.0.53/temp
Using JRE_HOME: /export/servers/jdk1.8.0_65/jre
Using CLASSPATH: /export/servers/apache-tomcat-8.0.53/bin/bootstrap.jar:/export/servers/apache-tomcat-8.0.53/bin/tomcat-juli.jar
Tomcat started.
[root@centos6-1 bin]# cd ..
[root@centos6-1 apache-tomcat-8.0.53]# cd webapps/
[root@centos6-1 webapps]# ll
total 17296
drwxr-xr-x. 5 root root 4096 Aug 20 08:57 appdemo-0.0.1-SNAPSHOT
-rw-r--r--. 1 root root 17684349 Aug 22 2018 appdemo-0.0.1-SNAPSHOT.war
drwxr-xr-x. 14 root root 4096 Aug 20 08:19 docs
drwxr-xr-x. 6 root root 4096 Aug 20 08:19 examples
drwxr-xr-x. 5 root root 4096 Aug 20 08:19 host-manager
drwxr-xr-x. 5 root root 4096 Aug 20 08:19 manager
drwxr-xr-x. 3 root root 4096 Aug 20 08:19 ROOT
[root@centos6-1 webapps]#
访问appdemo
appdemo-0.0.1-SNAPSHOT为appdemo的项目名,可以修改
至此,Tomcat作为Web服务器,appdemo为我们的web项目,一个单机版的web服务已经能够提供给用户访问,那么一个这样的Tomcat服务器能够承担多大的用户并发访问呢?下一篇将介绍一款web服务的压力测试软件,通过测试得到单机版Tomcat的访问极限。
---------------------
作者:枣面包
来源:CSDN
原文:https://blog.csdn.net/weixin_37490221/article/details/81917172
版权声明:本文为博主原创文章,转载请附上博文链接!