CentOS7.2 安装Tomcat

Centos默认安装JDK

现在要删除旧版本的jdk,安装新版本jdk

查看现有jdk:

[root@localhost 桌面]# rpm -qa | grep jdk
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64

删除旧版本:

[root@localhost 桌面]# yum -y remove java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 java-1.8.0-openjdk.x86_64.1.1.8.0.65-3.b17.el7 将被 删除
--> 正在处理依赖关系 java-1.8.0-openjdk,它被软件包 icedtea-web-1.6.1-4.el7.x86_64 需要
--> 正在检查事务
---> 软件包 icedtea-web.x86_64.0.1.6.1-4.el7 将被 删除
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package                架构       版本                     源             大小
================================================================================
正在删除:
 java-1.8.0-openjdk     x86_64     1:1.8.0.65-3.b17.el7     @anaconda     501 k
为依赖而移除:
 icedtea-web            x86_64     1.6.1-4.el7              @anaconda     2.1 M

事务概要
================================================================================
移除  1 软件包 (+1 依赖软件包)

安装大小:2.6 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在删除    : icedtea-web-1.6.1-4.el7.x86_64                              1/2 
  正在删除    : 1:java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64              2/2 
  验证中      : 1:java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64              1/2 
  验证中      : icedtea-web-1.6.1-4.el7.x86_64                              2/2 

删除:
  java-1.8.0-openjdk.x86_64 1:1.8.0.65-3.b17.el7                                

作为依赖被删除:
  icedtea-web.x86_64 0:1.6.1-4.el7                                              

完毕!

将下载的jdk文件放在/usr/local/jdk文件夹下,解压

添加/etc/profile文件为:

export JAVA_HOME=/usr/local/jdk/jdk1.8.0_121
export JRE_HOME=/usr/local/jdk/jdk1.8.0_121/jre
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

 

启用配置:

source /etc/profile

查看java版本:

[root@localhost 桌面]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

=====================================================

安装Tomcat:

将下载的tomcat迁移到/usr/local/tomcat下,并解压

修改/usr/local/tomcat/apache-tomcat-9.0.0.M17/bin/catalina.sh文件

在第二行添加:

JAVA_HOME=/usr/local/jdk/jdk1.8.0_121   
CATALINA_HOME=/usr/local/tomcat/apache-tomcat-9.0.0.M17

start.up文件添加:

#set java environment
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_121
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

#tomcat
export TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-9.0.0.M17

 

启动/bin/startup.sh

[root@localhost bin]# ./startup.sh
Using CATALINA_BASE:   /usr/local/tomcat/apache-tomcat-9.0.0.M17
Using CATALINA_HOME:   /usr/local/tomcat/apache-tomcat-9.0.0.M17
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.0.M17/temp
Using JRE_HOME:        /usr/local/jdk/jdk1.8.0_121
Using CLASSPATH:       /usr/local/tomcat/apache-tomcat-9.0.0.M17/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.0.M17/bin/tomcat-juli.jar
Tomcat started.

打开浏览器访问127.0.0.1:8080,ok!

为了以后tomcat可以自启动,在/etc/rc.local文件中添加配置:

#set java environment
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_121
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

#tomcat
export TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-9.0.0.M17

#configuration
/usr/local/tomcat/apache-tomcat-9.0.0.M17/bin/startup.sh

如果重启还是不行,那么应该就是该文件没有执行权限,那么就执行:

chmod +x /etc/rc.d/rc.local

 

http://newthink.blog.51cto.com/872263/1859308

http://www.itread01.com/articles/1476060057.html

posted @ 2017-04-04 21:52  hongdada  阅读(505)  评论(0编辑  收藏  举报