Linux安装tomcat一般有rpm和二进制安装的方法,下面主要介绍一下tomcat二进制安装方法
一、JDK的安装
1、rpm包安装jdk
# yum list all| grep jdk
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
java-1.6.0-openjdk.x86_64 1:1.6.0.0-1.66.1.13.0.el6 server
java-1.7.0-openjdk.x86_64 1:1.7.0.45-2.4.3.3.el6 server
jdk.x86_64 2000:1.6.0_22-fcs installed
java-1.6.0-openjdk-devel.x86_64 1:1.6.0.0-1.66.1.13.0.el6 server
java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.0-1.66.1.13.0.el6 server
java-1.7.0-openjdk-devel.x86_64 1:1.7.0.45-2.4.3.3.el6 server
java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.45-2.4.3.3.el6 server
ldapjdk.x86_64 4.18-6.el6 server
# yum install java-1.6.0-openjdk #安装目录/usr/lib/jvm/
# yum install java-1.7.0-openjdk #安装目录/usr/lib/jvm/
2、二进制方式安装jdk 下载地址:http://www.oracle.com/technetwork/java/archive-139210.html
# rpm -ivh jdk-6u22-linux-x64-rpm.bin #安装目录/usr/java/
# ll /usr/java/
total 4
lrwxrwxrwx. 1 root root 16 Feb 2 19:20 default -> /usr/java/latest
drwxr-xr-x. 9 root root 4096 Feb 2 19:20 jdk1.6.0_22
lrwxrwxrwx. 1 root root 21 Feb 2 19:20 latest -> /usr/java/jdk1.6.0_22
3、源码安装jdk 下载地址:http://www.oracle.com/technetwork/java/archive-139210.html
# tar xvf jdk-7u67-linux-x64.tar.gz -C /usr/local/
# ln -sv jdk1.7.0_67/ jdk
2和3方式安装的需要配置环境变量
# cat /etc/profile.d/java.sh
#JAVA_HOME=/usr/java/latest/
JAVA_HOME=/usr/local/jdk
export PATH=$PATH:$JAVA_HOME/bin
# source /etc/profile.d/java.sh
# javac -version
javac 1.7.0_67
# java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-x86_64 u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
二、安装tomcat
1、rpm包安装
# yum list all | grep tomcat
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
apache-tomcat-apis.noarch 0.1-1.el6 server
jakarta-commons-dbcp-tomcat5.noarch 1.2.1-13.8.el6 server
jakarta-commons-pool-tomcat5.x86_64 1.3-12.7.el6 server
tomcat6.noarch 6.0.24-62.el6 server
tomcat6-el-2.1-api.noarch 6.0.24-62.el6 server
tomcat6-jsp-2.1-api.noarch 6.0.24-62.el6 server
tomcat6-lib.noarch 6.0.24-62.el6 server
tomcat6-servlet-2.5-api.noarch 6.0.24-62.el6 server
tomcatjss.noarch 2.1.0-2.el6 server
# yum install tomcat6 -y
2、源码安装 下载地址:http://tomcat.apache.org/
tar xvf apache-tomcat-6.0.8.tar.gz -C /usr/local/
cd /usr/local/
ln -sv apache-tomcat-6.0.8/ tomcat
设置环境变量:
vim /etc/profile.d/catalina.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$PATH:$CATALINA_HOME/bin
三、设置自启动脚本
vim /etc/init.d/tomcat
#!/bin/sh # Tomcat init script for Linux. # # chkconfig: 2345 96 14 # description: The Apache Tomcat servlet/JSP container. export JAVA_HOME=/usr/local/jdk/ export CATALINA_HOME=/usr/local/tomcat export PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin export CATALINA_OPTS="-Xms128m -Xmx256m" #定义堆内存的最小值和最大值 case "$1" in "restart") $CATALINA_HOME/bin/catalina.sh stop sleep 2 $CATALINA_HOME/bin/catalina.sh start ;; "start") exec $CATALINA_HOME/bin/catalina.sh $* ;; "stop") exec $CATALINA_HOME/bin/catalina.sh $* #把所有的参数都传递给catalina.sh ;; *) echo "Usage:$0 start|stop|restart" ;; esac
# /etc/init.d/tomcat start
# /etc/init.d/tomcat restart
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest/
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest/
本文出自 “小鱼的博客” 博客,转载请与作者联系!