CentOS下安装Tomcat环境

作者:@skyflask
转载本文请注明出处:https://www.cnblogs.com/skyflask/p/9023749.html


目录

一、安装JAVA环境
二、安装Tomcat环境
三、配置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.配置环境变量

1
2
3
4
5
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

 

让配置生效:

1
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

1
2
3
CATALINA_BASE=/usr/local/tomcat
PATH=$CATALINA_BASE/bin:$PATH
export PATH CATALINA_BASE

  

让配置生效:

1
source  /etc/profile.d/tomcat.sh

  

3.查看tomcat版本状态

catalina.sh version

三、配置tomcat

1.配置server.xml

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

1
2
3
<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的管理页面,想要使用必须配置管理用户,不使用可以跳过此步。

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

  

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?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

1
2
3
4
5
6
7
8
9
10
11
12
<%@ 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的测试环境搭建完成。

posted @   skyflask  阅读(40223)  评论(2编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示