In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
I. introduction to Tomcatl
Tomcat is a core project of the Jakarta project of the Apache Software Foundation (Apache Software Foundation), which is jointly developed by Apache, Sun and other companies and individuals. With the participation and support of Sun, the latest Servlet and JSP specifications are always reflected in Tomcat, and Tomcat 5 supports the latest Servlet 2.4 and JSP 2.0 specifications. Because of its advanced technology, stable performance and free, Tomcat is deeply loved by Java enthusiasts and recognized by some software developers, and has become a popular Web application server.
II. Tomcat components and their characteristics tomcat components
Servlet (application or container) is a component provided by java for developing web server applications. It runs on the server side. Servlet is used to generate dynamic page content. Servlet is a java class on the platform. To write a servlet is actually to install the servlet specification and write a java class.
What is servlet?
The process of dealing with requests and responses in Tomcat is completed by servlet programs, and servlet is derived from the implementation of dynamic pages as an example, similar to the process that nginx or apache needs to communicate with php servers to implement dynamic pages. Servlet can be compared to php.
Tomcat is a web application server, a servlet/jsp container, tomcat as a servlet container, is responsible for processing customer requests and transmitting servlet responses to customers, while servlet is a component running on a server in java language. The most common use of servlet is to extend java web server functions, providing very secure and portable (packaged web code can run in another environment, such as linux system and windows environment) Easy to use cgi substitutes.
The flow of data processing in Tomcat
1.Tomcat is a process running in JVM. It is defined as [middleware], which, as its name implies, is an intermediate container between a Java project and JVM.
The essence of the 2.Web project is a pile of resource files and methods. The Web project does not have an entry method (main method), which means that the methods in the Web project do not run automatically.
The purpose of deploying the 3.Web project into Tomcat's webapp is clear, and that is to expect Tomcat to call
The written method to return the required resources and data for the client.
4. Tomcat can run and call the written method. Then Tomcat must have a main method.
5. As far as Tomcat is concerned, it does not know what kind of methods we will have, which are only determined after the project is deployed under webapp. Therefore, it is necessary to use the reflection of Java to realize the dynamic loading, instantiation, obtaining and calling methods of the class. But the Web project that we deploy to Tomcat must be written according to the specified interface in order to call the
How does 6.Tomcat determine which method to call. This is taken from the client request, http://127.0.0.1:8080/JayKing.Tomcat.Study/index.java?show such a request, through the http protocol, sent to port 8080 in the browser, carrying the parameter show method, including the path of this method is JayKing.Tomcat.Study, the file name is: index.java.
1. The browser sends request data
2. Tomcat receives the request data from the server, which is processed and parsed by the servlet container, and changes the client's data request request to the servlet instance (or object) instance at the back end to receive the request data from the client, processes the client's request, and responds the data to the servlet container after processing, which is called servlet response to the servlet container.
3. Send the response data of the instance received by Servlet to the client (as shown in the figure)
The Servlet (tomcat) container and the servlet instance need to communicate through the java servlet api interface, which is defined or written by the developer when writing the code.
The 4.servlet container delivers the received response data to the client
The difference between Servlet and jsp
Servlet can dynamically output HTML content through HttpServletResponse objects in Java code.
JSP embeds Java code in static HTML content, and then Java code generates a HTML page after it is executed dynamically
Characteristics of tomcat
The running time takes up small resources, has good expansibility, and supports the functions commonly used in developing application systems, such as load balancing and mail servers.
three。 Install tomcat
Download the software packages required for Tomcat
Installation of Tomcat requires the system Java environment version 1.8 or above, Centos 7 has been supported by default Java environment version 1.8, as most of the current use of Centos 6 system, because I use the Centos 7 system, so first need to uninstall the JDK environment. [root@localhost ~] # rpm-qa | grep jdk\\ query the installed jdk package copy-jdk-configs-1.2-1.el7.noarchjava-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64java-1.7.0-openjdk-1.7.0.111-2.6.7. 8.el7.x86_64java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 [root@localhost ~] # rpm-e java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64 java-1.8.0-openjdk-headless -1.8.0.102-4.b14.el7.x86_64-- nodeps\\ Uninstall the jdk environment that comes with the system [root@localhost] # tar zxf jdk-8u211-linux-x64.tar.gz-C / usr/local/ [root@localhost ~] # vim / etc/profile// write system environment variables Add the following export JAVA_HOME=/usr/local/jdk1.8.0_211 / / to the last line to specify the path to java export JRE_HOME=/usr/local/jdk1.8.0_211/jre / / java runtime export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar / / declare classes in java A class is a property of a kind of transaction. For example, the final attribute of all kinds of covered rice is rice export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH / / add the defined variables to the system environment variables [root@localhost ~] # source / etc/profile / / reload the system Environment variable file [root@localhost ~] # tar zxf apache-tomcat-8.5.35.tar.gz [root@localhost ~] # mv apache-tomcat-8.5.35 / usr/local/tomcat [root@localhost ~] # / usr/local/tomcat/bin/startup.sh\\ launch tomcatUsing CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usr/local/jdk1.8.0_211/jreUsing CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarTomcat started. [root@localhost ~] # netstat-anpt | grep 8080tcp6 0 0:: 8080: * LISTEN 16320/java can now be tested with client access
Tomcat directory description
[root@localhost ~] # ls / usr/local/tomcat/
Bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp workBin: storage of script files for starting or shutting down tomcat on windows or linux platforms Conf: stores the global configuration files of the tomcat server, the most important of which are the library files (jars) required by server.xml and web.xmlLib:tomcat to run. Log files generated by Logs:tomcat run Temp: temporary files storage directory Work:tomcat working directory Store tomcat runtime compilation configuration file Webapps: Web file storage path Tomcat common configuration file description Server.xml:tomcat main configuration file, you can set port number, domain name or IPWeb.xml: default web app configuration (it can also be understood to implement functions that are not defined in the main configuration file, such as directory traversal Define error page type) Tomcat-users.xml: used to configure the server.xml file structure in the tomcat of users and permissions for managing tomcat
Server: represents the entire container, the top-level element of the instance. There can be only one server element in a configuration file, which can contain multiple service. For example:
/ / means to turn off Tomcat, connect to 8005 using telnet, and enter the shutdown instruction
Service: an independent component that provides a complete jvm. Jvm represents a Java virtual machine, which is a fictional virtual machine that can contain an engine containing multiple connector.
/ / accept all requests accepted by tomcat. If Service name= "apache", it means to accept all requests forwarded by apache.
Connector: interface definition, which is responsible for accepting requests from the client and returning the response structure to the client
/ / port: the port that accepts data; protocol: set the http protocol; / / Connection Timeout: the connection timeout with the client is timed out.-1 means there is no limit on the connection time of the client; / / Redirectport: forward the request to 8443 when the client request is https
Engine: handles client requests and can contain multiple hots
/ / name: is the name of the engine. Default is to look for localhost when processing customer requests.
Host: a defined virtual host that handles all client requests for a specific virtual host
Context: a single web application running in a virtual host
Tomcat processing http request process
Process
The ① user clicks on the web content and the request is sent to local port 8080, which is obtained by the Coyote HTTP/1.1 Connector listening there; ② Connector hands the request to the Engine of the Service where it is located and waits for the response from Engine; ③ Engine gets the request localhost/test/index.jsp, which matches all virtual host Host The ④ Engine matches to a Host named localhost (even if it doesn't match, the request is handed over to the Host for processing, because the Host is defined as the default host for the Engine), and the Host named localhost gets the request / test/index.jsp, matching all the Context it owns. The Host matches the Context with the path / test (if there is no match, the request is handed over to the Context with the path name ""); the Context of ⑥ path= "/ test" gets the request / index.jsp and looks for the corresponding Servlet in its mapping table. Context matches Servlet with URL PATTERN * .jsp, corresponding to the JspServlet class; ⑥ constructs HttpServletRequest objects and HttpServletResponse objects, and calls doGet () or doPost () of JspServlet as parameters. ⑦ Context returns the HttpServletResponse object to Host; ⑧ Host, HttpServletResponse object to Engine; ⑨ Engine, HttpServletResponse object to Connector; ⑩ Connector, HttpServletResponse object to customer Browser; IV. Custom directory [root@localhost ~] # vim / usr/local/tomcat/conf/server.xml\\ add the following explanation Path under the Hostname of zhe: indicate the access path docBase: specify the storage path Debug: specify the debug level 0 output information is the least, 9 provide the most information Reloadable: automatically reload when the web.xml file changes when it is ture No need to restart service CorssContext: for ture, it means that different context shares a session (session pool) [root@localhost ~] # mkdir-p / data/project [root@localhost ~] # vim / data/project/index1.jspaaaaaaa [root@localhost ~] # vim / data/project/index2.jspbbbbbbb to enable tomcat directory traversal [root@localhost ~] # vim / usr/local/tomcat/conf/web.xml\\ change false to true in about 112 lines
Restart the service [root@localhost ~] # / usr/local/tomcat/bin/shutdown.sh\\ close the service Using CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usr/local/jdk1.8.0_211/jreUsing CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat -juli.jar [root@localhost ~] # / usr/local/tomcat/bin/startup.sh\\ start the service Using CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usr/local/jdk1.8.0_211/jreUsing CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarTomcat started. Client access authentication
five。 Custom monitoring page [root@localhost ~] # vim / usr/local/tomcat/conf/server.xml / / add to host
[root@localhost /] # mkdir / jk/jiankong-p [root@localhost /] # vim / jk/jiankong/index.jsp [root@localhost ~] # / usr/local/tomcat/bin/shutdown.sh [root@localhost ~] # / usr/local/tomcat/bin/startup.sh / / restart tomcat service access as follows
six。 Enable JMX remote debugging function [root@localhost /] # vim / usr/local/tomcat/bin/catalina.sh #-Execute The Requested Command-- / / the content entered must be about 309 lines below this line CATALINA_OPTS= "$CATALINA_OPTS-Dcom.sun.management.jmxremote-Dcom" .sun.management.jmxremote.port = 8888-Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=true "[root@localhost /] # cd / usr/local/jdk1.8.0_211/jre/lib/management/ [root @ localhost management] # cp jmxremote.password.template jmxremote.password [root@localhost management] # vim jmxremote.password / / add on the last line Define the user as xws, password 123456, and use "wq!" Force the file xws readwrite to exit xws 123456 [root@localhost management] # vim jmxremote.access / / to define user permissions\ / / on the penultimate line. Change the original user to xws [root@localhost management] # chmod 600jmxremote.access [root@localhost management] # chmod 600jmxremote.password [root@localhost management] # / usr/local/tomcat/bin/shutdown.sh [root@localhost management] # / usr/local/tomcat/bin/startup.sh [root@localhost ~] # netstat-anpt | grep 8888tcp6 00: 8888:: * LISTEN 58760/java / / confirm that port 8888 just defined is listening because it is an image interface So you need to execute the following command [root@localhost /] # in the desktop environment. / etc/profile\\ Update the environment variable [root@localhost /] # jconsole
seven。 Configure to use https to access the tomcat server [root@localhost /] # keytool-genkey-v-alias tomcat-keyalg RSA-keystore / usr/local/tomcat/conf/tomcat.keystore-validity 36500//alias: alias, here set to tomcat;//keyalg: certificate algorithm, RSA;//validity: certificate validity period, unit is day / / keystore: specify the certificate storage path, you can customize the keystore password: enter the new password again: what is your first name and last name? [Unknown]: xws what is the name of your organizational unit? [Unknown]: aaa what is the name of your organization? [Unknown]: bbb what is the name of your city or region? [Unknown]: ccc what is the name of your province / municipality / autonomous region? [Unknown]: wwwe what is the two-letter country code for this unit? [Unknown]: is qweCN=xws, OU=aaa, O=bbb, L=ccc, ST=wwwe, C=qwe correct? [no]: y is generating a 2048-bit RSA key pair and self-signed certificate (SHA256withRSA) (valid for 36500 days) for the following objects: key password entered by CN=xws, OU=aaa, O=bbb, L=ccc, ST=wwwe, C=qwe (press enter if the password is the same as the KeyStore password): [storing / usr/local/tomcat/conf/tomcat.keystore] Warning:JKS KeyStore uses a special format. It is recommended that you use "keytool-importkeystore-srckeystore / usr/local/tomcat/conf/tomcat.keystore-destkeystore / usr/local/tomcat/conf/tomcat.keystore-deststoretype pkcs12" to migrate to the industry standard format PKCS12. [root@localhost ~] # vim / usr/local/tomcat/conf/server.xml / / can be added or slightly modified from the original content / / specify the password [root@localhost ~] # / usr/local/tomcat/bin/shutdown.sh [root@localhost ~] # / usr/local/tomcat/bin/startup.sh entered to generate the certificate as follows:
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.