顿搜
飞过闲红千叶,夕岸在哪
类目归类
执行命令创建脚本文件
vim /etc/rc.d/init.d/tomcat在文件中写入如下代码,并保存退出
#!/bin/bash
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description: Start up the Tomcat servlet engine.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo -e "\atomcat: unable to locate functions lib. Cannot continue."
exit -1
fi
RETVAL=$?
CATALINA_HOME="/sw/tomcat" #tomcat安装目录,你安装在什么目录下就复制什么目录
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
Linux给文件添加权限,使得脚本文件可以执行
chmod 755 /etc/rc.d/init.d/tomcat将其添加到服务中
chkconfig --add /etc/rc.d/init.d/tomcat然后将下面的配置文件加到tomcat中的catalina.sh文件的最后面
export JAVA_HOME=/sw/java1.8 #jdk的安装路径,使用echo $JAVA_HOME命令可以读取
export CATALINA_HOME=/sw/tomcat
export CATALINA_BASE=/sw/tomcat
export CATALINA_TMPDIR=/sw/tomcat/temp启动和停止
service tomcat start
service tomcat stopvim /etc/rc.d/rc.local写入以下内容到末尾
export JAVA_HOME=/sw/java1.8
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export CATALINA_HOME=/sw/tomcat
#tomcat自启动
/sw/tomcat/bin/startup.在tomcat安装包下面的conf文件下含有一个tomcat-user.xml文件,写入下面这段配置即可
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>配置完用户名密码之后,需要重新启动tomcat