zoukankan      html  css  js  c++  java
  • CentOS下安装Tomcat环境

    一、安装JAVA环境

    1.安装JAVA

    mkdir -p /usr/local/java

    下载jdk1.7.0_67.tar.gz包,并解压到

    tar xf jdk1.7.0_67.tar.gz -C  /usr/local/java

    2.配置环境变量

    cd /etc/profile.d
    vim java.sh
    export JAVA_HOME=/usr/local/java/jdk1.7.0_67
    export CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
    export PATH=$PATH:$JAVA_HOME/bin
    

     

    让配置生效:

    source /etc/profile
    

      

    安装与配置比较简单。执行java -version命令,出现类似界面表示成功。

    二、安装Tomcat环境

    1、下载安装包

    wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar.gz
    tar xf apache-tomcat-8.5.31.tar.gz -C /usr/local/
    cd /usr/local/
    ln -sv apache-tomcat-8.5.31 tomcat

    2.配置环境变量

    vim /etc/profile.d/tomcat.sh

    CATALINA_BASE=/usr/local/tomcat
    PATH=$CATALINA_BASE/bin:$PATH
    export PATH CATALINA_BASE
    

      

    让配置生效:

    source  /etc/profile.d/tomcat.sh
    

      

    3.查看tomcat版本状态

    catalina.sh version

    三、配置tomcat

    1.配置server.xml

    /usr/local/tomcat/conf/server.xml (修改配置文件里面的端口号,修改为自己想要开放的端口)

     <Connector port="80" protocol="HTTP/1.1"      //默认端口为8080,改为自己想要开放的端口
                connectionTimeout="20000"
                redirectPort="8443" />
    

      

    2.配置tomcat-users.xml和webapps/manager/META-INF/context.xml和webapps/host-manager/META-INF/context.xml

    tomcat有manager-gui的管理页面,想要使用必须配置管理用户,不使用可以跳过此步。

    <role rolename="manager-gui"/>                                        //指定用户可以使用的接口为manager-gui
    <user username="tomcat" password="tomcat" roles="manager-gui"/>      //用户名和密码为tomcat,在manager-gui接口使用
    

      

    cat  webapps/manager/META-INF/context.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <Context antiResourceLocking="false" privileged="true" >
    <!--
      <Valve className="org.apache.catalina.valves.RemoteAddrValve"
             allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />         #可以改为本机的IP地址。默认为127.0.0.1,所以我们访问的时候不行。
    -->
      <Manager sessionAttributeValueClassNameFilter="java.lang.(?:Boolean|Integer|Long|Number|String)|org.apache.catalina.filters.CsrfPreventionFilter$LruCache(?:$1)?|java.util.(?:Linked)?HashMap"/>
    </Context>
    

     

    四、测试 

    1.创建测试页面

    /usr/local/tomcat/webapps/test/index.jsp

    <%@ page language="java" %>
    <%@ page import="java.util.*" %>
    <html>
        <head>
            <title>test</title>
        </head>
        <body>
            <%
                out.println("Hello World!");      //嵌入java语言
            %>
        </body>
    </html>
    

      

    2.启动测试

    catalina.sh start

    用浏览器打开页面。

    a、主页

    b、Server Status

    c、HostManager

     d、最后访问应用,Hellow World!

     至此,tomcat的测试环境搭建完成。

  • 相关阅读:
    小贝_mysql 存储过程
    Codeforces Round #253 (Div. 1)-A,B
    rac环境改动spfile后遭遇ora-29250小例
    Linux学习笔记——例说makefile 索引博文
    《信息检索》课程论文撰写指南 及 分享加分说明
    git mirror的创建与使用
    一起talk GDB吧(第二回:GDB单步调试)
    nginx源代码分析--配置信息的继承&amp;合并
    EasyUI基础入门之Droppable(可投掷)
    自己动手写CPU之第七阶段(5)——流水线暂停机制的设计与实现
  • 原文地址:https://www.cnblogs.com/skyflask/p/9023749.html
Copyright © 2011-2022 走看看