In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Tomcat Total Raiders
What is 1.tomcat?
Tomcat server is a free and open source Web application server, which was originally called catalina, but was later developed by Apache, Sun and other companies and individuals, and renamed Tomcat. Tomcat is an application (java) server, it is a servlet container, it is an extension of Apache, but it runs independently. Tomat is used in Java Servlet, JavaServer Pages,Java Expression Language and other Javaweb development technologies.
The Apache Tomcat software is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. The Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket specifications are developed under the Java Community Process.The Apache Tomcat software is developed in an open and participatory environment and released under the Apache License version 2. The Apache Tomcat project is intended to be a collaboration of the best-of-breed developers from around the world. We invite you to participate in this open development project. To learn more about getting involved, click here.
Apache Tomcat software powers numerous large-scale, mission-critical web applications across a diverse range of industries and organizations. Some of these users and their stories are listed on the PoweredBy wiki page.
Apache Tomcat, Tomcat, Apache, the Apache feather, and the Apache Tomcat project logo are trademarks of the Apache Software Foundation.
-- from http://tomcat.apache.org/
2.tomcat yum installation
1.yum install jdk
Yum install-y java-1.8.0-openjdk java-1.8.0-openjdk-devel
2.yum install tomcat
Yum install-y tomcat, tomcat-lib, tomcat-admin-webapps, tomcat-webapps, tomcat-docs-webapp
3.tomcat rpm package environment
1. View the way the program environment
Rpm-ql tomcat
two。 Environment introduction
Configuration file directory: / etc/tomcat
Master profile: server.xml
Webapps storage location: / var/lib/tomcat/webapps/
Examples
Manager
Host-manager
Docs
Unit File:tomcat.service
Environment profile: / etc/sysconfig/tomcat
4.tomcat configuration file composition
Server.xml: main profile
Web.xml: each webapp can only be accessed after "deployment". Its deployment method is usually defined by web.xml and its storage location is in the WEB-INF directory. The web.xml file provides default deployment-related configuration for all webapps.
Context.xml: each webapp can have a dedicated configuration file, which is usually defined by a dedicated configuration file context.xml, which is stored in the WEB-INF directory; the context.xml file provides the default configuration for all webapps
Tomcat-users.xml: account and password file authenticated by the user
Catalina.policy: used to set security policy for tomcat when tomcat is started with the-security option
The definition file for the catalina.properties:Java attribute, which is used to set the classloader path and some parameters related to JVM tuning
Logging.properties: log system-related configuration
Core component of 5.Tomcat: server.xml
... Engine >
Each component is implemented by a Java "class", which can be broadly divided into the following types:
Top-level component: Server
Service component: Service
Connector components: http, https, ajp (apache jserv protocol)
Container classes: Engine, Host, Context
Nested classes: valve, logger, realm, loader, manager,...
Cluster class components: listener, cluster,...
6.JSP WebAPP introduction
Tomcat can run JSP WebAPP. Now the mainstream large-scale web e-commerce web services are developed with JSP. Here is an introduction to JSP WebAPP.
6.1 organizational structure of JSP WebAPP
/: root directory of webapps
Index.jsp: home page
The private resource path of WEB-INF/: 's current webapp; typically used to store the web.xml and context.xml configuration files of the current webapp
META-INF/: is similar to WEB-INF/
Classes/: class file, the class provided by the current webapp
The lib/: class file, which is currently provided by webapp, is packaged in jar format
6.2 webapp Archive format
.war: webapp
.jar: class package file for EJB
.rar: resource adapter class package file
.ear: enterprise webapp
6.3 related operations to deploy (deploy) webapp:
Deploy: place the source files of webapp in the target directory (the directory where web program files are stored), and configure the tomcat server to access this webapp; based on the paths defined in web.xml and context.xml files. Load its unique and dependent classes to JVM through class loader
There are two ways to deploy:
1. Automatic deployment: auto deploy
two。 Manual deployment:
2.1Cold deployment: copy webapp to the specified location (tomcat installed by rpm at / var/lib/tomcat/webapps) before starting tomcat
2.2Hot deployment: deploy without stopping tomcat
Hot deployment tools include: manager, ant script, tcd (tomcat client deployer), etc.
Undeploy: anti-deployment, stop webapp, and uninstall webapp from the tomcat instance
Start: starts the webapp in the stopped state
Stop: stop webapp and no longer provide services to users; its class is still on jvm
Redeploy: redeploy
6.4 provide a test application manually and deploy it cold:
Mkidr-pv / usr/local/tomcat/webapps/test/ {classes,lib,WEB-INF} # create JSP WebAPP-related directories and file vi / usr/local/tomcat/webapps/test/index.jsp # manually create a WebAPP application Test Page
6.4.1 access test through browser
Configuration of common components of 7.Tomcat
7.1 Server
Stands for tomcat instance, that is, a java process shown; listens on port 8005 and only receives "SHUTDOWN". The listening ports of each server cannot be the same. Therefore, when starting multiple instances on the same physical host, you need to modify their listening ports to different ports.
7.2 Service
Used to associate one or more connector components to an engine component
7.3 Connector components
Responsible for receiving requests, there are three common types of http/https/ajp
Requests to enter the tomcat can be divided into two categories:
(1) standalone: the request comes from the client browser
(2) replaced by other web server: the reverse server from the front end. Here are four scenarios.
Nginx-- > http connector-- > tomcathttpd (proxy_http_module)-- > http connector-- > tomcathttpd (proxy_ajp_module)-- > ajp connector-- > tomcathttpd (mod_jk)-- > ajp connector-- > tomcat
Connector attribute:
Port= "8080"
Protocol= "HTTP/1.1"
ConnectionTimeout= "20000"
Address: the IP address of the listener; default is all available addresses on the machine
MaxThreads: maximum number of concurrent connections. Default is 200.
EnableLookups: whether to enable the DNS query feature
AcceptCount: the maximum length of the waiting queue
Secure: security related
SslProtocol:ssl security protocol
7.4 Engine components
A Servlet instance, or servlet engine, can define a site internally with one or more host components; usually a default virtual host is defined through defaultHost
Attributes:
Name=
DefaultHost= "localhost"
JvmRoute=
7.5 Host components
A host or virtual host located inside the engine to receive requests and process them accordingly, for example:
Common attribute description:
(1) appBase: the default storage directory for the webapps of this Host, which refers to the directory where non-archived web applications are stored or the path to the WAR file that is archived; you can use the relative path based on the path defined by the $CATALINA_BASE variable
(2) autoDeploy: when a webapp is placed in a directory defined by appBase when Tomcat is running, whether it is automatically deployed to tomcat
Example 1:
Mkdir-pv / appdata/huwho # create a directory where webapps is stored mkdir-pv / appdata/huwho/ROOT/ {lib,classes,WEB-INF} # create a file related to webapp vi / appdata/huwho/ROOT/index.jsp # provide a test page to Test Page
Access the test through the browser:
Sample 2:JSP WebAPP deployment application
Note: do this experiment on the basis of example 1, make sure the directory is at / appdata/huwho, do the following
Download this package: shopxx-a5-Beta.zip
Decompress: unzip shopxx-a5-Beta.zip
Create a soft link: ln-sv shop shopxx-v3.0-Beta
Browser access test
7.6 Context components
The Context component is the innermost component, which represents the Web application itself. The most important thing to configure a Context is to specify the root directory of the Web application so that the Servlet container can send user requests to the correct location.
Official example:
Add context component content based on the above experiment
Vi / etc/tomcat/server.xml mkdir-pv / e-shop cd / e-shop mv shopxx-v3.0-Beta / e-shop/ ln-sv eshop shopxx-v3.0-Beta
Browser access test
7.7 Valve components
Used to intercept a request and perform some processing before moving it to the target, similar to the filter defined in the Servlet specification.
There are many types of Valve:
Define the access log:
Org.apache.catalina.valves.AccessLogValve
Define access control:
Org.apache.catalina.valves.RemoteAddrValve
Two Management applications of 8.Tomcat
Tomcat has its own management application, and we only need to configure it to enable it.
One is manager, the other is host-manager.
Add the following three lines to the vi tomcat-users.xml # configuration file to open the tomcat management application
Once configured, let's have a look at it through the browser. Click on the location identified in the figure to enter the management center.
Prompt for account number and password. According to the account password configured by the configuration file, enter it.
View the administration page
9.Tomcat cluster deployment
9.1 nt (nginx+tomcat)
1.nginx reverse proxy Tomcat example
Server {server_name www.huwho.cn; listen 80; location / {proxy_pass http://192.168.0.13:8080;} location ~ *\. (jsp | do) {proxy_pass http://192.168.0.13:8080;}
Open the browser to test, the nginx agent succeeded
2.nginx load balancing reverse proxy Tomcat example
Add the following to the paragraph vi / etc/nginx/nginx.conf # http {}: upstream tcsrvs {# hash $request_uri consistent; server 192.168.0.13 upstream tcsrvs 8080; server 192.168.0.14 upstream tcsrvs 8080;} vi / etc/nginx/conf.d/huwho.conf server {server_name www.huwho.com; listen 80 Location / {proxy_pass http://tcsrvs;}}
Open the browser to test, the web page is accessed normally, and you can access two Tomat hosts.
9.2 at (httpd+tomcat)
1.httpd reverse proxy Tomat example
Vi / etc/httpd/conf.d/huwho.conf ServerName www.huwho.cn ProxyRequests Off ProxyVia On ProxyPreserveHost On Require all granted ProxyPass / http://192.168.0.13:8080/ ProxyPa***everse / http://192.168.0.13:8080/ Require all granted
Sample 2.proxy_http_module proxy configuration (proxy + load balancing)
Cat httpd-tomcat.huwho.conf BalancerMember http://192.168.0.13:8080 loadfactor=1 BalancerMember http://192.168.0.14:8080 loadfactor=2 ProxySet lbmethod=byrequests ServerName www.huwho.cn ProxyRequests Off ProxyVia On ProxyPreserveHost On Require all granted ProxyPass / balancer://tcsrvs/ ProxyPa*** Everse / balancer://tcsrvs/ Require all granted SetHandler balancer-manager ProxyPass! Require ip 10.0.0.1
Open the browser to test, the web page is accessed normally, and you can access two Tomat hosts.
3. Proxy_ajp_module proxy configuration example (proxy + load balancer)
[root@httpd conf.d] # cat http-ajp-huwho.conf BalancerMember ajp://192.168.0.13:8009 BalancerMember ajp://192.168.0.14:8009 ProxySet lbmethod=byrequests ServerName ajp.huwho.cn ProxyRequests Off ProxyVia On ProxyPreserveHost On Require all granted ProxyPass / balancer://ajsrvs/ ProxyPa***everse / balancer://ajsrvs/ Require all granted
Open the browser to test, the web page is accessed normally, and you can access two Tomat hosts.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.