您的位置:首页 > 运维架构 > Tomcat

CentOS-7.0中安装与配置Tomcat-8的方法

2017-04-07 15:32 567 查看
安装说明
安装环境:CentOS-7.0.1406
安装方式:源码安装
软件:apache-tomcat-8.5.13.tar.gz
下载地址:http://tomcat.apache.org/download-80.cgi

安装前提

在系统中,我安装的JDK版本是1.8

安装tomcat

创建tomcat目录

mkdir /usr/local/tomcat

将apache-tomcat-8.5.13.tar.gz文件上传到/usr/local/tomcat中执行以下操作:

[root@janus /]# cd /usr/local/tomcat
[root@janus tomcat]# tar -zxv -f apache-tomcat-8.5.13.tar.gz // 解压压缩包
[root@janus tomcat]# rm -rf apache-tomcat-8.5.13.tar.gz // 删除压缩包

启动Tomcat

执行以下操作:

[root@janus /]# /usr/local/tomcat/apache-tomcat-8.5.13/bin/startup.sh

如果出现以下错误

Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program

先看Tomcat的startup.bat,它调用了catalina.bat,而catalina.bat则调用了setclasspath.bat。只要在setclasspath.bat的开头声明环境变量,打开tomcat的bin目录下面的setclasspath.sh,添加红色部分,路径自己修改。windows 下用set,Linux下用export。

export JAVA_HOME=/usr/local/java/jdk1.8.0_121
export JRE_HOME=/usr/local/java/jdk1.8.0_121/jre

rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0 rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem ---------------------------------------------------------------------------
rem Set JAVA_HOME or JRE_HOME if not already set and ensure any provided
rem settings are valid and consistent with the selected start-up options.
rem ---------------------------------------------------------------------------

export JAVA_HOME=/usr/local/java/jdk1.8.0_121
export JRE_HOME=/usr/local/java/jdk1.8.0_121/jre

rem Make sure prerequisite environment variables are set

rem In debug mode we need a real JDK (JAVA_HOME)
if ""%1"" == ""debug"" goto needJavaHome

rem Otherwise either JRE or JDK are fine
if not "%JRE_HOME%" == "" goto gotJreHome
if not "%JAVA_HOME%" == "" goto gotJavaHome
echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
echo At least one of these environment variable is needed to run this program
goto exit

:needJavaHome
rem Check if we have a usable JDK
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
set "JRE_HOME=%JAVA_HOME%"
goto okJava

:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly.
echo It is needed to run this program in debug mode.
echo NB: JAVA_HOME should point to a JDK not a JRE.
goto exit

设置好后,保存当前配置文件。

[root@janus /]# /usr/local/tomcat/apache-tomcat-8.5.13/bin/startup.shUsing CATALINA_BASE:   /usr/local/tomcat/apache-tomcat-8.5.13
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-8.5.13
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-8.5.13/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_121
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-8.5.13/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-8.5.13/bin/tomcat-juli.jar
Tomcat started.

继续执行tomcat中bin文件夹下的startup.sh

/usr/local/tomcat/apache-tomcat-8.5.13/bin/startup.sh

然后通过浏览器访问



添加项目配置路径

#此配置在tomcat下的conf文件夹下,server.xml中的Host节点下添加项目文件名以及路径
<Context docBase="sparta" path="/sparta" debug="0" privileged="true"/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息