In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Many novices are not very clear about how to realize the perfect deployment of online mall applications with Tomcat. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.
Tomcat is a small and lightweight application server, which 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. For a beginner, it can be thought that when an Apache server is configured on a machine, it can be used to respond to requests for access to HTML pages. The Tomcat part is actually an extension of the Apache server, but it runs independently, so when you run tomcat, it actually runs as a separate process from Apache.
Tomcat is very popular with programmers because it takes up small system resources, has good expansibility, and supports functions commonly used in developing application systems, such as load balancing and mail services; moreover, it is still in the process of continuous improvement and improvement, and any interested programmer can change it or add new functions to it.
Environment introduction:
System version: CentOS 6.4_x86_64
Mysql version: mysql-server.x86_64 0vl 5.1.66-2.el6_3
Apache version: httpd-2.2.15-26.el6
Tomcat version: apache-tomcat-7.0.42
JDK version: jdk-7u40-linux-x64
Online mall system: shopxx-3.0Beta (downloadable)
Topology presentation:
Installation and configuration process:
1. Configure IP address
# Front-end server [root@node] #: # ifconfig eth0 172.16.18.6 ifconfig eth2 192.168.18.254 Tomcat 24 # Tomcat A [root@node1~] #: # ifconfig eth0 192.168.18.1 route add default gw 24 server 192.168.18.254 # # Tomcat B [root@node2~] #: # ifconfig eth0 192.168.18.2/24 route add default gw 192.168.18.254
2. Install and configure the backend server
# TomcatA server: # # install JDK:# [root@node1~] # rpm-ivh jdk-7u9-linux-x64.rpm [root@node1~] # vim / etc/profile.d/java.sh # Edit and execute script export JAVA_HOME=/usr/java/latest export PATH=$JAVA_HOME/bin:$PATH [root@node1~] #. / etc/profile.d/java.sh # read and execute script [root@node1~] # java-version # View installation information javaversion "1.7.0x09" # version information Java (TM) SE Runtime Environment (build 1.7.0_09-b05) # version JavaHotSpot (TM) 64-Bit Server VM (build 23.5-b02) of the runtime environment Mixed mode) # install Tomcat# [root@node1~] # tar xf apache-tomcat-7.0.42.tar.gz-C / usr/local/ [root@node1~] # cd / usr/local/ [root@node1local] # ln-sv apache-tomcat-7.0.42/ tomcat [root@node1tomcat] # vim / etc/profile.d/tomcat.sh # define the startup environment Variable exportCATALINA_HOME=/usr/local/tomcat exportPATH=$CATALINA_HOME/bin:$PATH [root@node1tomcat] #. / etc/profile.d/tomcat.sh # read script [root@node1~] # catalina.sh version # View installation information UsingCATALINA_BASE: / usr/local/tomcat UsingCATALINA_HOME: / usr/local/tomcat UsingCATALINA_TMPDIR: / usr/local/tomcat/temp UsingJRE_HOME: / usr/java/latest UsingCLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Serverversion: Apache Tomcat/7.0.42 Serverbuilt: Jul 2 2013 08:57:41 Servernumber: 7.0.42.0 OSName: Linux OSVersion: 2.6.32-358.el6.x86_64 Architecture: amd64 JVMVersion: 1.7.0_09-b05 JVMVendor: Oracle Corporation # launch # [root@node1~] # catalina. Sh start # View launch port # [root@node1~] # ss-tanl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128:: 111 : * LISTEN 0 128 *: 111 *: * LISTEN 0 100: 8080:: * LISTEN 0 128 : 49906:: * LISTEN 0 128 *: 56818 *: * LISTEN 0 128: 22 : * LISTEN 0 128 *: 22 *: * LISTEN 0 128 127.0.1 LISTEN 0128 : 1 LISTEN 631: * LISTEN 0 100:: 1:25: * LISTEN 0 100 127.0.0.1 LISTEN 25 *: * LISTEN 0 128 127.0.1 LISTEN 6010 *: * LISTEN 0 128:: * LISTEN 0 128:: 1 127.0.0.1 LISTEN 6011 *: * LISTEN 0 128 127.0.1 6011: * *: * LISTEN 0 128:: 1 LISTEN 6012: * LISTEN 01:: ffff:127.0.0.1:8005:: * LISTEN 0 100 : 8009: * # # Resolution: tomcat listens on port 8080 by default The startup listening port is 8005, and the monitoring port is also installed on the Tomcat B server. I will not repeat the demonstration here # # change listening port # [root@node1conf] # vim / usr/local/tomcat/conf/server.xml # restart service # [root@node1conf] # catalina.sh stop [root@node1conf] # catalina.sh start [ Root@node1conf] # scp server.xml 192.168.18.2:/usr/local/tomcat/conf/ [root@node2local] # catalina.sh stop [root@node2local] # catalina.sh start
3. Configure the front-end server to achieve load balancing
# install Apache# [root@node~] # yum-y install httpd [root@node~] # service httpd start # configuration based on mod_proxy Agent Load balancer # [root@node~] # cd / etc/httpd/conf.d/ [root@nodeconf.d] # vim mod_proxy_tomcat.conf ProxyViaOn ProxyRequestsOff # turn off the forward proxy ProxyPreserveHostOff # define the proxy's back-end server BalancerMember http://192.168.18.39:80 loadfactor=1 # specify the back-end server address and port BalancerMember http://192.168.18.36:80 loadfactor=1 ProxySet lbmethod=byrequests SetHandler balancer-manager Proxypass! Order Deny,Allow Allow from all ProxyPass/ balancer://hotcluster/ # stickysession=JSESSIONID | jsessionidnofailover=On ProxyPassReverse/ balancer://hotcluster/ Order Allow,Deny Allow From all Order Allow Deny Allow From all # Test syntax correctness # [root@nodeconf.d] # service httpd configtest # restart service # [root@nodeconf.d] # service httpd restart
4. Check the link status and enable the tomcat management feature:
# # Note: because both back-end servers may be used So both sides should create users and be consistent # change the user management profile # [root@node1conf] # vim / usr/local/tomcat/conf/tomcat-users.xml # # content: # copy to Tomcat B# [root@node1conf] # scp tomcat-users.xml 192.168. 18.2:/usr/local/tomcat/conf/ # restart Service # [root@node1conf] # catalina.sh stop [root@node1conf] # catalina.sh start [root@node2local] # catalina.sh stop [root@node2local] # catalina.sh start
5. Simply deploy the home page to view the session value:
# deploy virtual directory and deployment home page # # Tomcat A # [root@node1 tomcat] # mkdir webapps/testapp/WEB-INF/ {lib Classes}-pv [root@node1 tomcat] # vim webapps/testapp/index.jsp # content # # TomcatA TomcatA Session ID Created on [root@node1 tomcat] # catalina.sh stop [root@node1 tomcat] # catalina.sh start # Tomcat B # [root@node2 tomcat] # mkdir webapps/testapp/WEB-INF/ {lib Classes}-pv [root@node2 tomcat] # vim webapps/testapp/index.jsp # content # TomcatB TomcatB Session ID Created on [root@node2 webapps] # catalina.sh stop [root@node2 webapps] # catalina.sh start
6. Implement session shared cluster based on memory replication:
# Tomcat A # [root@node1 ~] # cd / usr/local/tomcat/conf/ [root@node1 conf] # nano server.xml # it is recommended to use this editor # # to add between / host and / engine due to the indentation format of the following # stop tomcat## [root@node1 ~] # catalina.sh stop [root@node1 conf] # cp web.xml.. / webapps/testapp/WEB-INF/ [root@ Node1 conf] # vim.. / webapps/testapp/WEB-INF/web.xml add the following field: # indicates that the session of this application will be distributed [root@node1 conf] # scp.. / webapps/testapp/WEB-INF/web.xml 192.168.18.2:/usr/local/tomcat/webapps/testapp/WEB-INF/ [root@node1 conf] # scp server.xml 192.168.18.2:/usr / local/tomcat/conf/ [root@node1 conf] # catalina.sh start # Tomcat B # [root@node1 ~] # catalina.sh stop [root@node1 conf] # catalina.sh start
Summary: we found that no matter how refreshed, the session id information will not change. So far, we have completed using mod_proxy to achieve load balancing and using tomcat clusters to achieve session sharing. Let's deploy the application of the store.
7. Application implementation of online store.
# Tomcat A # [root@node1 ~] # unzip shopxx-a5-Beta.zip [root@node1 ~] # mv shopxx-v3.0-Beta/* / usr/local/tomcat/webapps/shopxx [root@node2 tomcat] # vim webapps/shopxx/WEB-INF/web.xml # add this field # Tomcat B # # [root@node2 ~] # unzip shopxx-a5-Beta.zip [root@node2 ~] # mv shopxx-v3.0-Beta/* / usr/local/tomcat/webapps/shopxx [root@node2 tomcat] # vim webapps/shopxx/WEB-INF/web.xml # add this field
Note: the installation environment does not meet the basic environment needs to increase memory: the method is as follows
# Tomcat A # [root@node1 ~] # cd / usr/local/tomcat/bin/ [root@node1 bin] # vim catalina.sh JAVA_OPTS= "$JAVA_OPTS-Xmx256M" / / 237 Line Note: modify the memory of the java virtual machine needs to be modified in the startup script;-Xmx: define the maximum memory used by the java virtual machine. Where M: refers to MB, if not specified, KB # Tomcat B server also needs to change # # restart service #
After the change, the next step: if you cannot enter the installation page, you will go back to the entry page.
Reason: because there may be a load balancing transfer at the back end during installation, it is impossible to enter the installation page and can only use local installation.
# switch to front-end server # [root@node ~] # yum-y install firefox [root@node ~] # firefox &
Install Mall Application
Install the mysql server and authorize a user to log in to the installation service
# Tomcat A # [root@node1 shopxx] # yum-y install mysql-server [root@node1 shopxx] # service mysqld start [root@node1 shopxx] # mysql mysql > grant all on *. * to 'shopuser'@'192.168.%.%' identified by' shoppass'; mysql > flush privileges # Tomcat B # [root@node2 shopxx] # yum-y install mysql-server [root@node2 shopxx] # service mysqld start [root@node2 shopxx] # mysql mysql > grant all on *. * to 'shopuser'@'192.168.%.%' identified by' shoppass'; mysql > flush privileges
Click finish installation, restart the web service and delete the install directory
[root@node1 shopxx] # mv install install.bak [root@node1 shopxx] # catalina.sh stop [root@node1 shopxx] # catalina.sh start
Copy the shopxx installation file on Tomcat A to Tomcat B
[root@node1 webapps] # scp-rp shopxx/* 192.168.18.2:/usr/local/tomcat/webapps/shopxx/ [root@node2 shopxx] # catalina.sh stop [root@node2 shopxx] # catalina.sh start
Below, you can register an account in the mall system, log in to the system, buy some clothes, check whether the clothes that have been added to the shopping cart are saved in the shopping cart, and so on.
At this point, tomcat based on session shared cluster to achieve online mall application deployment is perfect, note that this mall can not be used for commercial purposes.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.