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

How to build tomcat+apache+linux Cluster

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

How to build a tomcat+apache+linux cluster, in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

The cluster is a pseudo-cluster. In practical application, tomcat should be installed on different machines, not on the same machine.

I. configure the environment

Operating system: rhel5

Server IP:192.168.93.43

Jdk version: 1.6.020

Apache version: httpd-2.2.16.tar.gz

Tomcat version: apache-tomcat-5.5.30.tar.gz

Jk version: tomcat-connectors-1.2.30-src.tar.gz

The three installation packages are placed in the usr/local directory by default and downloaded by root users.

There is a single machine, so apache, jdk and two tomcat are all installed on the same machine. Generally speaking, apache and jdk are installed on the same machine, and tomcat is installed on each machine or on the same machine.

II. Installation

A) jdk installation, slightly.

B) apache installation

# cd / usr/local/

# mkdir apache

# tar xvfz httpd-2.2.16.tar.gz

# cd httpd-2.2.16

#. / configure-prefix=/usr/local/apache-enable-modules=so-enable-so

Configure installation path information, etc.

# make

# make install

# cd / usr/local/apache/bin/

#. / apachectl configtest

If Syntax ok is displayed, the installation is successful, and some other information appears, such as: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.93.43 for ServerName can be ignored

#. / apachectl start

Start the apache service and enter 127.0.0.1 in the browser to see if there is it works

#. / apachectl stop

Shut down the service

Note: the system may have its own Apache installed. If you do not need it, you can uninstall it first and then install it, otherwise there may be direct access to the system's own Apache.

C) tomcat installation

# cd / usr/local/

# tar xvfz apache-tomcat-5.5.30.tar.gz

# mv apache-tomcat-5.5.30 / usr/local/tomcat modify the name of the decompressed folder

# / usr/local/tomcat/bin/startup.sh

After starting the service, access the native port 8080

# / usr/local/tomcat/bin/startup.sh / startup.bat

Shut down the service

# / usr/local/tomcat/bin/shutdown.sh

# tail-f logs/catalina.out to view the console output of tomcat

If you encounter a situation such as an incomplete tomcat off, do the following

# ps-ef | grep tomcat to view tomcat processes

# kill-9 pid, if available, use kill;pid as the process number

D) jk installation

# cd / usr/local/

# tar xzvf tomcat-connectors-1.2.30-src.tar.gz

# cd tomcat-connectors-1.2.30-src/jk/native

# chmod 755 buildconf.sh

#. / buildconf.sh

#. / configure-with-apxs=/usr/local/apache/bin/apxs

# make

# make install

After I installed it, I found that there is already mod_jk.so under / usr/local/apache/modules/

Note to check first, and if not, perform the following steps

# cd / usr/local/ jakarta-tomcat-connectors- jk1.2.14-src/jk/native/apache-2.0/

# cp mod_jk.so / usr/local/apache/modules/

III. Configuration

A) httpd.conf configuration

# vi / usr/local/apache/conf/httpd.conf

Add the following statement to the end of the file

# Load mod_jk

LoadModule jk_module modules/mod_jk.so

# Configure mod_jk

JkWorkersFile conf/workers.properties

JkLogFile logs/mod_jk.log

JkLogLevel info

Forward filtering to send requests to the load balancer that meet the following criteria

JkMount / * .jsp loadbalancer

JkMount / servlet/* loadbalancer

JkMount / application/* loadbalancer

B) workers.properties addition

# vi / usr/local/apache/conf/workers.properties if the workers.properties does not exist, it means to create the file

The contents are as follows:

Worker.list=loadbalancer

The port on which worker.worker1.port=8009 worker1 is located

The IP where worker.worker1.host=192.168.93.43 worker1 is located

Worker.worker1.type=ajp13

Worker.worker1.lbfactor=1

The port on which worker.worker2.port=9009 worker2 is located

The IP where the worker.worker2.host=192.168.93.43 worker2 is located

Worker.worker2.type=ajp13

The greater the weight value of worker.worker2.lbfactor=1 #, the least probability of allocation

Worker.loadbalancer.type=lb

Worker.loadbalancer.balanced_workers=worker1,worker2

Worker.loadbalancer.local_worker_only=1

Worker.loadbalancer.sticky_session=true

Whether session replication is required for the cluster is specified here. If set to true, it indicates session stickiness and does not perform session replication. When a user's request is first distributed to which Tomcat, subsequent requests will be distributed to this Tomcat server for processing; if set to false, session replication is required.

Worker.loadbalancer.sticky_session_force=true

If the above sticky_session is set to true, it is recommended to set it to true here. This parameter indicates whether the current request will be forwarded to other Tomcat servers for processing if a Tomcat server in the cluster does not respond to multiple requests. This parameter has a great impact on sticky_session=true and will cause requests forwarded to other Tomcat servers that cannot find the original session. Therefore, if some information in the session is read in the request at this time, it will result in an application null exception.

C) server.xml configuration

Modify the server.xml file of the first tomcat, and the modified configuration is as follows

Remove the comments from the Cluster tag pair and modify the

TcpListenAddress= "192.168.93.43"

The ports of the first tomcat are: 8005, 8080, 8009

Modify the server.xml file of the second tomcat. The modified configuration is as follows

Remove the comments from the Cluster tag pair and modify the

TcpListenAddress= "192.168.93.43"

The ports of the second tomcat are: 9005, 9080, 9009

Restart tomcat after saving to check whether it is normal

This is the answer to the question on how to build a tomcat+apache+linux cluster. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.

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