=================================
蓝色文字部分为执行代码,红色文字部分需注意修改
=================================
#下载tomcat源码包
wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.81/bin/apache-tomcat-7.0.81.tar.gz
tar-zxvf apache-tomcat-7.0.81.tar.gz
为此,tomcat安装完成
cd到tomcat的bin目录下使用 ./startup 启动Tomcat,关闭同理
==========================================================================
设置tomcat自启动
1.我们在/etc/init.d/下新建一个文件tomcat(需要在root权限下操作)
vi /etc/init.d/tomcat
加入以下代码:
============分割线==================================
# tomcat自启动脚本
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcatd
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JDK_HOME=/usr/java/jdk1.7.0_45 (请填写真实的JDK目录)
export CATALINA_HOME=/home/ldatum/usr/apache-tomcat-7.0.10(请填写真实的tomcat目录)
export CATALINA_BASE=/home/ldatum/usr/apache-tomcat-7.0.10(请填写真实的tomcat目录)
start()
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop()
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 1
ps -fwwu tomcat | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
echo " OK"
# [ $RETVAL -eq 0 ] && rm -f /var/lock/...
return $RETVAL
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restaring Tomcat"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
2.添加完毕之后,给其增加可执行权限: chmod +x /etc/init.d/tomcat
3.之后就是将这个shell文件的link连到/etc/rc2.d/目录下
ln -s /etc/init.d/tomcat /etc/rc2.d/S16Tomcat
4.接下来就是把这个脚本设置成系统启动时自动执行,系统关闭时自动停止,使用如下命令
chkconfig --add tomcat
大功告成,reboot之后自启动
文章来源:http://jingyan.baidu.com/article/1612d50079cfe5e20f1eee71.html