Java教程

Linux 上安装 Tomcat8

本文主要是介绍Linux 上安装 Tomcat8,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、配置主机

systemctl stop firewalld
systemctl disable firewalld

setenforce poermissive

hostnamectl set-hostname tomcat

二、安装JDK

1.到oracle网站上下载JDK
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html#license-lightbox
2.解压JDK
tar  -xf jdk-8uXXXXX -C /usr/local
ln -s /usr/local/jdk1.8.0_281/ /usr/local/jdk

cat >> /etc/profile <<'EOF'
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/fre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/fre/bin:$PATH
EOF


#测试是否安装成功
java -version

 

 

 

三、安装Tomcat
到tomcat.apache.org上下载Tomcat
https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-8/v8.5.69/bin/apache-tomcat-8.5.69.tar.gz

tar -xf apache-tomcat-8.5.69.tar.gz -C /usr/local/

ln -s /usr/local/apache-tomcat-8.5.69/ /usr/local/tomcat

/usr/local/tomcat/bin/startup.sh
/usr/local/tomcat/bin/shutdown.sh

登录tomcat,如果能正常登录说明安装成功

http://192.168.2.10:8080/

 

 


四、tomcat开启远程管理Manager App
1.修改/user/local/tomcat/conf/context.xml
将context的如下内容删除
<Context>
<!--
  <!-- Default set of monitored resources. If one of these changes, the -->
  <!-- web application will be reloaded. -->
  <WatchedResource>WEB-INF/web.xml</WatchedResource>
  <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

  <!-- Uncomment this to disable session persistence across Tomcat restarts -->
  <!--
  <Manager pathname="" />
  -->
-->
</Context>

修改context的内容如下:
<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
    allow="^.*$" />
</Context>

 

2.在/usr/local/tomcat/conf/tomcat-users.xml文件末尾增加如下角色及用户
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="tomcat" roles="admin-gui,admin,manager-gui,manager,manager-script"/>


3.配置远程访问manager
在/usr/local/tomcat/conf 目录下的Catalina/localhost目录下新建一个manager.xml文件,写入如下内容:

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


4.然后重启tomcat,登录web管理页面访问manager app

 

 

 

5.如果需要访问host-manager,则要修改如下的内容:

vi /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
    sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
    allow="\d+\.\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>

 

 

这篇关于Linux 上安装 Tomcat8的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!