Analysis of the process of building a cluster environment with Apache and Tomcat

Analysis of the process of building a cluster environment with Apache and Tomcat

In fact, it is not difficult to build an Apache cluster. I also found some information on the Internet and configured it myself. Of course, there are some parameters that need to be set by yourself to achieve the best

The first step to build a cluster is to download the software. Because the server on the company side is Win2003, some operations are saved:

Apache download address: http://httpd.apache.org/ I downloaded Apache httpd 2.2.27 Released

Tomcat download address: http://tomcat.apache.org/download-60.cgi I downloaded the decompressed version of 6.0.39

The first step is to configure Tomcat, because Tomcat is each node of the cluster, first of all, we need to ensure that each node can run normally:
Make two nodes, unzip the Tomcat folder and name them tomcat-node1 and tomcat-node2 respectively.
Configuration files that need to be modified:

Tomcat startup memory:

In the bin directory, catalina.bat is used. Because it is Win2003, it is catalina.sh in Linux. Add the following to the top of the file:

set JAVA_OPTS=-Xms256m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m -XX:-UseGCOverheadLimit -XX:+UseConcMarkSweepGC -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000

If it is Linux, the writing is slightly different:

JAVA_OPTS="-server -Xms256m -Xmx1030m -XX:PermSize=128m -XX:MaxPermSize=256m -XX:-UseGCOverheadLimit -XX:+UseConcMarkSweepGC -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"

For the specific meaning of each parameter and specific optimization plan, Google "tomat startup memory". It should be pointed out here that under Windows, the maximum startup memory of JVM is 1/4 of the device memory. No matter how large you set it on my machine, it is 1300M.

Tomcat log configuration:

You can ignore the logging.properties under conf, but it should be pointed out that if it is not configured, the log may fill up the disk after the service runs for a long time, which will cause downtime. I have encountered this before, so I won’t say more.
When configuring logs, there are a few points to note: 1: Log output address. 2: Log output level. 3: Try to configure the log output size yourself. I think even if you don’t configure it, it will not affect your reading.

Tomcat monitoring configuration:

conf, the file contains the following content:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
</tomcat-users>

I mean except for the comments. Here is to add a user:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager"/>
<user username="admin" password="admin_cui" roles="manager"/>
</tomcat-users>

More fancy configurations, well, you know. After configuration, you can view the current connection processing status by visiting http://localhost:8011/manager/html.

Core, focus, server.xml

Three ports, one name:

Management port: There is a port in front of shutdown="SHUTDOWN". I set the first port to 8012 and the second port to 22.

<Server port="8012" shutdown="SHUTDOWN">

Service Port:

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="300" minSpareThreads="50" maxIdleTime="120000" />
<Connector executor="tomcatThreadPool" address="0.0.0.0" port="8011" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="120000"
maxKeepAliveRequests="1" redirectPort="443" maxHttpHeaderSize="8192" URIEncoding="UTF-8" enableLookups="false" acceptCount="500" compression="on"
compressionMinSize="2048" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" disableUploadTimeout="true"/>

It can be seen that these are all optimized configurations, including NIO, connection pool, encoding, compression, etc. The meaning of each parameter is not explained in detail.
AJP Port:

<Connector port="8039" protocol="AJP/1.3" redirectPort="8443" />

jvmRoute name, used when clustering:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm3">

The following configuration is also released:

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" />

If you can start Tomcat and access 8011, then this node is configured. Other nodes are the same. Remember that the three ports and one name must be different for each node.

Configure Apache

The configuration file httpd.conf is the most important configuration file. The following points should be noted when configuring it:
Release the loading of the proxy module:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so

Open access to the website. I won't go into details here. I'll just open it.

Deny from All

Change all of

allow from all

Unlock the following configuration files and remove the # in front of them.

  • Include conf/extra/httpd-mpm.conf Auxiliary configuration file for configuring the multi-channel processing module (MPM)
  • Include conf/extra/httpd-vhosts.conf Auxiliary configuration file for configuring virtual hosts
  • Include conf/extra/httpd-default.conf configures auxiliary configuration files related to the Apache service itself

httpd-mpm.conf and httpd-default.conf are the default ones. If you want to make some relevant configurations according to the actual situation, you can refer to the previous article
For httpd-vhosts.conf, configure the cluster node service tag and set ServerAlias ​​to the local IP.

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName 192.168.1.102
ServerAlias ​​192.168.1.102
ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://cluster/
ErrorLog "logs/lbtest-error.log"
CustomLog "logs/lbtest-access.log" common
</VirtualHost>

Add the following configuration at the bottom of httpd.conf

ProxyRequests Off
<proxy balancer://cluster>
BalancerMember ajp://127.0.0.1:8019 loadfactor=1 route=jvm1
BalancerMember ajp://127.0.0.1:8029 loadfactor=1 route=jvm2
</proxy>

Enable reverse proxy and use AJP proxy for access. Loadfactor is the distribution weight, and route is the name defined in Tomcat. Note that this is the AJP port, not the Tomcat service port.

Tomcat performance tuning and Apache configuration file customization are two important factors that affect cluster performance.
At this point, the configuration has actually been completed. One thing that needs to be mentioned is that for session sharing, just add the <distributable/> configuration in the web.xml of each project.

Start Tomcat and Apache, then access the actual project.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Build a cluster with apache and tomcat (load balancing)
  • How to deploy stand-alone Pulsar and clustered Redis using Docker (development artifact)
  • Detailed process of building and deploying Apache Pulsar cluster

<<:  JavaScript to display hidden form text

>>:  MySQL learning tutorial clustered index

Recommend

How to implement the paging function of MyBatis interceptor

How to implement the paging function of MyBatis i...

Tips for viewing text in Linux (super practical!)

Preface In daily development, we often need to pe...

jQuery manipulates cookies

Copy code The code is as follows: jQuery.cookie =...

MySQL index knowledge summary

The establishment of MySQL index is very importan...

Some problems that may be caused by inconsistent MySQL encoding

Stored procedures and coding In MySQL stored proc...

Vue.js implements simple folding panel

This article example shares the specific code of ...

Example of building a redis-sentinel cluster based on docker

1. Overview Redis Cluster enables high availabili...

Solution to the problem that Centos8 cannot install docker

Problem [root@zh ~]# [root@zh ~]# [root@zh ~]# yu...

Install zip and unzip command functions under Linux and CentOS (server)

Install zip decompression function under Linux Th...

Ubuntu16.04 builds php5.6 web server environment

Ubuntu 16.04 installs the PHP7.0 environment by d...

Web page printing thin line table + page printing ultimate strategy

When I was printing for a client recently, he aske...