Windows下配置jboss负载均衡

此文档转载于:http://blog.csdn.net/zhaofeng987/archive/2008/12/25/3597419.aspx

参考资料:http://www.cnblogs.com/bingoidea/archive/2009/06/03/1495743.html

环境说明
 1.服务器有3台,一台安装apache,两台安装jboss

 2.软件准备:

  apache http server 2.2.4,mod jk 1.2.27,jboss,jdk1.5

  下载mod jk 1.2.27:(把下载到的mod jk 拷到%https_home%/moudles目录下,改名为mod_jk.so)
  http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.27/
  下载:jems、http

  http://mirrors.isc.org/pub/apache/httpd/
  http://jaist.dl.sourceforge.net/sourceforge/jboss/jems-installer-1.2.0.GA.jar
 3.ip配置,一台安装apache的ip为192.168.1.6,两台安装jboss的服务器ip分别为192.168.1.3/155
安装过程刘兵召写于2008122316:55
 1.在两台要安装jboss的服务器上先安装jdk,配置环境变量,安装jboss;
 安装jboss步骤:

  执行java –jar jems-installer-1.2.0.GA.jar,出现Jboss安装图形界面。
  选择“中文”。
  下一步。

  同意协议。
  安装路径设置为/usr/local/jboss,下一步。
  选择”all”,下一步。
  选择”advance”,把Name由default改为all.其余直接按下一步。
  输入Admin密码,下一步。
  等待安装结束,完成。
 配置Jboss:
  这里的默认WEB服务端口是8888,找到jboss/server/all/deploy/jbossweb-tomcat55.sar/server.xml,
  jboss默认端口为:8080,修改为8888,同时修改下面代码:
   <Engine name=”jboss.web” defaultHost=”localhost”>
  修改为:
  <Engine name=”jboss.web” defaultHost=”localhost” jvmRoute=”node1″>//注意jvmRoute,看jboss文档 里面用的是jvmRoute还是jmvRoute!其中 jvmRoute是用来让apache识别的节点名称,一个节点一个名称,  注意不要有重复的。
  改变cluster广播地址。$JBOSS_HOME/server/all/deploy/tc5-cluster.sar/META-INF/jboss-service.xml.
  注释掉" <config><UDP mcast_addr="${jboss.partition.udpGroup:230.1.2.7}" .../></config>属性。
  去掉<config><TCP bind_addr=  .... /></config>的注释并修改如下内容:
  <TCP bind_addr="192.168.1.3" 192.168.1.3为本机IP,<TCPPING initial_hosts="192.168.1.3[7810],
  192.168.1.155[7810]" initial_hosts 里面加入集群里面的本服务和其它服务节点,把所有的
  down_thread="false" up_thread="false" 修改为:down_thread="true" up_thread="true"
  同理编辑192.168.1.155的%JBoss_Home%/server/default/deploy/jbossweb-tomcat55.sar/server.xml
  注意把jvmRoute设置为node2,可以设置成别的只要和192.168.1.3的不重复就行,但是要和Apache的  workers.properties下的配置一致。找到jboss/server/all/deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml 把UseJK改为true,在集群各机器的jboss/bin,分别执行run –c all, 测试每个
  jboss的启动是否正常
 
 安装apache
  安装后将apache2/conf/下的httpd.conf 找到ServerName并修改为:ServerName 127.0.0.1:80
 apache mod_jk配置

  在apache2/conf/httpd.conf的末尾增加:Include conf/mod_jk.conf,新建mod_jk.conf,输入以下内容:
   # Load mod_jk module
   # Specify the filename of the mod_jk lib
   LoadModule jk_module modules/mod_jk.so
   # Where to find workers.properties
   JkWorkersFile conf/workers.properties
   # Where to put jk logs
   JkLogFile logs/mod_jk.log
   # Set the jk log level [debug/error/info]
   JkLogLevel info
   # Select the log format
   JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
   # JkOptions indicates to send SSK KEY SIZE
   JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
   # JkRequestLogFormat
   JkRequestLogFormat "%w %V %T"
   # Mount your applications
   JkMount /application/* loadbalancer
   # You can use external file for mount points.
   # It will be checked for updates each 60 seconds.
   # The format of the file is: /url=worker
   # /examples/*=loadbalancer
   JkMountFile conf/uriworkermap.properties
   # Add shared memory.
   # This directive is present with 1.2.10 and
   # later versions of mod_jk, and is needed for
   # for load balancing to work properly
   JkShmFile logs/jk.shm
   # Add jkstatus for managing runtime data
   <Location /jkstatus/>
    JkMount status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
   </Location>
  新建apache2/conf/workers.properties,增加以下内容:

   #定义request所要转发到的节点

   worker.list=loadbalancer,status
   # 定义节点 Node1

   #lbfactor定义该节点的权重,数字越大分发到该节点的request越多
   # modify the host as your host IP or DNS name.
   worker.node1.port=8009
   worker.node1.host=192.168.1.3
   worker.node1.type=ajp13
   worker.node1.lbfactor=1
   worker.node1.local_worker=1
   worker.node1.cachesize=10
   # 定义节点 Node2

   # modify the host as your host IP or DNS name.
   worker.node2.port=8009
   worker.node2.host= 192.168.1.155
   worker.node2.type=ajp13
   worker.node2.lbfactor=1
   worker.node2.local_worker=1
   worker.node2.cachesize=10
   # 负载配置
   worker.loadbalancer.type=lb
   worker.loadbalancer.balance_workers=node1,node2
   worker.loadbalancer.sticky_session=1
   worker.loadbalancer.local_worker_only=1
   # Status worker for managing load balancer
   worker.status.type=status
  至此Apache服务器配置完毕,用Text Configration测试mod_jk加载是否正常,如果正常就可启动Apache
 配置应用程序  在应用程序的web.xml的<web-app>段中增加<distributable />。
  在jboss-web.xml中增加以下内容:
  <jboss-web>
  <replication-config>
  <replication-trigger>SET_AND_NON_PRIMITIVE_GET</replication-trigger>
  <replication-granularity>SESSION</replication-granularity>
  <replication-field-batch-mode>
  在此,我在jboss/server/all/deploy/jbossweb-tomcat55.sar/ROOT.war下创建了一个目录test,加入inex.jsp,  session.jsp,test_action.jsp,文件内容分别如下:
   <%@ page contentType="text/html;charset=ISO8859_1" %>
   <html>
   <head>
   <title>Test</title>
   <meta http-equiv="Content-Type" content="text/html; charset=gb2312″>
   /head>
  
   <body οnlοad="document.form.name.focus()">
   <br><br><br>
   <center>
   The host is : <%=java.net.InetAddress.getLocalHost().toString()%><br>
   Your session id is : <%=session.getId()%><br>
   Your session detail is : <%=session.toString()%><br>
   Your session context is : <%=session.getSessionContext()%><br><br>
   Please input your name:<br>
   <form action="test_action.jsp" method="POST" name="form">
    <input type="input" name="name"/>
    <input type="submit" value="Commit">
   </form>
   </center>
   </body>
   </html>

   <%@ page contentType="text/html;charset=ISO8859_1" %>
   <html>
   <head>
   <title>Test Action</title>
   <meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
   </head>
   <%
    String name = null;
    if(session.getAttribute("name")!=null)
    name = (String)session.getAttribute("name");
    String host = java.net.InetAddress.getLocalHost().toString();
   %>
   <body>
   <br>
   <br>
   <center>
   The host is : <%=host%><br>
   Your session id is : <%=session.getId()%><br>
   Your session detail is : <%=session.toString()%><br>
   Your session context is : <%=session.getSessionContext()%><br><br>
   <%
    if(name!=null){
    out.print("Your name is "+name+"<br>");
    out.print("The session is valid.");
    }
    else{
    out.print("The session is invalid!!!");
    }
   %>
   <a href="index.jsp">Return!</a>
   </center>
   </body>
   <%
    if(session.getAttribute("name")!=null)
    session.invalidate();
   %>
   </html>

   <%@ page contentType="text/html;charset=ISO8859_1" %>
   <html>
   <head>
   <title>Test Action</title>
   <meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
   </head>
   <%
    String name = request.getParameter("name");
    session.setAttribute("name",name);
    String host = java.net.InetAddress.getLocalHost().toString();
   %>
   <body>
   <br>
   <br>
   <center>
   The host is : <%=host%><br><br>
   Your session id is : <%=session.getId()%><br>
   Your session detail is : <%=session.toString()%><br>
   Your session context is : <%=session.getSessionContext()%><br><br>
   Your name is : <%=name%><br>
   This name is set into the session.<br>
   Please click <a href="session.jsp">here</a> to check the session valid or not.
   </center>
   </body>
   </html>
  分布式热部署(distributable hot deploy)

     在一个节点很多的cluster中,如果部署应用的时候必须 把程序文件拷贝到每个机器上的话,
     那实在太愚蠢了,幸好通过all启动的jboss自动支持分布式热部署。把支持cluster的应用(
     通常需要打包成 war文件),放到%jboss%/server/all/farm下,那么处于同一cluster中的
     其他节点会自动下载并且部署,jboss把这个称 为Farm deploy
 到现在我们的jboss集群已经布署完成,在你的浏览器里输入http://1292.168.1.6/test就可以测试了,测试过程你可以看到你的请求是哪个节点处理的……
 apache能够自动发现新启动的Jboss节点。当第一个Jboss节点启动后,自动创建Jboss集群。然后依次将 其他节点加入到集群中。现在 访问http://192.168.1.6,能够看到jboss的状态.说明请求已经被转发到 Jboss节点。集群启动成功。apache能够监视集群中各节点的状况,自动从集群中去掉无法访问的节点, 从而保证每个请求都被响应。当集群的全部节点都停止工作,集群消亡。
 有关Jboss集群的session复制问题请参考jboss相关文档

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangyadong110/archive/2009/09/01/4501493.aspx

发布了26 篇原创文章 · 获赞 0 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/sameseam/article/details/5002899