日期:2014-05-16  浏览次数:20998 次

Apache+Tomcat+JK配置负载均衡
   这一节讲述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
引用

#加载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



    4、修改httpd.conf,增加下面一句代码
       Include conf/mod_jk.conf
    5、创建一个workers.properties文件
      workers.properties
引用

#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

   
     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:
引用

Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.


解决方案:
引用

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
引用

[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 attribut