欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Apache jboss 集群详细配置 博客分类: 技术文档 Apachejboss集群配置 

程序员文章站 2024-03-16 15:30:22
...

一.准备工作 

  下载jdk ,安装jdk
  下载jboss,安装jboss
  下载apache http,安装apache http,下载mod_jk-apache-2.0.59.so,拷贝到apache的

   modules目录下

 
二.配置
 
1.配置jboss
    说明:假设有两台服务器,分别安装了jboss,两台服务器的ip地址  为:192.168.1.1、192.168.1.2

    a.拷贝文件
     把jboss的server/all/lib目录下的
     jbossha.jar(加载org.jboss.ha.framework.server.ClusterPartition)
     jgroups.jar(JBoss集群底层通信协议)
     jboss-cache-jdk50.jar (加载org.jboss.cache.aop.TreeCacheAop)文件拷贝到server/default/lib目录下
     再把jboss的server/all/deploy里的cluster-service.xml和jboss-web-cluster.sar拷贝到
     jboss的server/default/deploy目录下

    b.编辑jboss/server/default/deploy/jboss-web.deployer/server.xml文件
      修改下面代码:
      <Engine name="jboss.web" defaultHost="localhost">
      修改为:
      <Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
      其中 jvmRoute是用来让apache识别的节点名称,一个节点一个名称。
      同理编辑192.168.1.2的jboss/server/default/deploy/boss-web.deployer/server.xml文件,注意

      把 jvmRoute设置为node2,
      可以设置成别的只要和192.168.1.1的不重复就行,但是要和Apache workers.properties保持一致

    c.编辑jboss/server/default/deploy/jboss-web.deployer/ROOT.war/WEB-INF/web.xml
       在<web-app>节点下增加如下代码:<distributable/>

    d.编辑jboss/server/default/deploy/jboss-web.deployer/META-INF/jboss-service.xml 文件
      把 <attribute name="UseJK">false</attribute>
      改为:<attribute name="UseJK">true</attribute>
      这样的话就会使用粘稠session,这样可以保证用户的所有请求都在同一台服务器上
    
   2.配置apache
     说明:我们使用apache的mod_jk来做jboss的web集群,浏览器请求apache服务器,apache服务器根据 

     workers.properties中的配置 进行request分发,apache服务器和JBoss中的Tomcat可以用ajp1.3进行

     通信的,request通过ajp1.3协议的包装被发送到JBoss,JBoss执行后返回结果。 

     a.在apache\conf\目录下 新建mod-jk.conf文件并添加如下内容:
        # Load mod_jk module
        # Specify the filename of the mod_jk lib
        LoadModule jk_module modules/mod_jk-apache-2.0.59.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 debug

        # 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

        JkMount /* 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> 
    b.配置apache\conf\httpd.conf文件
        在文件的最后一行加:
        # mod_jk config
        Include conf/mod_jk.conf 

    c.apache/conf/目录下 新建workers.properties文件,该文件就是配置Apache所要将

       request转发到的JBoss的路径信息,代码如下:
        worker.list=loadbalancer,status
        #  Node1
        worker.node1.port=8009
        worker.node1.host=192.168.1.1
        worker.node1.type=ajp13
        worker.node1.lbfactor=1
        worker.node1.cachesize=10
        #  Node2
        worker.node2.port=8009
        worker.node2.host=192.168.1.2 
        worker.node2.type=ajp13
        worker.node2.lbfactor=1
        worker.node2.cachesize=10
        #
        worker.loadbalancer.type=lb
        worker.loadbalancer.balance_workers=node1,node2
        worker.loadbalancer.sticky_session=0 
        worker.status.type=status
        说明:port是配置JBoss AJP所监听的端口号,可以在 

        jobss/server/default/deploy/jbossweb.deployer/server.xml看到,如下
         <!-- A AJP 1.3 Connector on port 8009 -->
         <Connector port="8009" address="${jboss.bind.address}" emptySessionPath="true"

           enableLookups="false"  redirectPort="8443" protocol="AJP/1.3"/>    
         host定义JBoss所在机器的IP地址
         lbfactor定义该节点的权重,数字越大分发到该节点的request越多
         cachesize是servlet线程池的大小(对session复制有影响)


   3.配置web项目
       在web项目的WEB-INF中添加jboss-web.xml文件,内容如下:
       <?xml version="1.0" encoding="UTF-8"?>
       <!DOCTYPE jboss-web PUBLIC 
                 "-//JBoss//DTD Web Application 4.2//EN" 
                 "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
       <jboss-web>
               <replication-config>
                       <replication-trigger>SET_AND_NON_PRIMITIVE_GET</replication-trigger>
                        <replication-granularity>SESSION</replication-granularity>
                        <replication-field-batch-mode>true</replication-field-batch-mode>
                </replication-config>
                <context-root>/</context-root>
       </jboss-web>