Cluster of Java Web Learning Notes

colony

Clusters are mainly divided into three categories (high availability cluster, load balancing cluster and scientific computing cluster)

  • High availability cluster

  • Load balance cluster

  • High performance computing cluster

1. High availability cluster

   HA clusters made of two nodes are common. They have many popular and unscientific names, such as "dual machine hot standby", "dual machine mutual standby" and "dual machine"
   high availability cluster solves the problem of ensuring the ability of users' applications to continuously provide external services. (please note that the high availability cluster is not used to protect business data, but to protect the user's business programs to provide uninterrupted services to minimize the impact of software / hardware / man-made failures on the business).

2. Load balance cluster

  load balancing system: all nodes in the cluster are active, and they share the workload of the system. Generally, Web server cluster, database cluster and application server cluster all belong to this type.

  load balancing cluster is generally used for web server and database server of corresponding network requests. This cluster can check the servers that accept fewer requests and are not busy when receiving requests, and transfer the requests to these servers. From the point of checking the status of other servers, load balancing is very close to fault-tolerant clusters, but the difference is more in number.

3. High Performance Computing Cluster

   high performance computing cluster, referred to as HPC cluster for short. Such clusters are dedicated to providing powerful computing power that a single computer cannot provide.

apache,nginx

tomcat: load balancing, failed migration

Server cluster

Horizontal cluster: install servers on different computers (failed migration)

Vertical cluster: install multiple servers on the same computer

Build clusters

apache: it can handle static resources (html, pictures, js)

be careful!
apache mentioned here is a server tool, not a cluster organization as previously understood

tomcat: it can handle dynamic resources

apache+tomcat: dynamic and static separation

apache: requested shunting operation

1. Download apache server tools:

https://www.apachehaus.com/cgi-bin/download.plx?dli=gWF5kdSlXT41ERJBjZsZ1aNRVMUNlVSZETXJlVlZ1Y

Configuration: conf/http.conf

2. Open cmd as administrator: register apache service through command


apache can be configured as a Windows service when in use


After successful registration, start the service and use the browser to access localhost to check whether it is successful

3. After Apache service configuration, continue to configure tomcat service

Copy two tomcat files and modify the port number

Before modifying, plan the port to avoid port occupation (the file to be modified is apache-tomcat-9.0.39-A\conf\server.xml)

Modify the server.xml file of tomcat-a

    <Connector port="1080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
<Server port="1005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
    <Connector protocol="AJP/1.3"
               address="::1"
               port="1009"
               redirectPort="8443" />

tomcat-b is configured as tomcat-a

4. Configure Engine (the file to be modified is apache-tomcat-9.0.39-A\conf\server.xml)

Add jvmRoute to the engine

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat-a">

tomcat-b is configured as tomcat-a

5. Turn on the cluster switch (off by default)

6. Combine apache and tomcat: use mod_jk.so plug-in

Download address: http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/


Extract the so file:

Configure mod_jk.so:

(1) Storage location: \ apache24 \ modules \ Mod_ In jk.so

(2) Write the configuration file \ Apache24\conf\worker.properties

Code example:

worker.list=controller,tomcata,tomcatb
#tomcata

worker.tomcata.port=1009
worker.tomcata.host=localhost
worker.tomcata.type=ajp13
#Weight of load balancing
worker.tomcata.lbfactor=1

#tomcatb

worker.tomcatb.port=2009
worker.tomcatb.host=localhost
worker.tomcatb.type=ajp13
#Weight of load balancing
worker.tomcata.lbfactor=2


#controller

worker.controller.type=lb
worker.controller.balance_workers=tomcata,tomcatb
worker.controller.sticky_session=false



(3) Distributed session policy:

① sticky: the requests of each user are allocated to a specific server, and the later requests will not be allocated to other servers

② Session broadcast (automatic synchronization session): automatically synchronize sessions,
Disadvantages: if there are too many servers, it may cause a broadcast storm (the session of one server needs to be synchronized to all other servers)

③ Centralized management (applicable to large projects): centrally store the session s of each server in one database (recommended)

(4) Configure \ Apache24\conf\mod_jk.conf (used to load mod_jk.so and workers.properties)

  • JkMount /* controller means to intercept all requests. You can also intercept only jsp: / *. JSP
Code example:
#Load mod_jk.so file
LoadModule jk_moudle moudles/mod_jk.so

#Load the workers.properties file
JkWorkersFile conf/wokers.properties
JkMount /* controller

(5) Configure heepd.conf: automatically load mod when apache starts_ jk.conf

Cluster: application phase, deployment and implementation, not used in development phase

be careful! The system environment variable CATALINA HOME causes the tomcat specified by CATALINA HOME to be automatically turned on when starting tomcat. In the cluster, you need to open multiple different Tomcats. Therefore, in the stand-alone environment, you need to delete cataliva home.

CATALINA_HOME Will start tomcat Automatically on when CATALINA_HOME designated tomcat. 
	In the cluster, you need to open multiple different tomcat,Therefore, in the stand-alone environment, it needs to be deleted CATALINA_HOME. 
Start in sequence apache,tomcata,tomcatb

details
apache:
worker.list=controller,tomcata,tomcatb

tomcat Configuration: (only need to ensure all tomcat of jvmRoute You can't have the same name, you can and apache (inconsistent naming in)
jvmRoute="tomcat-a"
jvmRoute="tomcat-b"

technological process: apache->workers.properties Configured in ip:Find the specific port tomcat Services (and tomcat Medium jvmRoute="tomcat-a"(it doesn't matter)

tomcat Directory name of the service: (any)
tomcata
tomcatb

7. Write test cases

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<body>
<h1>ClusterProject1</h1>
Server address:
<%
	out.print(request.getRemoteAddr() + ": " + request.getLocalPort());
%><br/>
sessionId: 
<%
	out.print(session.getId());
%>
</body>
</html>


web.xml
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <distributable/>
</web-app>

Start apache

Start tomcat-a and tomcat-b.

  • Delete Catalina in environment variable_ HOME,CATALINA_BASE configuration. (no operation is required if there is no configuration)
  • Click startup.bat under the bin directory of Tomcat to start tomcat-a and tomcat-b.
    Test screenshot:

Keywords: Apache Load Balance server

Added by jpadie on Fri, 03 Dec 2021 20:25:50 +0200