Linux安装Tomcat
1、安装Tomcat
1)下载apache-tomcat-6.0.37.tar.gz,上传到服务器的/softs目录
[root@h1 ~]# cd /softs [root@h1 softs]# ls apache-tomcat-6.0.37.tar.gz [root@h1 softs]#
2)进入/usr/local目录,执行如下明命令
[root@h1 local]# tar -zxvf /softs/apache-tomcat-6.0.37.tar.gz
执行结束,Tomcat已经解压好
[root@h1 local]# ls apache-tomcat-6.0.37 bin etc games include lib lib64 libexec sbin share src [root@h1 local]#
3)进入Tomcat安装路径中的bin目录,执行如下命令,启动Tomcat
[root@h1 bin]# ./startup.sh Using CATALINA_BASE: /usr/local/apache-tomcat-6.0.37 Using CATALINA_HOME: /usr/local/apache-tomcat-6.0.37 Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.37/temp Using JRE_HOME: /usr/java/jdk1.6.0_37 Using CLASSPATH: /usr/local/apache-tomcat-6.0.37/bin/bootstrap.jar
4)执行如下命令,关闭Tomcat
[root@h1 bin]# ./shutdown.sh Using CATALINA_BASE: /usr/local/apache-tomcat-6.0.37 Using CATALINA_HOME: /usr/local/apache-tomcat-6.0.37 Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.37/temp Using JRE_HOME: /usr/java/jdk1.6.0_37 Using CLASSPATH: /usr/local/apache-tomcat-6.0.37/bin/bootstrap.jar [root@h1 bin]#
2、将Tomcat配置成系统服务
1)进入/etc/init.d目录,编写Tomcat启动脚本
[root@h1 init.d]# vi tomcat
脚本内容如下
#!/bin/bash #description:tomcat start stop restart #processname:tomcat #chkconfig:2345 20 85 JAVA_HOME=/usr/java/jdk1.6.0_37 export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH CATALINA_HOME=/usr/local/apache-tomcat-6.0.37 case $1 in start) sh $CATALINA_HOME/bin/startup.sh ;; stop) sh $CATALINA_HOME/bin/shutdown.sh ;; restart) sh $CATALINA_HOME/bin/shutdown.sh sh $CATALINA_HOME/bin/startup.sh ;; esac
# chkconfig: 2345 10 90 告诉chkconfig缺省的启动执行等级、启动优先级、停止优先级
2)赋予tomcat脚本可执行权限
[root@h1 init.d]# chmod 755 tomcat
3)将Tomcat添加为系统服务
[root@h1 init.d]# chkconfig --add tomcat
4)指定Tomcat服务在系统服务等级中开启
[root@h1 init.d]# chkconfig --level 2345 tomcat on
5)查看tomcat在那些执行等级中开启
[root@h1 init.d]# chkconfig --list tomcat tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@h1 init.d]#
6)启动tomcat
[root@h1 init.d]# service tomcat start
7)停止tomcat
[root@h1 init.d]# service tomcat stop
8)重启动tomcat
[root@h1 init.d]# service tomcat restart