apache2.2+mod_jk1.2.36+jboss4.2.3集群配置

1、首先确保安装JDK、APACHE、JBOSS
2、打开apache安装目录找到conf/httpd.conf文件,在文档中引入mod-jk.conf文件

 

Include conf/mod-jk.conf

 

3、在该目录下建立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 /* loadbalancer
           
HostnameLookups Off

 

 需注意的是将上述配置拷贝至文件时请先用记事本打开看是否出现乱码,如果出现乱码将无法正确引入该文件需删除乱码文字。其中【JkMount /* loadbalancer】代码块表示那些请求将被转发负载

4、在该目录下建立workers.properties文件,内容如下

 

# Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,status
# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=192.168.3.5
worker.node1.type=ajp13
worker.node1.lbfactor=50
#worker.node1.cachesize=100
# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host=192.168.3.2
worker.node2.type=ajp13
worker.node2.lbfactor=50
#worker.node2.cachesize=100
# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
#1表示使用粘着0表示非粘着
worker.loadbalancer.sticky_session=0
#worker.list=loadbalancer
# Status worker for managing load balancer
worker.status.type=status

 

 该属性文件标识出集群中所有的web服务器;

属性worker.loadbalancer.sticky_session表示是否基于请求的负载,

当其值为1时来自同一session的请求将被转发至同一web服务器


............................................................................ 至此apache+mod-jk配置完成

 

5、配置web服务器支持集群
    ................................................下列配置均修改于all文件夹

    5.1、找到文件deploy/jboss-web.deployer/server.xm中的下列节点l修改如下

 

<Connector protocol="HTTP/1.1" port="8080" address="${0.0.0.0}"
<Connector port="8009" address="${0.0.0.0}"
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
            启动时绑定ip地址:run.bat -a all -b 192.168.3.5
   5.2、找到文件deploy/jboss-web.deployer/META-INF/jboss-service.xml中的下列节点修改如下
<attribute name="UseJK">true</attribute>
   5.3、找到文件deploy/jboss-web-cluster.sar/META-INF/jboss-service.xml中的config节点
           注释掉该节点,放开下面配置的config节点
          将全部down_thread和up_thread的false都改为true.        
  
<TCP bind_addr=192.168.3.5”
<tcpping initial_hosts=”192.168.3.5[7810],192.168.3.2[7810]”
 
      值得注意的是在该文件44行左右存在配置
<attribute name="CacheMode">REPL_SYNC</attribute> 
             值REPL_SYNC表示立即复制,REPL_ASYNC表示延迟复制
其他web服务器配置与该配置保持一致、但需修改jvmRoute="绑定的节点"
.................................................................................................至此web服务器jboss配置完毕
  6、使自己的项目支持集群
          WEB-INF/jboss-web.xml,加入下列配置
<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>
          WEB-INF/web.xml,加入下列配置
<distributable />
 

 ............................................... 至此web项目已支持集群

7、配置缓存支持集群(如果用到)Ehcache
<cacheManagerPeerProviderFactory 
class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
properties="connect=TCP(start_port=7810):
        TCPPING(initial_hosts=192.168.3.2[7810],192.168.3.5[7810];port_range=3;timeout=10000;
        num_initial_members=3;up_thread=true;down_thread=true):
        VERIFY_SUSPECT(timeout=1500;down_thread=false;up_thread=false):
        pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):
        pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;
        print_local_addr=false;down_thread=true;up_thread=true)" 
        propertySeparator="::" />
 
...............................................至此集群全部配置完毕.........附件为mod_jk.so....................

猜你喜欢

转载自zhaotian.iteye.com/blog/1545707