系统:centos 6.5
tomcat: apache-tomcat-7.0.72.tar.gz
java: jdk-7u79-linux-x64.tar.gz
1、安装JDK
1)创建相关目录
mkdir -p /usr/local/tomcat
mkdir /usr/local/java
2)安装JDK,配置java环境(安装Tomcat之前必须安装JDK(Java Development kit),是SUN公司免费提供JAVA语言开发的工具包,实现JAVA的跨平台使用)
tar zxvf jdk-7u79-linux-x64.tar.gz
mv jdk1.7.0_79/ /usr/local/java/
3)在/etc/profile.d/下建立java脚本
vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/java/jdk1.7.0_79/
export PATH=$PATH:$JAVA_HOME/bin
4)将java脚本导入到环境变量
source /etc/profile.d/java.sh
5)运行Java -version命令查看java版本是否和之前安装的一致
java –version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
2、安装Tomcat
1)安装配置Tomcat
tar zxvf apache-tomcat-7.0.72.tar.gz mv apache-tomcat-7.0.72/*
/usr/local/tomcat
开启tomcat,运行/usr/local/tomcat/bin/startup.sh
关闭tomcat,运行/usr/local/tomcat/bin/shutdown.sh
2)添加快捷启动
cd /usr/local/tomcat/
cp bin/catalina.sh /etc/init.d/tomcat
chmod 755 /etc/init.d/tomcat vim /etc/init.d/tomcat
CATALINA_HOME=/usr/local/tomcat/
JAVA_HOME=/usr/local/java/jdk1.7.0_79
3)修改环境变量 最后添加
vim /etc/profile
export CATALINA_HOME=/usr/local/tomcat
source /etc/profile
4)开放防火墙端口号8080
iptables -I INPUT -p tcp –dport 8080 -j ACCEPT
service iptables save
5)测试
service tomcat stop
service tomcat start
http://IP:8080/
6)Tomca开机自启
vim /etc/init.d/tomcat
#!/bin/sh
# chkconfig: 2345 80 90
# description: Tomcat servive
CATALINA_HOME=/usr/local/tomcat/
JAVA_HOME=/usr/local/java/jdk1.7.0_79
chkconfig –add tomcat 加入
chkconfig –list 查看