CentOS下安裝Tomcat環境

1、安裝JAVA環境

1.安裝JAVA

mkdir -p /usr/local/javahtml

下載jdk1.7.0_67.tar.gz包,並解壓到java

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

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

 

讓配置生效:express

source /etc/profile

  

安裝與配置比較簡單。執行java -version命令,出現相似界面表示成功。apache

 

2、安裝Tomcat環境

一、下載安裝包

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 tomcatvim

2.配置環境變量

vim /etc/profile.d/tomcat.sh瀏覽器

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

  

讓配置生效:

tomcat

source  /etc/profile.d/tomcat.sh

  

3.查看tomcat版本狀態

catalina.sh versionbash

3、配置tomcat

1.配置server.xml

/usr/local/tomcat/conf/server.xml (修改配置文件裏面的端口號,修改成本身想要開放的端口)session

 <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>

 

4、測試 

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的測試環境搭建完成。

相關文章
相關標籤/搜索