apache+tomcat负载均衡出错

     手中有一个项目需要用的负载均衡,一般我们会选择apache或者nginx,以前一直用apache做转发,对apache相对熟悉,所以选择了apache。

      tomcat1:http://192.168.100.133:8093/BaseCoreWebComponent/test.jsp  (正常)

      tomcat2:http://192.168.166.243:28094/BaseCoreWebComponent/test.jsp(正常)

      apache : http://127.0.0.1/BaseCoreWebComponent/test.jsp (无法访问)

     于是查看mod_jk.log和重新走查配置过程,发现两个问题:

(1)参考的文章,有个配置写错

  1. worker.controller.type=lb  
  2. worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3  
  3. worker.controller.sticky_session=false  
  4. worker.controller.sticky_session_force=1  
  5. #worker.controller.sticky_session=1  

正确的应该是

worker.controller.type=lb
worker.controller.balance_workers=tomcat_8093,tomcat_base_js
worker.controller.sticky_session=false
#worker.controller.sticky_session_force=1
#worker.controller.sticky_session=1

  

 (2)使用了错误的端口

#========tomcat1========
worker.tomcat_8093.port=8693
worker.tomcat_8093.host=192.168.100.133
worker.tomcat_8093.type=ajp13
worker.tomcat_8093.lbfactor = 1
 
#========tomcat2========
worker.tomcat_base_js.port=48024
worker.tomcat_base_js.host=192.168.166.243
worker.tomcat_base_js.type=ajp13
worker.tomcat_base_js.lbfactor = 1

上面标红色的端口需使用

<!-- Define an AJP 1.3 Connector on port 8693 -->
    <Connector port="8693" protocol="AJP/1.3" redirectPort="8493" />

 而非下面的端口

<Connector port="8093" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8493" />

相关推荐