Blog.csdn.net/qq_38264999… Blog.csdn.net/h273979586/…

Download the latest Tomcat package and deploy tomcat. For the convenience of storing tomcat in /usr/local, decompress the package to the bin directory and start the tomcat service

./startup.sh 
Copy the code

Stop service is this command

./shutdown.sh
Copy the code

When always listening on tcp6 we can use the following solutionAccess it in a browserhttp://IP:8080 if the following information is displayed, Tomcat is successfully deployed

Tomcat Configures user passwords

Configuration file location: /opt/tomcat/conf/tomcat-users. XML Sets the Tomcat account and password

<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" />
Copy the code

This problem occurs if tomcat9 is used

  • (1) Visit the Tomcat home page and find that it can be accessed normally

  • (2) Generally, clicking Manager App at this time will lead to smooth entry, but error 403 appears, and the error page is as follows:

Reading the wrong information should be modified Context. The XML file, after go to online search and experiment eventually found to be in the/usr/soft/tomcat9 / conf/Catalina/localhost under new file Manager. XML

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

Restart Tomcat9 and you can access Manager App normally. Stop and start commands see above.If that doesn’t work, try (1) modifying context.xml directly, where you modify the context tag. Modify before:Revised:(2) When I open my context. XML, I find the following configuration file, which is completely different from the above configuration file. It may be because I use different versions.


      
<! -- 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 are 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>
Copy the code

(3) Change the context. XML directory to /webapps/magager/ meta-INF /context.xml

  • Comment the value tag

Modify before:


      
<! -- 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 are 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>
Copy the code

Revised:


      
<! -- 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 are 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>
Copy the code

Simply comment out RemoteAddrValve and restart Tomcat9 to access Tomcat9 Manager. The first method can be used to see if it is available, but try to use the third method to resolve the problem.

Modify the encoding and decoding character set of the URL address

/usr/local/apache-tomcat-9.0.41/conf//server. XML add URIEncoding=” utF-8″

<Connector port="8080" protocol="HTTP / 1.1" 
connectionTimeout="20000" 
redirectPort="8443" URIEncoding="UTF-8"/>
Copy the code