一、准備工作
jbossha.jar 用於加載org.jboss.ha.framework.server.ClusterPartition,2.2 修改配置文件
jgroups.jar 用於支持Jboss集群底層通信
jboss-cache-jdk50.jar 用於加載org.jboss.cache.aop.TreeCacheAop
<?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>/jspdemo</context-root> <!-- 這裡替換你的Java Web應用名 --> </jboss-web>
# 加載mod_jk.so 模塊 LoadModule jk_module modules/mod_jk.so # # 配置 mod_jk.so模塊 # JkWorkersFile conf/workers.properties # 指定哪些請求交由jboss處理 JkMountFile conf/uriworkermap.properties # mod_jk插件的日志 JkLogFile logs/mod_jk.log # mod_jk 的日志級別 JkLogLevel warn
# 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 and your AJP 1.3 port worker.node1.port=6009 worker.node1.host=127.0.0.1 worker.node1.type=ajp13 worker.node1.lbfactor=1 worker.node1.socket_timeout=60 worker.node1.connection_pool_timeout=60 worker.node1.ping_mode=A worker.node1.ping_timeout=20000 worker.node1.connect_timeout=20000 # Define Node2 # modify the host as your host IP or DNS name and your AJP 1.3 port worker.node2.port=7009 worker.node2.host=127.0.0.1 worker.node2.type=ajp13 worker.node2.lbfactor=1 worker.node2.socket_timeout=60 worker.node2.connection_pool_timeout=60 worker.node2.ping_mode=A worker.node2.ping_timeout=20000 worker.node2.connect_timeout=20000 # Load-balancing behaviour worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=node1,node2 worker.loadbalancer.sticky_session=true worker.loadbalancer.sticky_session_force=false # Status worker for managing load balancer worker.status.type=status
# 這裡表示所有的請求都交給負載均衡器(也就是mod_jk.so這個模塊)進行轉發 /*=loadbalancer #你可以聲明對某些靜態資源的請求無需交給jboss處理. 這樣的話,你需要把這部分靜態資源(比如gif, jpg, css等文件)拷貝到 # Apache服務器的部署目錄中 #!/*.gif=loadbalancer #!/*.jpg=loadbalancer #!/*.png=loadbalancer #!/*.css=loadbalancer #!/*.js=loadbalancer #!/*.htm=loadbalancer #!/*.html=loadbalancer
在兩台Jboss服務器上部署一個相同的Java Web項目(比如通過session緩存記錄JSP頁面的訪問次數)。 啟動進Apache, Jboss進行測試
原文地址:http://jianfeiok.iteye.com/blog/1161698