APACHE apache_2.0+TOMCAT6.0配置负载均衡
注:本例程以一台机器为例子,即同一台机器上装一个apache和2个Tomcat。
一、前期准备工作:安装用的程序(前提保证已安装了JDK1.5以上的版本)
apache_2.0.49-win32-x86-no_ssl.msi (下载:http://archive.apache.org/dist/httpd/binaries/win32/)
jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip (下载:http://archive.apache.org/dist/tomcat/tomcat-connectors/jk2/binaries/win32/)
JDK1.6 安装(D:\Program Files\Java\jdk1.6)。
APAHCE 2.0 安装(C:\Program Files\Apache Group\Apache2)。
TOMCAT6.0 解压(绿色版)。
jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip 解压.
二、配置
1.jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip 解压.
复制[jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49\modules\mod_jk2.so] 粘贴到 Apache下的[modules]目录下
2.Tomcat配置
2.1由于2个Tomcat是放在一个电脑上,需要修改不同的 tomcat 的关闭口,避免出现端口被占用的情况。在tomcat6.1\conf, 和tomcat6.2\conf下的 server.xml 中找到3处位置,更改他们的端口号:例子:
(a).<Server port="8081" shutdown="SHUTDOWN">
(b).<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>
(c)..<Connector port="8082" protocol="AJP/1.3" redirectPort="8443"/>
2.2 注释掉[<Engine name="Catalina" defaultHost="localhost">] 取消[<Engine name="Catalina" defaultHost="localhost" jvmRoute="XXXXX">] 的注释
例如:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<!-- <Engine name="Catalina" defaultHost="localhost">-->
tomcat6.1和tomcat6.2 都需要这样修改,其中"XXXXX"的值需要不一样。
3、Apache配置
3.1、httpd.conf配置
修改APACHE的配置文件(conf\httpd.conf)
3.1.1添加如下代码:
LoadModule jk2_module modules/mod_jk2.so
Include conf/mod_jk2.conf
3.1.2 查找"DirectoryIndex",在它的后面添加要访问的后缀名(index.jsp)
3.2 在Apache[conf]目录下添加文件 workers.properties
文件内容:(配置Tomcat信息)
[shm]
info=Scoreboard. Requried for reconfiguration and status with multiprocess servers.
file=anon
# Defines a load balancer named lb. Use even if you only have one machine.
[lb:lb]
####------------tomcat1 begin------------####
# Example socket channel, override port and host.
[channel.socket:localhost:8082] # 由于tomcat是在本地,所以用localhost,端口号8082 来自与2.1配置中的(c) ,根据自己的填写
port=8082
host=127.0.0.1
# define the worker
[ajp13:localhost:8082]
channel=channel.socket:localhost:8082
group=lb
####------------tomcat1 end------------####
####------------tomcat2 begin------------####
# Example socket channel, override port and host.
[channel.socket:localhost:8072]
port=8072
host=127.0.0.1
# define the worker
[ajp13:localhost:8072]
channel=channel.socket:localhost:8072
group=lb
####------------tomcat2 end------------####
# Map the Tomcat examples webapp to the Web server uri space
[uri:/test/*] #此处为应用的路径
group=lb
[status:]
info=Status worker, displays runtime information
group=status:
3.3 在Apache[conf]目录下添加文件 mod_jk2.conf
文件内容:
<IfModule mod_jk2.c>
JkSet config.file "C:/Program Files/Apache Group/Apache2/conf/workers.properties"
</IfModule>
注:"C:/Program Files/Apache Group/Apache2/conf/workers.properties" 为workers.properties文件的绝对路径。
4.测试
新建一个【test】WEB工程:index.jsp
内容:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Apache Tomcat 集群测试</title>
</head>
<body>
<center>
<h3><font color="red">Apache Tomcat 集群测试</font> </h3>
</center>
<%
out.write(request.getSession().getId());
%>
</body>
</html>
注:本例程以一台机器为例子,即同一台机器上装一个apache和2个Tomcat。
一、前期准备工作:安装用的程序(前提保证已安装了JDK1.5以上的版本)
apache_2.0.49-win32-x86-no_ssl.msi (下载:http://archive.apache.org/dist/httpd/binaries/win32/)
jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip (下载:http://archive.apache.org/dist/tomcat/tomcat-connectors/jk2/binaries/win32/)
JDK1.6 安装(D:\Program Files\Java\jdk1.6)。
APAHCE 2.0 安装(C:\Program Files\Apache Group\Apache2)。
TOMCAT6.0 解压(绿色版)。
jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip 解压.
二、配置
1.jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip 解压.
复制[jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49\modules\mod_jk2.so] 粘贴到 Apache下的[modules]目录下
2.Tomcat配置
2.1由于2个Tomcat是放在一个电脑上,需要修改不同的 tomcat 的关闭口,避免出现端口被占用的情况。在tomcat6.1\conf, 和tomcat6.2\conf下的 server.xml 中找到3处位置,更改他们的端口号:例子:
(a).<Server port="8081" shutdown="SHUTDOWN">
(b).<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>
(c)..<Connector port="8082" protocol="AJP/1.3" redirectPort="8443"/>
2.2 注释掉[<Engine name="Catalina" defaultHost="localhost">] 取消[<Engine name="Catalina" defaultHost="localhost" jvmRoute="XXXXX">] 的注释
例如:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<!-- <Engine name="Catalina" defaultHost="localhost">-->
tomcat6.1和tomcat6.2 都需要这样修改,其中"XXXXX"的值需要不一样。
3、Apache配置
3.1、httpd.conf配置
修改APACHE的配置文件(conf\httpd.conf)
3.1.1添加如下代码:
LoadModule jk2_module modules/mod_jk2.so
Include conf/mod_jk2.conf
3.1.2 查找"DirectoryIndex",在它的后面添加要访问的后缀名(index.jsp)
3.2 在Apache[conf]目录下添加文件 workers.properties
文件内容:(配置Tomcat信息)
[shm]
info=Scoreboard. Requried for reconfiguration and status with multiprocess servers.
file=anon
# Defines a load balancer named lb. Use even if you only have one machine.
[lb:lb]
####------------tomcat1 begin------------####
# Example socket channel, override port and host.
[channel.socket:localhost:8082] # 由于tomcat是在本地,所以用localhost,端口号8082 来自与2.1配置中的(c) ,根据自己的填写
port=8082
host=127.0.0.1
# define the worker
[ajp13:localhost:8082]
channel=channel.socket:localhost:8082
group=lb
####------------tomcat1 end------------####
####------------tomcat2 begin------------####
# Example socket channel, override port and host.
[channel.socket:localhost:8072]
port=8072
host=127.0.0.1
# define the worker
[ajp13:localhost:8072]
channel=channel.socket:localhost:8072
group=lb
####------------tomcat2 end------------####
# Map the Tomcat examples webapp to the Web server uri space
[uri:/test/*] #此处为应用的路径
group=lb
[status:]
info=Status worker, displays runtime information
group=status:
3.3 在Apache[conf]目录下添加文件 mod_jk2.conf
文件内容:
<IfModule mod_jk2.c>
JkSet config.file "C:/Program Files/Apache Group/Apache2/conf/workers.properties"
</IfModule>
注:"C:/Program Files/Apache Group/Apache2/conf/workers.properties" 为workers.properties文件的绝对路径。
4.测试
新建一个【test】WEB工程:index.jsp
内容:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Apache Tomcat 集群测试</title>
</head>
<body>
<center>
<h3><font color="red">Apache Tomcat 集群测试</font> </h3>
</center>
<%
out.write(request.getSession().getId());
%>
</body>
</html>