增加到開(kāi)機(jī)啟動(dòng)項(xiàng)里面
1.安裝jdk及tomcat
把a(bǔ)pache-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文件為可執(zhí)行
chmod +x rc.local
5.reboot 重啟驗(yàn)證
tomcat設(shè)置為服務(wù)的形式
1.配置tomcat自啟動(dòng)
tomcat文件里面的內(nèi)容
#!/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 復(fù)制tomcat文件到該路徑下面
(需要root操作權(quán)限注:需要修改以下3個(gè)部分的路徑“export JRE_HOME=/usr/jdk1.8.0_131”叁征、“export CATALINA_HOME=/usr/tomcat6”、“export CATALINA_BASE=/usr/tomcat6”)
第二步仇轻、設(shè)置權(quán)限
chmod +x /etc/init.d/tomcat
第三步授嘀、設(shè)定開(kāi)機(jī)啟動(dòng)服務(wù)
chkconfig tomcat on
第四步驰凛、reboot 驗(yàn)證