CentOS下配置安装Tomcat并配置JDK环境
第一步、下载JDK、Tomcat 下载JDK 版本:jdk-7u45-linux-x64.rpm 安装JDK [root@thinkpig007 ss]# rpm –ivhjdk-7u45-linux-x64.rpm 下载tomcat7 http://apache.fayea.com/apache-mirror/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz 或者: #wget http://apache.fayea.com/apache-mirror/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz 版本:apache-tomcat-7.0.47.tar.gz 第二步、卸载系统老的tomcat 卸载使用yum自动安装的tomcat6 #yum remove tomcat6 查看本机的jdk本版 #java –version [root@thinkpig007 ss]# java-version java version"1.6.0_24" OpenJDK Runtime Environment(IcedTea6 1.11.13) (rhel-1.65.1.11.13.el6_4-x86_64) OpenJDK 64-Bit Server VM(build 20.0-b12, mixed mode) [root@thinkpig007 ss]# 查看本机已经安装的JDK版本 [root@thinkpig007 ss]# cd/usr/java/ default/ jdk1.7.0_45/ latest/ 注意:这里的jdk目录就是我们修改/etc/profile环境变量是所要填写路径及目录名称,如下 exportJAVA_HOME=/usr/java/jdk1.7.0_45 (详解:“第三步、安装tomcat7”中的“(4) 添加tomcat环境变量”) [root@thinkpig007 ss]# cd/usr/java/ [root@thinkpig007jdk1.7.0_45]# cat release JAVA_VERSION="1.7.0" OS_NAME="Linux" OS_VERSION="2.6" OS_ARCH="amd64" SOURCE=" .:f0cdb08a4624corba:80f65a8f5850 deploy:2b1995e2c8f5 hotspot:12374864c655hotspot/make/closed:2c0b7ecdd92d hotspot/src/closed:b8a50da977b6hotspot/test/closed:47eee40b7622 install:99193876e329 jaxp:4beb90ab48f7jaxws:65b0f3ccdc8b jdk:c5ca4daec23b jdk/make/closed:917a8e455dc3jdk/src/closed:b6127fd9ff72 jdk/test/closed:e3c74041acc5 langtools:ba3ff27d4082pubs:476da1da84f7 sponsors:c732b1a6f43b" BUILD_TYPE=commercial 第三步、安装tomcat7 安装tomcat (1)解压apache-tomcat-7.0.47.tar.gz [root@thinkpig007 ss]# tar-zxvf apache-tomcat-7.0.47.tar.gz (2)复制解压后的目录apache-tomcat-7.0.47到/usr/local下并重命名为tomcat7 [root@thinkpig007 ss]# cp -Rapache-tomcat-7.0.47 /usr/local/tomcat7 注意:/usr/local/tomcat7就是后面我们要修改环境变量时需要填写的目录路径 (3)进入bin目录 [root@thinkpig007 ss]# cd/usr/local/tomcat7/ [root@thinkpig007 tomcat7]# cdbin/ [root@thinkpig007 bin]# 没修改环境变量前,启动tomcat出错 [root@thinkpig007 bin]#./startup.sh Cannot find ”/usr/local/tomcat”/bin/setclasspath.sh (4)添加tomcat环境变量 # [root@thinkpig007 ~]# vi/etc/profile 加入下代码 #set environment variable exportJAVA_HOME=/usr/java/jdk1.7.0_45 export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar exportTOMCAT_HOME=/usr/local/tomcat7 exportCATALINA_HOME=/usr/local/tomcat7 exportPATH=$PATH:$JAVA_HOME/bin (5)修改应用环境变量,是配置生效 [root@thinkpig007 bin]# source/etc/profile (6)修改环境变量后重新启动tomcat启动成功 This file is needed to runthis program [root@thinkpig007 bin]# ./startup.sh Using CATALINA_BASE: /usr/local/tomcat7 Using CATALINA_HOME: /usr/local/tomcat7 Using CATALINA_TMPDIR:/usr/local/tomcat7/temp Using JRE_HOME: /usr/java/jdk1.7.0_45 Using CLASSPATH: /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
(7)关闭tomcat [root@thinkpig007 bin]#./shutdown.sh Using CATALINA_BASE: /usr/local/tomcat7 Using CATALINA_HOME: /usr/local/tomcat7 Using CATALINA_TMPDIR:/usr/local/tomcat7/temp Using JRE_HOME: /usr/java/jdk1.7.0_45 Using CLASSPATH: /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar [root@thinkpig007 bin]# 第四步、添加管理权限 默认情况下,Tomcat并没提供具有管理权限的账号,所以需要添加具有这种权限的账号。角色manager-gui具有这种权限,但在系统用户控制文件tomcat-users.xml中并没有设置这两种角色和对应的用户,所以需要添加这种角色和用户,方法是打开tomcat-users.xml文件,添加如下内容: <rolerolename="manager-gui"/> <userusername="manager" password="manager"roles="manager-gui"/> 然后重启Tomcat服务器,文件修改生效。