这一节讲述Apache+Tomcat+JK配置
运行环境:
WindowXP
Tomcat6.0.18
Apache2.2.15
mod_jk mod_jk-1.2.30-httpd-2.2.3.so
一、负载均衡配置
配置步骤:
1、安装apache2.2.15
2、安装tomcat6.0.18
3、在apache2/conf下创建一个文件mod_jk.conf
mod_jk.conf
[quote]
#加载mod_jk Module
LoadModule jk_module modules/mod_jk.so
#指定 workers.properties文件路径
JkWorkersFile conf/workers.properties
#指定那些请求交给tomcat处理,"lbcontroller"为在workers.propertise里指定的负载分配控制器
JkMount /* lbcontroller
#JkMount /*.jsp lbcontroller
#JkMount /*.do lbcontroller
[/quote]
4、修改httpd.conf,增加下面一句代码
Include conf/mod_jk.conf
5、创建一个workers.properties文件
workers.properties
[quote]
#server 列表
worker.list = lbcontroller
#========tomcat1========
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.port=8029
#tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.host=130.120.2.147
worker.tomcat1.type=ajp13
#server的加权比重,值越高,分得的请求越多
worker.tomcat1.lbfactor = 1
#========tomcat2========
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.port=8019
#tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.host=130.120.2.147
worker.tomcat2.type=ajp13
#server的加权比重,值越高,分得的请求越多
worker.tomcat2.lbfactor = 1
#========controller,负载均衡控制器========
worker.lbcontroller.type=lb
#指定分担请求的tomcat
worker.lbcontroller.balanced_workers=tomcat1,tomcat2
worker.lbcontroller.sticky_session=1
[/quote]
6、修改tomcat sever.xml文件
server.xml
<Connector port="8029" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
AJP端口与workers.properties文件中对应的tomcat AJP端口
7、启动tomcat1,tomcat2,Apache2.2
8、访问一下系统检查一下是否配置成功
配置过程中可能会遇到下列问题:
问题1:
[quote]
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
[/quote]
解决方案:
[quote]
1、直接通过tomcat端口访问系统,访问成功,则问题出来apache配置文件,如mod_jk,workers.properties文件,如下面配置文件就存在一个问题。
worker.controller.type=lb
#指定分担请求的tomcat
worker.lbcontroller.balanced_workers=tomcat1,tomcat2
worker.lbcontroller.sticky_session=1
worker.list = lbcontroller
首先查看apache日志文件
mok_jk.log
[quote]
[Fri Oct 08 17:10:42.921 2010] [3900:812] [warn] jk_map.c (411): The attribute 'worker.lbcontroller.balanced_workers' is deprecated - please check the documentation for the correct replacement.
[Fri Oct 08 17:10:42.921 2010] [3900:812] [info] mod_jk.c (3189): mod_jk/1.2.30 initialized
[Fri Oct 08 17:10:42.984 2010] [3900:812] [warn] jk_map.c (411): The attribute 'worker.lbcontroller.balanced_workers' is deprecated - please check the documentation for the correct replacement.
[Fri Oct 08 17:10:42.984 2010] [3900:812] [info] mod_jk.c (3189): mod_jk/1.2.30 initialized
[Fri Oct 08 17:10:43.093 2010] [1876:5440] [warn] jk_map.c (411): The attribute 'worker.lbcontroller.balanced_workers' is deprecated - please check the documentation for the correct replacement.
[Fri Oct 08 17:10:43.093 2010] [1876:5440] [info] mod_jk.c (3189): mod_jk/1.2.30 initialized
[Fri Oct 08 17:10:43.171 2010] [1876:5440] [warn] jk_map.c (411): The attribute 'worker.lbcontroller.balanced_workers' is deprecated - please check the documentation for the correct replacement.
[Fri Oct 08 17:10:43.171 2010] [1876:5440] [info] mod_jk.c (3189): mod_jk/1.2.30 initialized
[/quote]
原因是下面一句代码配置出错
worker.controller.type------>worker.lbcontroller.type
2、访问不成功就检查tomcat server.xml配置文件
[/quote]
问题2:
[quote]
apache无法启动提示the requested operation has failed
[/quote]
解决方案:
[quote]
原因一:80端口占用
例如IIS,另外就是迅雷。我的apache服务器就是被迅雷害得无法启用!
原因二:软件冲突
装了某些软件会使apache无法启动如Dr.com 你打开网络连接->TcpIp属性->高级->WINS标签 把netbios的lmhosts对勾去掉,禁用tcp/ip的netbios. 然后再启动应该就可以了。
原因三:httpd.conf配置错误
如果apache的配置文件httpd.conf搞错了,在windows里启动它,会提示the requested operation has failed,这是比较郁闷的事,因为查错要看个半天。
其实可以用命令行模式启动apache,并带上参数,apache会提示你哪句有误,然后就可以针对性的解决,命令如下: httpd.exe -w -n "Apache2" -k start
还有一种情况:
即使你这次启动了,下次你都有可能启动失败
在运行里输入:netsh winsock reset
一会儿cmd会提示你重启,不用理会,现在APACHE已经可以启动了。
[/quote]
二、tomcat集群配置参考这篇文章[url]http://xuzhfa123.iteye.com/admin/blogs/694918[/url]
运行环境:
WindowXP
Tomcat6.0.18
Apache2.2.15
mod_jk mod_jk-1.2.30-httpd-2.2.3.so
一、负载均衡配置
配置步骤:
1、安装apache2.2.15
2、安装tomcat6.0.18
3、在apache2/conf下创建一个文件mod_jk.conf
mod_jk.conf
[quote]
#加载mod_jk Module
LoadModule jk_module modules/mod_jk.so
#指定 workers.properties文件路径
JkWorkersFile conf/workers.properties
#指定那些请求交给tomcat处理,"lbcontroller"为在workers.propertise里指定的负载分配控制器
JkMount /* lbcontroller
#JkMount /*.jsp lbcontroller
#JkMount /*.do lbcontroller
[/quote]
4、修改httpd.conf,增加下面一句代码
Include conf/mod_jk.conf
5、创建一个workers.properties文件
workers.properties
[quote]
#server 列表
worker.list = lbcontroller
#========tomcat1========
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.port=8029
#tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.host=130.120.2.147
worker.tomcat1.type=ajp13
#server的加权比重,值越高,分得的请求越多
worker.tomcat1.lbfactor = 1
#========tomcat2========
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.port=8019
#tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.host=130.120.2.147
worker.tomcat2.type=ajp13
#server的加权比重,值越高,分得的请求越多
worker.tomcat2.lbfactor = 1
#========controller,负载均衡控制器========
worker.lbcontroller.type=lb
#指定分担请求的tomcat
worker.lbcontroller.balanced_workers=tomcat1,tomcat2
worker.lbcontroller.sticky_session=1
[/quote]
6、修改tomcat sever.xml文件
server.xml
<Connector port="8029" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
AJP端口与workers.properties文件中对应的tomcat AJP端口
7、启动tomcat1,tomcat2,Apache2.2
8、访问一下系统检查一下是否配置成功
配置过程中可能会遇到下列问题:
问题1:
[quote]
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
[/quote]
解决方案:
[quote]
1、直接通过tomcat端口访问系统,访问成功,则问题出来apache配置文件,如mod_jk,workers.properties文件,如下面配置文件就存在一个问题。
worker.controller.type=lb
#指定分担请求的tomcat
worker.lbcontroller.balanced_workers=tomcat1,tomcat2
worker.lbcontroller.sticky_session=1
worker.list = lbcontroller
首先查看apache日志文件
mok_jk.log
[quote]
[Fri Oct 08 17:10:42.921 2010] [3900:812] [warn] jk_map.c (411): The attribute 'worker.lbcontroller.balanced_workers' is deprecated - please check the documentation for the correct replacement.
[Fri Oct 08 17:10:42.921 2010] [3900:812] [info] mod_jk.c (3189): mod_jk/1.2.30 initialized
[Fri Oct 08 17:10:42.984 2010] [3900:812] [warn] jk_map.c (411): The attribute 'worker.lbcontroller.balanced_workers' is deprecated - please check the documentation for the correct replacement.
[Fri Oct 08 17:10:42.984 2010] [3900:812] [info] mod_jk.c (3189): mod_jk/1.2.30 initialized
[Fri Oct 08 17:10:43.093 2010] [1876:5440] [warn] jk_map.c (411): The attribute 'worker.lbcontroller.balanced_workers' is deprecated - please check the documentation for the correct replacement.
[Fri Oct 08 17:10:43.093 2010] [1876:5440] [info] mod_jk.c (3189): mod_jk/1.2.30 initialized
[Fri Oct 08 17:10:43.171 2010] [1876:5440] [warn] jk_map.c (411): The attribute 'worker.lbcontroller.balanced_workers' is deprecated - please check the documentation for the correct replacement.
[Fri Oct 08 17:10:43.171 2010] [1876:5440] [info] mod_jk.c (3189): mod_jk/1.2.30 initialized
[/quote]
原因是下面一句代码配置出错
worker.controller.type------>worker.lbcontroller.type
2、访问不成功就检查tomcat server.xml配置文件
[/quote]
问题2:
[quote]
apache无法启动提示the requested operation has failed
[/quote]
解决方案:
[quote]
原因一:80端口占用
例如IIS,另外就是迅雷。我的apache服务器就是被迅雷害得无法启用!
原因二:软件冲突
装了某些软件会使apache无法启动如Dr.com 你打开网络连接->TcpIp属性->高级->WINS标签 把netbios的lmhosts对勾去掉,禁用tcp/ip的netbios. 然后再启动应该就可以了。
原因三:httpd.conf配置错误
如果apache的配置文件httpd.conf搞错了,在windows里启动它,会提示the requested operation has failed,这是比较郁闷的事,因为查错要看个半天。
其实可以用命令行模式启动apache,并带上参数,apache会提示你哪句有误,然后就可以针对性的解决,命令如下: httpd.exe -w -n "Apache2" -k start
还有一种情况:
即使你这次启动了,下次你都有可能启动失败
在运行里输入:netsh winsock reset
一会儿cmd会提示你重启,不用理会,现在APACHE已经可以启动了。
[/quote]
二、tomcat集群配置参考这篇文章[url]http://xuzhfa123.iteye.com/admin/blogs/694918[/url]