Apache与Tomcat负载均衡设置

在同一台windows上 apache and two tomcat

1. 安装apache2.2
  
    下载 mod_jk.so, put in the directory C:\Apache2.2\modules

2.  修改apche 的 配置文件 http.conf

     added following lines
    
        LoadModule jk_module modules/mod_jk.so

       JkWorkersFile conf/workers.properties
       JkMount /*.jsp loadbalancer  //注意这个名字和workers.properties文件中的控制器名字一致
       JkLogFile logs/mod_jk.log
       JkLogLevel warn
      

3. 新建workers.properties文件, 目录在C:\Apache2.2\conf下

   增加下面的内容
  
   # list the workers by name

   worker.list=loadbalancer,worker1,worker2

   # localhost server 1
   # ————————
   worker.worker1.port=8019
   worker.worker1.host=localhost
   worker.worker1.type=ajp13
   worker.worker1.lbfactor = 1

   # localhost server 2
   # ————————
   worker.worker2.port=8029
   worker.worker2.host=localhost
   worker.worker2.type=ajp13
   worker.worker2.lbfactor = 1 权重, 数字越大,分配的几率越高

   worker.loadbalancer.type=lb
   worker.loadbalancer.balanced_workers=worker1, worker2
   worker.loadbalancer.sticky_session=1
   

4. 下载tomcat的解压版, 解压在两个不同的目录中

    修改Server.xml
   
    tomcat1 修改下列的配置, 主要是改变端口号 jvmRoute
    <Server port="8015" shutdown="SHUTDOWN">
    <Service name="Tomcat1">
    <Connector port="8060" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />
    <Connector port="8019" protocol="AJP/1.3" redirectPort="8443" />
    <Engine name="Standalone" defaultHost="localhost" jvmRoute="worker1">
    

   
    tomcat2 修改下列的配置, 主要是改变端口号 jvmRoute
    <Server port="8025" shutdown="SHUTDOWN">
    <Service name="Tomcat2">
    <Connector port="8070" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />
    <Connector port="8029" protocol="AJP/1.3" redirectPort="8443" />
    <Engine name="Standalone" defaultHost="localhost" jvmRoute="worker2">
    

5. 启动两个tomcat , run startup.bat

6. 在两个tomcat webapp 下 增加一个jsp 文件

   <%
   System.out.println("===========================");
   %>

7.  http://localhost/test/test.jsp
    关掉浏览器,再次访问这个地址, 你会发现控制台会轮流打印, 重复刷新的话, 只会在一个控制台上不断打印, 因为 session还是老

session, 所以不会给你分到另外一台tomcat上去

  
对httd.conf做任何更改后都需要重新启动apache

你可能感兴趣的:(apache,tomcat,windows,jsp,浏览器)