In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
JAVA Enterprise Application TOMCAT practice 1. Introduction to Tomcat
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.
Tomcat server is a free and open source Web application server, which is a lightweight application server. It is widely used in small and medium-sized systems and not many concurrent access users. It is the first choice for developing and debugging JSP programs.
Tomcat and Nginx, Apache (httpd), lighttpd and other Web servers, has the function of dealing with HTML pages, in addition, it is also a Servlet and JSP container, independent Servlet container is the default mode of Tomcat. However, Tomcat is not as capable of handling static HTML as Nginx/Apache servers.
What is the difference between comparing php software?
Currently, the latest version of Tomcat is 9.0. Java containers also include resin, weblogic, and so on.
2. Tomcat installation 2.1Software preparation
JDK download: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Tomcat download: http://tomcat.apache.org/
Because the versions of jdk and Tomcat are no different to the operation and maintenance staff, the download address of the software used in this article is http://pan.baidu.com/s/1IpioA.
2.2 deploy the java environment
[root@tomcat ~] # cd / application/tools/
[root@tomcat tools] # rz
Rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring apache-tomcat-8.0.27.tar.gz...
8914 KB 8914 KB/sec 00:00:01 0 Errors
Transferring jdk-8u60-linux-x64.tar.gz...
176990 KB 14749 KB/sec 00:00:12 0 Errors
Tar xf jdk-8u60-linux-x64.tar.gz-C / application/
Ln-s / application/jdk1.8.0_60 / application/jdk
Sed-i.ori'$an export JAVA_HOME=/application/jdk\ nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\ nexport CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' / etc/profile
Source / etc/profile
# → shows the following results to prove that the deployment is successful
[root@tomcat ~] # java-version
Java version "1.8.0mm 60"
Java (TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot (TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
There is a special use of the sed command above. For more information, → http://edu.51cto.com/course/course_id-5266.html
2.3 install Tomcat
Tar xf apache-tomcat-8.0.27.tar.gz-C / application/
Ln-s / application/apache-tomcat-8.0.27 / application/tomcat
Echo 'export TOMCAT_HOME=/application/tomcat' > > / etc/profile
Source / etc/profile
Chown-R root.root / application/jdk/ / application/tomcat/
[root@tomcat] # tail-4 / etc/profile
Export JAVA_HOME=/application/jdk
Export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
Export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
Export TOMCAT_HOME=/application/tomcat
2.4 introduction to the Tomcat directory
[root@tomcat ~] # cd / application/tomcat/
[root@tomcat tomcat] # tree-L 1
.
├── bin # → scripts (.bat files and .sh files) to start and turn off Tomcat or other features
├── conf # → XML and DTD files used to configure Tomcat
├── lib # → stores JAR packages accessible to web applications
├── LICENSE
Log files for ├── logs # → Catalina and other Web applications
├── NOTICE
├── RELEASE-NOTES
├── RUNNING.txt
├── temp # → temporary File
├── webapps # → Web application root directory
└── work # → is used to generate .java and .class files with Servlet compiled by JSP
7 directories, 4 files
[root@tomcat tomcat] # cd webapps/
[root@tomcat webapps] # ll
Total 20
Drwxr-xr-x 14 root root 4096 Oct 5 12:09 docs # → tomcat help documentation
Drwxr-xr-x 6 root root 4096 Oct 5 12:09 examples # → web Application example
Drwxr-xr-x 5 root root 4096 Oct 5 12:09 host-manager # → Management
Drwxr-xr-x 5 root root 4096 Oct 5 12:09 manager # → Management
Drwxr-xr-x 3 root root 4096 Oct 5 12:09 ROOT # → default site root directory
2.5 start Tomcat
# → launcher / application/tomcat/bin/startup.sh
# → shutdown program / application/tomcat/bin/shutdown.sh
[root@tomcat ~] # / application/tomcat/bin/startup.sh
Using CATALINA_BASE: / application/tomcat
Using CATALINA_HOME: / application/tomcat
Using CATALINA_TMPDIR: / application/tomcat/temp
Using JRE_HOME: / application/jdk
Using CLASSPATH: / application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@tomcat ~] # netstat-tunlp | grep java
Tcp 00: 8009: * LISTEN 4743/java
Tcp 0 0: 8080: * LISTEN 4743/java
[root@tomcat ~] # ps-ef | grep [j] ava
Root 4743 1 17 06:10 pts/0 00:00:03 / application/jdk/bin/java-Djava.util.logging.config.file=/application/tomcat/conf/logging.properties-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager-Djava.endorsed.dirs=/application/tomcat/endorsed-classpath / application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar-Dcatalina.base=/application/tomcat-Dcatalina.home=/application/tomcat-Djava.io.tmpdir=/application/tomcat/temp org.apache.catalina.startup.Bootstrap start
2.6 visit the website
Web site: http://10.0.0.3:8080/
2.7 Tomcat Lo
[root@tomcat ~] # cd / application/tomcat/logs/
[root@tomcat logs] # ls
Catalina.2016-01-26.log localhost.2016-01-26.log
Catalina.out localhost_access_log.2016-01-26.txt
Host-manager.2016-01-26.log manager.2016-01-26.log
# → tomcat Real time Log
[root@tomcat logs] # tailf catalina.out
26-Jan-2016 06:10:24.006 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory / application/apache-tomcat-8.0.27/webapps/examples has finished in 666 ms
10. 26-Jan-2016 06:10:24.007 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory / application/apache-tomcat-8.0.27/webapps/docs
11. 26-Jan-2016 06:10:24.054 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory / application/apache-tomcat-8.0.27/webapps/docs has finished in 47 ms
12. 26-Jan-2016 06:10:24.055 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory / application/apache-tomcat-8.0.27/webapps/manager
13. 26-Jan-2016 06:10:24.134 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory / application/apache-tomcat-8.0.27/webapps/manager has finished in 80 ms
14. 26-Jan-2016 06:10:24.139 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory / application/apache-tomcat-8.0.27/webapps/host-manager
15. 26-Jan-2016 06:10:24.188 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory / application/apache-tomcat-8.0.27/webapps/host-manager has finished in 50 ms
16. 26-Jan-2016 06 main 10 main 24.195 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080]
17. 26-Jan-2016 06 main 10 main 24.206 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
18. 26-Jan-2016 06:10:24.211 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1560 ms
3. Tomcat profile 3.1 Tomcat profile
[root@tomcat conf] # pwd
/ application/tomcat/conf
[root@tomcat conf] # ll-h
Total 216K
Drwxr-xr-x 3 root root 4.0K Jan 26 06:10 Catalina
-rw- 1 root root 13K Sep 28 16:19 catalina.policy
-rw- 1 root root 7.0K Sep 28 16:19 catalina.properties
-rw- 1 root root 1.6K Sep 28 16:19 context.xml
-rw- 1 root root 3.4K Sep 28 16:19 logging.properties
-rw- 1 root root 6.4K Sep 28 16:19 server.xml # → main configuration file
-rw- 1 root root 1.8K Sep 28 16:19 tomcat-users.xml # → Tomcat manage user profile
-rw- 1 root root 1.9K Sep 28 16:19 tomcat-users.xsd
-rw- 1 root root 164K Sep 28 16:19 web.xml
3.2 Tomcat Management
Test function, do not use in production environment.
The Tomcat management function is used to manage web applications that manage Tomcat itself and applications deployed on Tomcat. Is disabled by default. If you need to turn on this feature, you need to configure the administrative user, that is, configure the tomcat-users.xml mentioned earlier.
[root@tomcat ~] # vim / application/tomcat/conf/tomcat-users.xml
.
# → add the above three lines before this line
[root@tomcat ~] # / application/tomcat/bin/shutdown.sh
[root@tomcat ~] # / application/tomcat/bin/startup.sh
3.3 Tomcat main profile Server.xml details 3.3.1 server.xml component categories
Top-level components: located at the top level of the entire configuration, such as server.
Container class components: components that can contain other components, such as service, engine, host, context.
Connector components: connect user requests to tomcat, such as connector.
Nested class components: in a container, can not contain other components, such as Valve, logger.
3.3.2 detailed explanation of components
Engine: the core container component, catalina engine, is responsible for receiving user requests through connector, processing the requests, and transferring the requests to the corresponding virtual host host.
Host: similar to virtual hosts in httpd, FQDN-based virtual hosts are generally supported.
Context: defines an application that is the innermost container class component (can no longer be nested). The main purpose of configuring context is to specify the root directory of the corresponding webapp, similar to httpd's alias, which can also specify additional properties for webapp, such as how to deploy, and so on.
Connector: receives user requests, similar to httpd's listen configuration listening port.
Service (service): associate the connector to the engine, so there can be multiple connector within a service, but only one engine engine. There are two connector inside the service, one engine. Therefore, in general, there is only one service inside a server, and there is only one engine inside a service, but there can be multiple connector inside a service.
Server: represents an instance of tomcat running in JVM.
Valve: valve that intercepts requests and performs some processing before transferring them to the corresponding webapp. It can be used in any container, such as logging (access log valve), IP-based access control (remote address filter valve).
Logger: a logger that records state information within a component and can be used in any container except context.
Realm: can be used in components of any container class to associate a user authentication library for authentication and authorization. There are two types of authentication libraries that can be associated: UserDatabaseRealm, MemoryRealm and JDBCRealm.
UserDatabaseRealm: use the user authentication library customized by JNDI.
MemoryRealm: authentication information is defined in tomcat-users.xml.
JDBCRealm: the authentication information is defined in the database and connects to the database through JDBC to find the authenticated user.
3.3.3 profile comment
1.
two。
7.
8.
9.
10.
11.
twelve。
13.
14.
19.
20.
21.
twenty-two。
thirty-four。
thirty-seven。
thirty-eight。
thirty-nine。
forty-two。
forty-three。
forty-four。
forty-five。
forty-seven。
forty-eight。
fifty-seven。
fifty-nine。
sixty-five。
sixty-six。
sixty-seven。
seventy。
seventy-one。
seventy-two。
seventy-three。
4. WEB site deployment
There are two ways to put the code online. The first way is to put the program directory directly under the webapps directory. This way is already understood, so we won't say much about it. The second way is to use development tools to package the program into a war package and upload it to the webapps directory. Let's take a look at this.
4.1 deploy web sites using war packages
1. [root@tomcat webapps] # pwd
2. / application/tomcat/webapps
3. [root@tomcat webapps] # rz # → upload memtest.war, this file is also on the Baidu network disk above
4. [root@tomcat webapps] # ls
5. Docs examples host-manager manager memtest memtest.war ROOT
Browser access: http://10.0.0.3:8080/memtest/meminfo.jsp
4.2 customize the default site directory
The URL visited above is http://10.0.0.3:8080/memtest/meminfo.jsp
Now I want to access the format as http://10.0.0.3:8080/meminfo.jsp
how to deal with it?
Method one
Just put meminfo.jsp or other programs in the tomcat/webapps/ROOT directory. Because the default site root is tomcat/webapps/ROOT
Method two
1. [root@tomcat ~] # vim / application/tomcat/conf/server.xml
two。
4.
5. [root@tomcat ~] # / application/tomcat/bin/shutdown.sh
6. [root@tomcat ~] # / application/tomcat/bin/startup.sh
5. Tomcat multi-instance and cluster architecture 5.1 Tomcat multi-instance 5.1.1 replication Tomcat directory
1. [root@tomcat ~] # cd / application/
2. [root@tomcat application] # cp-an apache-tomcat-8.0.27 tomcat8_1
3. [root@tomcat application] # cp-an apache-tomcat-8.0.27 tomcat8_2
5.1.2 modify the configuration file
1. [root@tomcat application] # mkdir-p / data/www/www/ROOT
2. [root@tomcat application] # cp / application/tomcat/webapps/memtest/meminfo.jsp / data/www/www/ROOT/
3. [root@tomcat] # sed-I '22s 805 / 8011 / 69s8080 / 8081 / 123s / application/tomcat8_1/conf/server.xml = "." # appBase= "/ data/www/www" #' / application/tomcat8_1/conf/server.xml
4. [root@tomcat] # sed-I '22s 805 / 8012 / 69s8080 / 8082 / 123s / appBase= = ". *" # appBase= "/ data/www/www" #' / application/tomcat8_2/conf/server.xml
5. [root@tomcat ~] # diff / application/tomcat/conf/server.xml / application/tomcat8_1/conf/server.xml
6. 22c22
7.
< 8. --- 9. >10. 69c69
11. <
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.