Tomca
Tomca 简介
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求。实际上Tomcat是Apache 服务器的扩展,但运行时它是独立运行的,所以当你运行tomcat 时,它实际上作为一个与Apache 独立的进程单独运行的。
Tomcat是一个免费的开源的Serlvet容器,用来运行java程序的容器
是开发和调试Servlet(Server Applet)、JSP(Java Server Pages) 程序的首选;
Tomcat就是传说中的中间件之一,tomcat本身是一个容器,专门用来运行java程序,java语言开发的网页.jsp就应该运行于tomcat中,而tomcat本身的运行也依赖于jdk环境。
//常见的中间件:
一般本地开发的话,小项目,或者是个人开发建议使用tomcat;
linux系统建议使用jetty或apache hpppd;
大型的项目就用JBOSS或webloigc;
大项目或者商业项目一般采用:weblgoic/webshere,其他的还有jboss、glasshfish等;
一些示例项目或者小项目常采用jetty;
tomcat , jboss, weblogic, websphere 一般项目tomcat就可以了。
Tomca部署
[root@node1 ~]# hostnamectl hostname tomcat
[root@node1 ~]# bash
[root@tomcat ~]# yum -y install java-11-openjdk tar
[root@tomcat ~]# ls
anaconda-ks.cfg apache-tomcat-10.0.23.tar.gz -e -i.bak
[root@tomcat ~]# tar -zxvf apache-tomcat-10.0.23.tar.gz -C /usr/local/
[root@tomcat ~]# cd /usr/local/
[root@tomcat local]# ls
apache-tomcat-10.0.23 bin etc games include lib lib64 libexec sbin share src
[root@tomcat local]# ln -s apache-tomcat-10.0.23/ tomcat
[root@tomcat local]# ls -l
total 4
drwxr-xr-x 9 root root 4096 Aug 23 23:29 apache-tomcat-10.0.23
drwxr-xr-x. 2 root root 6 May 16 2022 bin
drwxr-xr-x. 2 root root 6 May 16 2022 etc
drwxr-xr-x. 2 root root 6 May 16 2022 games
drwxr-xr-x. 2 root root 6 May 16 2022 include
drwxr-xr-x. 2 root root 6 May 16 2022 lib
drwxr-xr-x. 3 root root 17 Jul 11 13:57 lib64
drwxr-xr-x. 2 root root 6 May 16 2022 libexec
drwxr-xr-x. 2 root root 6 May 16 2022 sbin
drwxr-xr-x. 5 root root 49 Jul 11 13:57 share
drwxr-xr-x. 2 root root 6 May 16 2022 src
lrwxrwxrwx 1 root root 22 Aug 23 23:30 tomcat -> apache-tomcat-10.0.23/
[root@tomcat local]#
测试网页
[root@tomcat ~]# mkdir /usr/local/tomcat/webapps/test
[root@tomcat ~]# cd /usr/local/tomcat/webapps/test/
[root@tomcat test]# vim index.jsp
[root@tomcat test]# cat index.jsp
<html>
<head>
<title> test page </title>
</head>
<body>
<%
out.println("hell world");
%>
</body>
</html>
[root@tomcat test]#
启动
[root@tomcat bin]# pwd
/usr/local/tomcat/bin
[root@tomcat bin]# ls
bootstrap.jar ciphers.sh daemon.sh migrate.bat shutdown.sh tool-wrapper.bat
catalina.bat commons-daemon.jar digest.bat migrate.sh startup.bat tool-wrapper.sh
catalina.sh commons-daemon-native.tar.gz digest.sh setclasspath.bat startup.sh version.bat
catalina-tasks.xml configtest.bat makebase.bat setclasspath.sh tomcat-juli.jar version.sh
ciphers.bat configtest.sh makebase.sh shutdown.bat tomcat-native.tar.gz
[root@tomcat bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@tomcat bin]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 *:8080 *:*
[root@tomcat bin]#
解决 Server Status Manager App Host Manager 无法进去的问题
Host Manager
[root@tomcat ~]# vim /usr/local/tomcat/conf/tomcat-users.xml
<role rolename="admin-gui"/>
<user username="tomcat" password="123456" roles="admin-gui"/>
</tomcat-users>
[root@tomcat ~]# vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
// 添加 192\.168\.100\.\d
<Context antiResourceLocking="false" privileged="true" >
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="192\.168\.100\.\d+|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>
[root@tomcat bin]# ./shutdown.sh
[root@tomcat bin]# ./startup.sh
Server Status Manager App
Server Status
Manager App
[root@tomcat bin]# vim /usr/local/tomcat/conf/tomcat-users.xml
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="123456" roles="admin-gui,manager-gui"/>
[root@tomcat bin]# vim /usr/local/tomcat/webapps/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="192\.168\.100\.\d+|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>
~
----------------------------------------------------------------
[root@tomcat bin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@tomcat bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@tomcat bin]#
Server Status
Manager App