Linux下配置tomcat负载均衡

1.1  配置负载均衡

1.1.1  安装tomcat-connectors-1.2.25-src.tar.gz

步骤1:    将文件复制到/usr/local

cp tomcat-connectors-1.2.25-src.tar.gz /usr/local

步骤2:    解压

Cd /usr/local

tar xzvf tomcat-connectors-1.2.25-src.tar.gz

步骤3:    修改buildconf.sh的权限

cd /usr/local/tomcat-connectors-1.2.25-src/native

chmod 755 buildconf.sh

./buildconf.sh

步骤4:     

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

步骤5:     

make

步骤6:     

make install

步骤7:    将mod_jk.so复制到/usr/local/apache/modules/

cd /usr/local/tomcat-connectors-1.2.25-src/native/apache-2.0

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

1.1.2  系统整合

步骤1:    在/usr/local/apache/conf/httpd.conf加上如下语句

# Load mod_jk

LoadModule jk_module /usr/local/apache/modules/mod_jk.so

# Configure mod_jk

JkWorkersFile /usr/local/apache/conf/workers.properties

JkLogFile /usr/local/apache/logs/mod_jk.log

JkLogLevel info

JkMount /*.jsp loadbalancer

JkMount /servlet/* loadbalancer

JkMount /application/* loadbalancer

步骤2:    在/usr/local/apache/conf/目录下添加workers.properties

# list the workers by name

worker.list=tomcat1, tomcat2, loadbalancer

# ------------------------

# First tomcat server

# ------------------------

worker.tomcat1.port=8009

worker.tomcat1.host=127.0.0.1

worker.tomcat1.type=ajp13

# Specify the size of the open connection cache.

#worker.tomcat1.cachesize

#

# Specifies the load balance factor when used with

# a load balancing worker.

# Note:

# ----> lbfactor must be > 0

# ----> Low lbfactor means less work done by the worker.

worker.tomcat1.lbfactor=100

# ------------------------

# Second tomcat server

# ------------------------

worker.tomcat2.port=8009

worker.tomcat2.host=192.168.228.138

worker.tomcat2.type=ajp13

# Specify the size of the open connection cache.

#worker.tomcat2.cachesize

#

# Specifies the load balance factor when used with

# a load balancing worker.

# Note:

# ----> lbfactor must be > 0

# ----> Low lbfactor means less work done by the worker.

worker.tomcat2.lbfactor=100

# ------------------------

# Load Balancer worker

# ------------------------

# The loadbalancer (type lb) worker performs weighted round-robin

# load balancing with sticky sessions.

# Note:

# ----> If a worker dies, the load balancer will check its state

# once in a while. Until then all work is redirected to peer

# worker.

worker.loadbalancer.type=lb

worker.loadbalancer.balanced_workers=tomcat1, tomcat2

#

# END workers.properties

#

步骤3:    修改tomcat1的server.xml文件

<Connector port="8009"  protocolHandlerClassName= "org.apache.jk. server. JkCoyoteHandler "  redirectPort="8443" protocol="AJP/1.3" />

在120行左右加入如下语句

<Engine name="Standalone" defaultHost="localhost" jvmRoute="tomcat1"/>

步骤4:    修改tomcat2的server.xml文件

<Connector port="8009"  protocolHandlerClassName= "org.apache.jk. server. JkCoyoteHandler "  redirectPort="8443" protocol="AJP/1.3" />

在120行左右加入如下语句

<Engine name="Standalone" defaultHost="localhost" jvmRoute="tomcat2"/>

步骤5:    重新启动apache和tomcat

步骤6:    在tomcat1和tomcat2相同的目录的相同的文件中,写入不同的测试代码,通过启停tomcat,利用浏览器来判断是否安装成功。

在tomcat1中放一个jsp测试文件,内容为<%out.println(“tomcat1”)%>;

在tomcat2中放一个jsp测试文件,内容为<%out.println(“tomcat2”)%>;

如果tomcat1和tomcat2均启动,输入URL,页面有显示;

如果tomcat1启动,tomcat2关闭,输入URL,页面显示“tomcat1”;

如果tomcat1关闭,tomcat2启动,输入URL,页面显示“tomcat2”;

如果tomcat1和tomcat2均关闭,输入URL,页面会提示错误信息;

如果以上四种情况出现,那么负载均衡配置成功。


你可能感兴趣的:(tomcat,linux,jsp,负载均衡,url,less)