CentOS下安装Tomcat环境

目录

一、安装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的测试环境搭建完成。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值