Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation, configuration and use of Tomcat services

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

On the basis of introducing the installation, configuration and use of Tomcat service, this paper focuses on its concrete steps, which are simple and easy to operate, and the content of the article is compact step by step. I hope you can get something from this article.

Jdk installation jdk download address: http://www.oracle.com/technetwork/java/javase/downloads/index.html1) decompress and configure the environment variable # cd / usr/local/src/#tar xf jdk-8u231-linux-x64.tar.gz#ln-s jdk1.8.0_231/ jdk#cat > / etc/profile.d/jdk.sh / usr/lib/systemd/system/tomcat.service directoryAJP (Apache Jserv protocol) is a binary communication protocol based on TCP. The core component indicates that Tomcat starts a Server process. You can start multiple Server, but generally only start one to create one Service to provide services. You can create multiple Service, but generally create only one per Service. The associated configuration of Engine and its connector Connector can provide multiple connector Connector for this Server. These Connector use different protocols and bind different ports. Its function is to handle different connection requests or responses from the client. Engine is also defined within the Service, and the engine is the real entrance to the request. The internal definition of multiple virtual hosts HostEngine analyzes the request header and sends the request to the corresponding virtual host. If there is no match, the data is sent to the default virtual host on the Engine, the default virtual host on the Engine, which can modify the Host to define the virtual host. The virtual host has a name name, and the process of defining the application's separate path mapping by name matching Context and configuring Tomcat to handle requests assumes that the request from the customer is: tomcat 1) the request from the browser side is sent to the server port 808080tomcat process listening on this port. This request is obtained through the listening HTTP/1.1 Connector. 2) Connector hands the request to the Engine of the Service where it is located and waits for the response of Engine. 3) Engine gets the request localhost:8080/test/index.jsp, matching all its virtual hosts Host 4) Engine matches to the Host named localhost. Even if there is no match, the request is handed over to the Host for processing, because the Host is defined as the default host of the Engine. 5) localhost Host gets the request / test/index.jsp, matches all the Context it owns. 6) Host matches to Context 7) path=/test with path / test get request / index.jsp, look in its mapping table for corresponding servlet 8) Context matches servlet with URL PATTERN = * .jsp, corresponding to JspServlet class to construct HttpServletRequest object and HttpServletResponse object Call the doGet or doPost method of JspServlet as a parameter. 9) Context returns the HttpServletResponse object after execution to Host 10) Host returns the HttpServletResponse object to Engine 11) Engine returns the HttpServletResponse object to Connector 12) Connector returns the HttpServletResponse object to the browser application deployment root directory Tomcat the default website root directory is CATALINA_BASE/webapps/, in the Tomcat webapps directory, there is a very special directory ROOT, which is the website default root directory. The directory of each virtual host can be configured with its own site directory using appBase, and the ROOT directory can be used as the home directory. JSP WebApp directory structure home page configuration: generally specified as the private resource path of the current WebApp of index.jsp or index.htmlWEB-INF/:, and usually stores the web.xml and context.xml configuration files used by the current application META-INF/: is similar to the WEB-INFclasses/: class file, the current webapp needs class lib/: the current application depends on the jar package to change the default home page file, by default, visit the home page of Tomcat The returned content is provided by the CATALINA_BASE/webapps/ROOT/index.jsp file. Here, an index.html file will be added under CATALINA_BASE/webapps/ROOT/, as follows: # cat/ usr/local/src/tomcat/webapps/ROOT/index.html tomcat index.html add the contents of the file before visiting the Tomcat default page The returned result is as follows: # curl localhost:8080tomcat index.html produces the above result because of the tag content (default page) in the CATALINA_BASE/conf/web.xml file. Copy it to CATALINA_BASE/webapps/ROOT/WEB-INF/web.xml. After the following Welcome to Tomcat Welcome to Tomcat index.jsp index.htm index.html configuration is modified, visit the home page again. The result is as follows

From the above verification results, it can be found that the default page access order of Tomcat is the webapp archive format matched from top to bottom. War: WebApp packaged .jar: EJB class packaged file .rar: resource adapter class packaged file .ear: enterprise WebApp packaged traditional application development testing, usually packaged into war format, this kind of file is deployed under the webapps of Tomcat, and can also be automatically expanded. Deploy Deploy deployment: place the source files of the webapp in the target directory, access the webapp through the paths configured in the web.xml and context.xml files, and load its unique and dependent classes on the JVM through the class loader. Automatic deployment Auto Deploy:Tomcat loads this application and starts it to deploy cold deployment manually: put webapp to the specified directory before starting Tomcat hot deployment: Tomcat service does not stop, you need to rely on manager, ant scripts, tcd (tomcat client)

Tools such as deployer) undeploy undeploy: stop running webapp, remove loaded classes from JVM, remove deployed files from Tomcat application directory, start start: webapp can access stop stop:webapp can't access, can't provide services, but JVM doesn't clear it experiment 1 add a test.jsp file jsp example is the server-side dynamic generation of strings, and finally spliced together

Put test.jsp under ROOT, and then visit http://YourIP:8080/test.jsp. You can immediately see that this is converted to test_jsp.java after finding the corresponding test.jsp through path mapping. Then compiled into the test_jsp.classCATALINA_BASE/work/Catalina/localhost/ROOT/org/apache/jsp/ directory with converted files 2 add an application simulation deployment an application common development project directory composition structure # mkdir projects/myapp/ {WEB-INF,classes,lib}-p#tree projects/projects/ └── myapp ├── classes ├── lib └── WEB-INF4 directories, 0 files common application home page Use the above test.jsp#cp webapps/ROOT/test.jsp projects/myapp/index.jsp to copy the project directory to the webapps directory # cp-r projects/myapp/ / usr/local/src/tomcat/webapps/ access test http://YourIP:8080/myapp main configuration file

CATALINA_BASE/conf/server.xml

1) Port 8005 this port is the management port of Tomcat, and the default listening is 127.0.0.1. When the string SHUTDOWN is received, the Server is closed. # ss-nlt | grep 8080LISTEN 0 100 [:]: 8080 [:]: * # telnet 127.0.0.1 8005Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is'^ '.SHUTDOWNConnection closed by foreign host. This management function is recommended to be disabled, changing SHUTDOWN to a string that cannot be guessed, such as 2) user authentication

CATALINA_BASE/conf/tomcat-users.xml

If you want to use Manager App, you need a role manager-gui, which is added in the CATALINA_BASE/conf/tomcat-users.xml configuration file, as follows: after Tomcat starts loading, these contents are resident in memory. If a new user is configured, you need to restart Tomcat. Visit Manager App

When visiting manager, tell 403.The prompt tells manager to modify in the context.xml, and the file path CATALINA_BASE/webapps/manager/META-INF/context.xml can see from the configuration file that the regular expression after allow only allows local access, but my current address is 192.168, so you need to add regular expressions to support access. After configuration, the following allow= "127\.\ d +\.\ d + |: 1 | 0VOVOVOV 0VOV 0VERV 0VERV 00VERV 00VERV 0l1 | 192\ .168\.\ d +\.\ d +" access the test again after reboot.

3) Service in general, a Server instance is configured with a Service,name attribute that is equivalent to the ID of the Service. 4) the connector is configured with redirectPort, and automatically redirects to this connector if you access the HTTPS protocol. However, most of the time, Tomcat does not enable HTTPS, because Tomcat is often deployed internally, and HTTPS performance is poor. 5) engine configuration defaultHost points to define a virtual host internally. The default virtual host can be changed, the default localhost. 6) Virtual host configuration description: name # must be a hostname, which is matched by a hostname. AppBase # the web page root directory of the current host is relative to CATALINA_HOME, and you can also use the absolute path unpackWARs # whether to automatically extract the war format autoDeploy # hot deployment, automatically load and run the application virtual host configuration experiment to try to configure another virtual host, and deploy myapp to / data/webapps directory # mkdir / data/webapps-p#cp-r projects/myapp/ / data/webapps/ROOT just defined www.hechunping.com in the host name in the virtual host All domain name resolution access tests need to be added to the hosts file of the host

Context configuration Context action path mapping applies independent configuration, such as separate configuration of application log and application access control configuration description: path # refers to the access path docBase # can be an absolute path or a relative path (relative to the appBase of Host) reloadable # true means that if there are changes to the .class file in the WEB-INF/classes or META-INF/lib directory, the WEB application will be reloaded, which will consume a lot of performance. In a production environment, false is used to disable it. Copy the project file under projects/myapp to / data/ # cp-r projects/myapp/ / data/myapp_v1#cd / data/#ln-s myapp_v1/ test add the following content access test http://www.hechunping.com:8080/test/ to the main configuration file server.xml of Tomcat

Note: soft links are especially used here because when future versions are upgraded, you need to point the soft link to myapp_v2 and restart Tomcat. If there is a problem after the new version is launched, modify the soft link to the previous version of the directory, and restart, you can achieve rollback.

So much for the installation, configuration and use of Tomcat services. I hope the above can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report