Centos7 安装java1.7和tomcat7并部署应用

作者: 繁著 | 来源:发表于2017-08-18 22:44 被阅读0次

    安装Java1.7

    登录服务器查看JDK软件包的列表

    yum search java | grep -i --color JDK

    ldapjdk-javadoc.noarch : Javadoc for ldapjdk 
    icedtea-web.x86_64 : Additional Java components for OpenJDK - Java browser 
    java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment 
    java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment 
    java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation 
    java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle 
    java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment 
    java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector 
    java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos 
    java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment 
    java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without 
    java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation 
    java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle 
    java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment 
    java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment 
    java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector 
    java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK accessibility connector 
    java-1.8.0-openjdk-debug.i686 : OpenJDK Runtime Environment with full debug on 
    java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment with full debug on 
    java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos 
    java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos with full debug on 
    java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment 
    java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment 
    java-1.8.0-openjdk-devel-debug.i686 : OpenJDK Development Environment with full 
    java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment with 
    java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment 
    java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment 
    java-1.8.0-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full 
    java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full 
    java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation 
    java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK API Documentation for packages 
    java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK API Documentation compressed in 
    java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK API Documentation 
    java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle 
    java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle for packages with 
    ldapjdk.noarch : The Mozilla LDAP Java SDK 
    openprops.noarch : An improved java.util.Properties from OpenJDK
    
    
    选择自己需要的版本进行安装

    yum install java-1.7.0-openjdk-devel.x86_64

    配置环境变量

    [root@localhost ~]# vi /etc/profile
    在profile文件中添加如下内容

    #set java environment 
    JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64(java的安装路径)
    JRE_HOME=$JAVA_HOME/jre 
    CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib 
    PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin 
    export JAVA_HOME JRE_HOME CLASS_PATH PATH 
    
    验证及查看版本
    java -version
    echo $JAVA_HOME
    echo $JRE_HOME
    echo $CLASSPATH
    echo $PATH
    

    安装Tomcat7

    下载tomcat7的安装文件

    wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.69/bin/apache-tomcat-7.0.69.tar.gz
    解压并移到/usr/local目录下

    tar -zxvf apache-tomcat-7.0.57.tar.gz
    mv apache-tomcat-7.0.69/ /usr/local/tomcat
    
    配置tomcat环境变量和内存设置

    在tomcat的bin目录下打开catalina.sh文件,vi /usr/local/tomcat/bin/catalina.sh,添加以下信息:

    JAVA_OPTS="-Xms512m -Xmx1024m -Xss1024K -XX:PermSize=512m -XX:MaxPermSize=1024m"
    export TOMCAT_HOME=/usr/local/tomcat
    export CATALINA_HOME=/usr/local/tomcat
    export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64
    export JRE_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64/jre
    
    启动、关闭Tomcat

    启动/usr/local/tomcat/bin/startup.sh

    Using CATALINA_BASE:   /usr/local/tomcat
    Using CATALINA_HOME:   /usr/local/tomcat
    Using CATALINA_TMPDIR: /usr/local/tomcat/temp
    Using JRE_HOME:        /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64/jre
    Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
    Tomcat started.
    

    关闭/usr/local/tomcat/bin/shutdown.sh

    手动部署web应用

    方法一

    在conf目录的server.xml中的,找到<host>节点,添加如下标签:

    <Context path="/hello" docBase="/root/helloworld" debug="0" privileged="true">
    </Context>
    
    方法二

    conf/Catalina/localhost目录下创建xml配置文件,文件容易如下:

    <Context path="/hello" docBase="/root/helloworld" debug="0" privileged="true">
    </Context>
    

    此法有个优点,可以定义别名。服务器端运行的项目名称为path,外部访问的URL则使用XML的文件名。这个方法很方便的隐藏了项目的名称,对一些项目名称被固定不能更换,但外部访问时又想换个路径,非常有效。

    参考
    1. Linux——CentOS7使用yum命令安装Java SDK

    相关文章

      网友评论

        本文标题:Centos7 安装java1.7和tomcat7并部署应用

        本文链接:https://www.haomeiwen.com/subject/opszrxtx.html