Redhat Linux企业版安装Tomcat并设置为开机启动详解

04-01 18:41:05   来源:admin   评论: 点击:

如何设置tomcat开机启动
Redhat Linux企业版安装Tomcat并设置为开机启动详解
 
1. 从http://java.sun.com/javase/downloads/index.jsp下载JDK jdk-6u11-linux-i586-rpm.bin 
 
 
2. 进入下载目录并安装JDK;
 #./jdk-6u11-linux-i586.bin
 
3. 编辑 /etc/profile文件,将JDK安装路径添加到文件中,如下:
#vim /etc/profile 
export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
 
#source /etc/profile
 
4.下载Tomcat
#wget http://ftp.sh.cvut.cz/MIRRORS/apache/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
 
 
5. 解压Tomcat
#tar xvzf apache-tomcat-6.0.18.tar.gz
 
6.将解压过后的tomcat移动到目录/usr/share/目录下 
#mv -f apache-tomcat-6.0.18 /usr/share/tomcat6
 
7.修改权限
 #chown -R tomcat /usr/share/tomcat6
 
8. 创建软连接
#ln -s /usr/share/tomcat6 /usr/share/tomcat
 
9. 添加tomcat分组
#useradd -d /usr/share/tomcat -s /sbin/nologin tomcat
 
 
10.创建tomcat开机启动脚本
 
#vi /etc/init.d/tomcat
将下面的代码拷贝到tomcat文件中:
#!/bin/bash
#
# Startup script for Tomcat
#
# chkconfig: 345 84 16
# description: Tomcat jakarta JSP server
#Necessary environment variables
export CATALINA_HOME="/usr/local/tomcat"
if [ ! -f $CATALINA_HOME/bin/catalina.sh ]
then
echo "Tomcat not available..."
exit
fi
 
 
start() {
echo -n -e '\E[0;0m'"\033[1;32mStarting Tomcat: \033[0m \n"
su -l tomcat -c $CATALINA_HOME/bin/startup.sh
echo
touch /var/lock/subsys/tomcatd
sleep 3
}
 
stop() {
echo -n -e '\E[0;0m'"\033[1;31mShutting down Tomcat: \033[m \n"
su -l tomcat -c $CATALINA_HOME/bin/shutdown.sh
rm -f /var/lock/subsys/tomcatd
echo
}
 
status() {
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
echo -n "tomcatd ( pid "
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
echo -n ") is running..."
echo
else
echo "Tomcat is stopped"
fi
}
 
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
status
;;
*)
echo "Usage: tomcatd {start|stop|restart|status}"
exit 1
esac
 
11、保存启动脚本并分配“可执行”权限
#chmod +x /etc/init.d/tomcat
 
12. #chkconfig tomcat6 on
 
13. 将 $CATALINA_HOME添加到文件/etc/profile中:
#vim /etc/profile
export CATALINA_HOME=/usr/share/tomcat
 
14. #/etc/init.d/tomcat start
 
15. 打开浏览器访问http://localhost:8080测试
 
16. 如果出现下面结果则安装成功
 

相关热词搜索:tomcat redhat 开机启动

上一篇:如何在Amazon EC2 Linux(Redhat)实例上搭建JDK,Tomcat环境 下一篇:多备份免费网站数据备份:一键备份,自动备份,快速备份
分享到: 收藏