阅读 279

linux安装tomcat

blog.csdn.net/qq_38264999… blog.csdn.net/h273979586/…

下载最新的tomcat包并部署tomcat,为了方便还是放到/usr/local,解压 进入bin目录开启服务

./startup.sh 
复制代码

在这里插入图片描述

停止服务是这个命令

./shutdown.sh
复制代码

当出现总是监听tcp6时我们可以用以下方法解决 在这里插入图片描述 在浏览器中访问http://IP:8080,出现如下说明tomcat部署成功 在这里插入图片描述

tomcat配置用户密码

配置文件位置:/opt/tomcat/conf/tomcat-users.xml 设置tomcat账号和密码

<role rolename="manager-gui"/> 
<role rolename="manager-script"/> 
<role rolename="manager-jmx"/> 
<role rolename="manager-status"/> 
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status" />
复制代码

如果是tomcat9,会遇到该问题

  • (1)访问tomcat首页,发现可以正常访问

在这里插入图片描述

  • (2)一般这个时候点击Manager App会顺利进入,但出现403的错误,错误页面如下:

在这里插入图片描述

看报错信息应该是修改Context.xml文件,经过去网上查找和实验最终发现是要在/usr/soft/tomcat9/conf/Catalina/localhost下新建文件Manager.xml

<Context privileged="true" antiResourceLocking="false"
         docBase="${catalina.home}/webapps/manager">
    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>
复制代码

重新启动Tomcat9就可以正常访问Manager App了。停止和启动命令看上面。 在这里插入图片描述 如果还不行,试一下其他方法 (1)直接修改context.xml,在其中修改Context标签。 修改前: 在这里插入图片描述 修改后: 在这里插入图片描述 (2)打开我的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.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>
 
    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
</Context>
复制代码

(3)修改的context.xml目录为/webapps/magager/META-INF/context.xml

  • 注释value标签

修改前:

<?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" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
复制代码

修改后:

<?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" />-->
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
复制代码

只需要注释掉RemoteAddrValve,重启Tomcat9即可正常访问Tomcat9 Manager,第一种方法可以尝试是否可用,但尽量使用第三种方法解决不能访问问题。

修改 URL 地址的编码解码字符集

打开/usr/local/apache-tomcat-9.0.41/conf//server.xml 加上URIEncoding="UTF-8"

<Connector port="8080" protocol="HTTP/1.1" 
connectionTimeout="20000" 
redirectPort="8443" URIEncoding="UTF-8"/>
复制代码
文章分类
后端
文章标签