CentOs安装Tomcat6、7
- 安装Tomcat 和 jsvc
- 下载并安装tomcat
到Tomcat 官网下载 tar.gz版本
将Tomcat 安装包上传至Centos对应目录下。
使用 tar -zxvf 命令解压
- 编译jsvc
注意:编译前需要安装 gcc,autoconf和jdk
进入解压的tomcat目录的bin目录
解压commons-daemon-native.tar.gz 文件
进入解压后的目录中的 unix 目录
执行命令: ./configure --with-java=/usr/java/jdk1.8.0_131(等号后面为JDK安装目录)
执行命令:make
执行命令:cp jsvc ../..
- 添加Tomcat 用户,并分配目录
tomcat的daemon.sh默认以tomcat用户启动,所以需要先添加tomcat.
执行命令:useradd tomcat -s /sbin/nologin -M
执行命令:chown -R tomcat /opt/tomcat/apache-tomcat-6.0.26(红色部分为Tomcat目录)
- 添加systemd服务单元,添加tomcat为自启动服务
执行命令:/etc/init.d/tomcat
加入如下内容:
#!/bin/sh
# chkconfig: 2345 10 90
# description: Tomcat6 Daemon
##############################################################################
#
# Copyright 2004 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################
#
# Small shell script to show how to start/stop Tomcat using jsvc
# If you want to have Tomcat running on port 80 please modify the server.xml
# file:
#
#
#
# port="80" minProcessors="5" maxProcessors="75"
# enableLookups="true" redirectPort="8443"
# acceptCount="10" debug="0" connectionTimeout="60000"/>
#
# That is for Tomcat-5.0.x (Apache Tomcat/5.0)
#
# Adapt the following lines to your configuration
JAVA_HOME=/usr/java/jdk1.8.0_131
CATALINA_HOME=/opt/tomcat/apache-tomcat-6.0.26
TOMCAT_USER=mark
DAEMON_HOME=$CATALINA_HOME/bin
# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=$CATALINA_HOME
CATALINA_OPTS=
CLASSPATH=
$JAVA_HOME/lib/tools.jar:
$CATALINA_HOME/bin/commons-daemon.jar:
$CATALINA_HOME/bin/bootstrap.jar
case "$1" in
start)
#
# Start Tomcat
#
$DAEMON_HOME/jsvc
-user $TOMCAT_USER
-home $JAVA_HOME
-Dcatalina.home=$CATALINA_HOME
-Dcatalina.base=$CATALINA_BASE
-Djava.io.tmpdir=$TMP_DIR
-wait 10
-pidfile $PID_FILE
-outfile $CATALINA_HOME/logs/catalina.out
-errfile "&1"
$CATALINA_OPTS
-cp $CLASSPATH
org.apache.catalina.startup.Bootstrap
#
# To get a verbose JVM
#-verbose
# To get a debug of jsvc.
#-debug
exit $?
;;
stop)
#
# Stop Tomcat
#
$DAEMON_HOME/jsvc
-stop
-pidfile $PID_FILE
org.apache.catalina.startup.Bootstrap
exit $?
;;
*)
echo "Usage tomcat.sh start/stop"
exit 1;;
esac
注意修改黄色部分路径
分别执行命令:
chkconfig --add tomcat
chmod 755 /etc/init.d/tomcat
service tomcat start
以上是 CentOs安装Tomcat6、7 的全部内容, 来源链接: utcz.com/z/513055.html