Tomcat ~ 从入门到入坑。

Tomcat ~ 从入门到入坑。



ApacheTomcat® 软件是 Java Servlet,JavaServer Pages,Java Expression Language 和 Java WebSocket 技术的开源实现。 Java
Servlet,JavaServer Pages,Java Expression Language 和 Java WebSocket 规范是在 Java Community Process 下开发的。
~~ Tomcat 官方。

Tomcat 是一个广泛使用的支持 jspservlet 的 Web 服务器。Tomcat 服务器是一个免费的开放源代码的Web
应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试 JSP 程序的首选。

当我们 下载 好 Tomcat,

apache-tomcat-8.5.51.tar.gz 解压会看到 Tomcat 的目录结构如下。
在这里插入图片描述

These are some of the key tomcat directories:

  • /bin 目录 —> startup(启动)、shutdown(关闭)等。

/bin - Startup, shutdown, and other scripts. The *.sh files (for Unix systems) are functional duplicates of the *.bat
files (for Windows systems). Since the Win32 command-line lacks certain functionality, there are some additional files
in here.

Linux 系统中用 *.sh 运行。如:./startup.sh
Windows 系统中用 *.bat 运行。如:…/bin/startup.bat 或 双击 startup.bat,会出现一个 cmd
窗口,运行中请不要关闭,如运行 shutdown.bat 或关闭了 cmd 窗口,Tomcat 服务将退出。

  • /conf 目录 —> 配置文件和相关 DTD。

/conf - Configuration files and related DTDs. The most important file in here is server.xml. It is the main
configuration file for the container.

server.xml 是 Tomcat 的灵魂。一般的配置均在此配置。

  • server.xml 常用配置。

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443"/>

port —> 指定 Tomcat 的访问端口。
当 Tomcat 启动后,浏览器访问 Tomcat 所在的 IP 地址 - :8080 即可访问 Tomcat。



  • 进入 Tomcat 的 /bin 目录,用 notepad 打开 catalina.sh。在文件末尾添加以下内容(JAVA_HOME,JRE_HOME)。
JAVA_HOME=/home/geek/geek/tools_my/jdk1.8.0_241/bin
JRE_HOME=/home/geek/geek/tools_my/jdk1.8.0_241/jre
#   JAVA_HOME       Must point at your Java Development Kit installation.
#                   Required to run the with the "debug" argument.
#
#   JRE_HOME        Must point at your Java Runtime installation.
#                   Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
#                   are both set, JRE_HOME is used.

配置完成后保存,运行

$ ./catalina.sh start  # 后台运行。可以关闭终端。
# 需要使用 ./catalina.sh stop 结束 Tomcat 服务。
$ ./catalina.sh run  # 终端运行,终端窗口关闭,Tomcat 服务也关闭。

开启 Tomcat 服务后,在浏览器中输入地址即可访问。
:8080 端口号是你在 server.xml 中配置的端口号。

http://127.0.0.1:8080/
在这里插入图片描述
当看到此页面,恭喜你,Tomcat 启动成功。


  • logs 目录 —> Tomcat 日志文件夹。

/logs - Log files are here by default.

  • /webapps 目录 —> 将你的 web 应用网页放于此,通过浏览器访问的页面的存放处。

/webapps - This is where your webapps go.



CATALINA_HOME & CATALINA_BASE。

CATALINA_HOME and CATALINA_BASE
Throughout the documentation, there are references to the two following properties:

  • CATALINA_HOME

指向 Tomcat 的安装目录根目录。
如:/home/geek/tools_my/apache-tomcat-8.5.51

CATALINA_HOME: Represents the root of your Tomcat installation, for example /home/tomcat/apache-tomcat-9.0.10 or C:
\Program Files\apache-tomcat-9.0.10.

  • CATALINA_BASE

指向 Tomcat 实例运行所依赖的配置文件的根目录。

CATALINA_BASE: Represents the root of a runtime configuration of a specific Tomcat instance. If you want to have
multiple Tomcat instances on one machine, use the CATALINA_BASE property.
If you set the properties to different locations, the CATALINA_HOME location contains static sources, such as .jar
files, or binary files. The CATALINA_BASE location contains configuration files, log files, deployed applications, and
other runtime requirements.

  • 默认情况下,CATALINA_HOMECATALINA_BASE 指向同一目录。如果你想搭建 Tomcat 集群

By default, CATALINA_HOME and CATALINA_BASE point to the same directory. Set CATALINA_BASE manually when you require
running multiple Tomcat instances on one machine. Doing so provides the following benefits:

Easier management of upgrading to a newer version of Tomcat. Because all instances with single CATALINA_HOME location
share one set of .jar files and binary files, you can easily upgrade the files to newer version and have the change
propagated to all Tomcat instances using the same CATALIA_HOME directory.
Avoiding duplication of the same static .jar files.
The possibility to share certain settings, for example the setenv shell or bat script file (depending on your operating
system).

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

lyfGeek

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

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

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

打赏作者

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

抵扣说明:

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

余额充值