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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM