#!/bin/bash
# This is the init script for starting up the
# Jakarta Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#
# Source function library.
. /etc/rc.d/init.d/functions
# Get config.
. /etc/sysconfig/network
# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
export JAVA_HOME=/usr/local/java/jdk1.7.0_79 ------jdk路径,这里要根据实际路径修改
tomcat_home=/usr/local/java/apache-tomcat-7.0.77-----tomcat路径,也是根据实际路径修改
startup=$tomcat_home/bin/startup.sh
shutdown=$tomcat_home/bin/shutdown.sh
start(){
echo -n "Starting Tomcat service:"
cd $tomcat_home
$startup
echo "tomcat is succeessfully started up"
}
stop(){
echo -n "Shutting down tomcat: "
cd $tomcat_home
$shutdown
echo "tomcat is succeessfully shut down."
}
status(){
numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`
if [ $numproc -gt 0 ]; then
echo "Tomcat is running..."
else
echo "Tomcat is stopped..."
fi
}
restart(){
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
将以上代码复制并拷贝到文件tomcat文件中,vim tomcat复制以上内容
chmod +x tomcat ——添加执行权限
mv tomcat /etc/rc.d/init.d/ ——将tomcat文件拷贝到服务目录下
添加tomcat服务
chkconfig - -add tomcat
chkconfig tomcat on——开机启动tomcat服务
service tomcat start/stop/restart ——启动tomcat命令
注意:如果发现执行启动tomcat命令还是无法启动,请确认jdk bin目录是否有执行权限
确定jdk版本使用以下命令
如果发现jdk使用的是系统自带的openjdk,可以卸载掉
rpm -qa | grep jdk
rpm -e - - nodeps java-1.7.0-openjdk***
卸载完成后再执行java -version确认jdk版本是否正确。
转载于:https://blog.51cto.com/12185273/2049163