Tomcat 7 安装教程

预备知识:

  • Context: WebAPP
  • $CATALINA_HOME : Tomcat安装根目录, 目录结构如下
   /bin - 启动脚本
   /conf - 配置文件, 配置文件在Tomcat启动时读取,对配置文件的任何修改都需要重启Tomcat
   /logs - 日志文件
   /webapps - webAPP存放位置
  • $CATALINA_BASE

设置

安装以及部署方法都放在 (RUNNING.txt)[https://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt]中, 以下内容是对它的一个总结.

1. 安装JRE6及以上

一般直接安装JDK, JDK中包含了JRE, 具体安装过程这里不详细叙述.

2. 安装Tomcat

2.1 下载

  • apache-tomcat-[version].zip or .tar.gz
    Base distribution. These distributions do not include the Windows service wrapper nor the compiled APR/native library for Windows.
  • apache-tomcat-[version].exe
    32-bit/64-bit Windows installer for Tomcat. Please note that while this distribution includes the vast majority of the base distribution, some of the command-line scripts for launching Tomcat are not included. This distribution is intended for those users planning to launch Tomcat through the Windows shortcuts or services.
  • apache-tomcat-[version]-windows-x86.zip
    32-bit Windows specific distribution that includes the Windows service wrapper and the compiled APR/native library for use with 32-bit JVMs on both 32 and 64 bit Windows platforms.
  • apache-tomcat-[version]-windows-x64.zip
    64-bit Windows specific distribution that includes the Windows service wrapper and the compiled APR/native library for use with 64-bit JVMs on x64 Windows platforms.
  • apache-tomcat-[version]-deployer.zip or .tar.gz
    The standalone Tomcat Web Application Deployer.
  • apache-tomcat-[version]-fulldocs.tar.gz
    The Tomcat documentation bundle, including complete javadocs.

这是官方首页上出现的下载版本, 一般情况下:

  • Linux 选择 第一个
  • Windows 按照操作系统选择三或者四

2.2 安装

安装过程就是解压, 解压得到Tomcat根目录, 目录的命名规则是 apache-tomcat-[version], 之前提到的$CATALINA_HOME就是指这个目录.

3. 配置环境变量

Tomcat是Java应用, 使用不需要环境变量. 但是启动Tomcat时需要执行在/lib下的启动脚本, 这些脚本需要环境变量来运行.

3.1 CATALINA_HOME (required) && CATALINA_BASE (optional)

二者在只有一个Tomcat实例时是相同的, 设置为Tomcat安装包解压出来的目录.
Windows:
CMD:

C:\Windows\system32>setx /m CATALINA_HOME C:\Development\apache-tomcat-7.0.78
SUCCESS: Specified value was saved.
C:\Windows\system32>setx /m CATALINA_BASE C:\Development\apache-tomcat-7.0.78
SUCCESS: Specified value was saved.

PowerShell:

PS C:\Windows\system32> [System.Environment]::setEnvironmentVariable("CATALINA_HOME", "C:\Developme
nt\apache-tomcat-7.0.78", "Machine")
PS C:\Windows\system32> [System.Environment]::setEnvironmentVariable("CATALINA_BASE", "C:\Developme
nt\apache-tomcat-7.0.78", "Machine")

注:虽然cmd中的setx非常方便,但是它只能设置环境变量,不能删除。Powershell 虽然语法繁琐一点,但是对于后期的维护以及管理还是非常方便。

Linux:

[lihongjie@lihongjie ~]$ echo "export CATALINA_HOME=/usr/tomcat_dir" >> /etc/profile
[lihongjie@lihongjie ~]$ echo "export CATALINA_BASE=/usr/tomcat_dir" >> /etc/profile

3.1 JRE_HOME or JAVA_HOME (required)

JAVA_HOME 是jdk的根目录
JRE_HOME 是jre的根目录

CMD:

C:\Windows\system32>setx /m JRE_HOME C:\Development\Java\jdk1.8.0_131\jre\
SUCCESS: Specified value was saved.
C:\Windows\system32>setx /m JAVA_HOME C:\Development\Java\jdk1.8.0_131\
SUCCESS: Specified value was saved.

PowerShell:

PS C:\Windows\system32> [System.Environment]::setEnvironmentVariable("JRE_HOME", "C:\Development\Ja
va\jdk1.8.0_131\jre\", "Machine")
PS C:\Windows\system32> [System.Environment]::setEnvironmentVariable("JAVA_HOME", "C:\Development\J
ava\jdk1.8.0_131\", "Machine")

Linux:

[lihongjie@lihongjie ~]$ echo "export JRE_HOME=/usr/java/jdk" >> /etc/profile
[lihongjie@lihongjie ~]$ echo "export JAVA_HOME=/usr/java/jdk/jre" >> /etc/profile

4. 启动以及关闭Tomcat

Windows:

# 启动
     %CATALINA_HOME%\bin\startup.bat
     %CATALINA_HOME%\bin\catalina.bat start
# 关闭
     %CATALINA_HOME%\bin\shutdown.bat
     %CATALINA_HOME%\bin\catalina.bat stop

Linux:

# 启动
     $CATALINA_HOME/bin/startup.sh
     $CATALINA_HOME/bin/catalina.sh start
# 关闭
     $CATALINA_HOME/bin/shutdown.sh
     $CATALINA_HOME/bin/catalina.sh stop

你可能感兴趣的:(Tomcat 7 安装教程)