增加到开机启动项里面
1.安装jdk及tomcat
把apache-tomcat-6.0.28.tar.gz和jdk-7u10-linux-x64.tar.gz放到/usr目录下
cp apache-tomcat-6.0.28.tar.gz /usr/
cp jdk-7u10-linux-x64.tar.gz /usr/
安装jdk:
tar xvzf jdk-7u10-linux-x64.tar.gz
安装tomcat:将在/usr下生成apache-tomcat-6.0.28目录
tar xvzf apache-tomcat-6.0.28.tar.gz
2.在/etc/profile 末尾添加
export JAVA_HOME=/usr/java/jdk1.7.0_25
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
3.在/etc/rc.d/rc.local 末尾添加
export JDK_HOME=/usr/jdk1.7.0_10
export JAVA_HOME=/usr/jdk1.7.0_10
/usr/apache-tomcat-6.0.28/bin/startup.sh
4.修改rc.local文件为可执行
chmod +x rc.local
5.reboot 重启验证
tomcat设置为服务的形式
1.配置tomcat自启动
tomcat文件里面的内容
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcat
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JRE_HOME=/usr/java/jdk1.7.0_25
export CATALINA_HOME=/home/hospital/apache-tomcat-7.0.41
export CATALINA_BASE=/home/hospital/apache-tomcat-7.0.41
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
第一步:/etc/init.d 复制tomcat文件到该路径下面
(需要root操作权限注:需要修改以下3个部分的路径“export JRE_HOME=/usr/jdk1.8.0_131”、“export CATALINA_HOME=/usr/tomcat6”、“export CATALINA_BASE=/usr/tomcat6”)
第二步、设置权限
chmod +x /etc/init.d/tomcat
第三步、设定开机启动服务
chkconfig tomcat on
第四步、reboot 验证