Skip to main content

JEAP 6 - 使用mod_cluster 連接JBoss做Load Balance

先前版本的JBoss 大多用 mod_jk, 但是這個版本的J老闆已經開始支援更聰明的load balance 機制,mod_cluster.
mod_cluster 有什麼好處咧?他可以去判斷server的狀況來決定request 要導到哪一台server 上,如CPU的loading 啦~session 的數量等等。而先前的只有亂數丟,跟輪流丟這兩種方式而已。

在開始設定前,請先確定你的JBoss Cluster 環境已經建立起來了。
如果沒有,請參考先前的文章

1. Standalone 啟動 Cluster
2. Domain 啟動 Cluster

以上兩種選一個即可!
=======================================================

首先,請自己去Apache 的官網下載 Apache 的 HTTP Server, 當然,如果你是Red Hat Enterprise Linux 的客戶,那應該內建就會有了。
如果你是JBoss Enterprise 的客戶,這時就幸運拉,因為安裝的紅帽都幫你準備好了!可以到JBoss EAP 6 的下載網頁裡面,下載最新的HTTP Server!


網路上到處是文章,這裡我就不再贅述Apache 的安裝與使用方式了。
首先,先確定你的 HTTP_INSTALL_PATH/modules 下,有這些so 檔案, 如果沒有,請自己找!當然如果你是JBoss Enterprise 的客戶,一樣可以粉方便地去下載!

請找 :jboss-eap-native-webserver-connectors-xxxxx

mod_proxy_cluster.so
mod_slotmem.so
mod_manager.so
mod_advertise.so








==================================================
Apache 設定
==================================================

開始設定config 檔案。
請到HTTP_INSTALL_PATH/conf 下,打開 httpd.conf
設定去讀取剛剛下載的檔案。


LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
LoadModule slotmem_module modules/mod_slotmem.so
LoadModule manager_module modules/mod_manager.so
LoadModule advertise_module modules/mod_advertise.so


記得將下方的mod_proxy_balancer.so 檔案關閉,不然會有衝突。
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

到httpd.conf檔案的最下方加入以下設定

Listen {你的IP}:10001

#以下這行只有Linux 環境下需要加

MemManagerFile /var/cache/httpd   
<VirtualHost {你的IP}:10001>
  <Directory />
    Order deny,allow
    Allow from all
  </Directory>
  <Location /mod_cluster-manager>
   SetHandler mod_cluster-manager
   Allow from all
  </Location>
  KeepAliveTimeout 60
  MaxKeepAliveRequests 0
  EnableMCPMReceive
  ManagerBalancerName myBalancer
  AdvertiseFrequency 5
</VirtualHost>

重開Apache 這樣mod_cluster 就設定好了。



==================================================
JBoss 設定
==================================================
如果你是Standalone , 請參考先前的Cluster 設定。
如果你是Domain , 請參考先前的Cluster 設定。
以下的設定都是相同的,只是 standalone 模式請改在standalone-ha.xml 裡,
domain 模式的話,就改在domain.xml 你設定的profile中 (例如: ha, full-ha)
告訴JBoss 怎麼樣可以找到剛剛設定的Apache.

以下範例是我的domain.xml


<subsystem xmlns="urn:jboss:domain:modcluster:1.1">
   <mod-cluster-config advertise-socket="modcluster" balancer="myBalancer" connector="ajp" proxy-list="Apache的IP:10001">
      <dynamic-load-provider>
         <load-metric type="busyness"/>
      </dynamic-load-provider>
   </mod-cluster-config>
</subsystem>

之後啓動JBoss server這樣就完成拉!

確認是否成功,你可以到 http://Apache的IP:10001/mod_cluster-manager 看到以下的畫面拉!


然後,為了確定Cluster 是可以導頁,證明我沒有呼隆~
所以拿了一個自己寫的session test 來證明!
先登入網頁,可以看到Session 是在server four,

把server four 關掉,


重新load 剛剛的網頁,發現session 裡面的值,Christina 還在,
而且server 變成server three.






Comments

JEAP 6 native component內沒有包含這幾個so檔ㄟ, JEAP 5 native component才有ㄟ, 是不是沒包好
Christina Lin said…
那時抓圖沒抓好,應該是jboss-eap-native-webserver-connectors 我已經更正了!
Hi,

Could u translate this in English...tq
請問一下如果有其中一台jboss發生錯誤,前端的apache仍會把session轉送至這台有問題的jboss,有辦法避免嗎? 謝謝!!

Popular posts from this blog

Red Hat JBoss Fuse/A-MQ - Fuse and A-MQ Version 6.3 GA is released!

Fuse and A-MQ 6.3 GA has just went out. Maybe, you would think this is just only a minor version release why should I care? Hold your thoughts on that! Because they have done a lot of improvements and also added many new features into this release.

Besides various bug fixes and making sure Fuse Fabric is much more stable. There are two major change in this version update:

New Tooling in JBoss Developer Studio (JBDS) 9.1 GA. Newer Apache Camel version – Camel v2.17. I was really impressed by the work put in to make developing Camel application much simpler. First is the installation of tooling itself. Now it has a all-in-one installer so you don't need to worry about which plugins you need to check. See the videos below to see the new "Getting Started" of Fuse 6.3.



And If you notice from the above video, the presentation of camel route in JBDS has also updated. It fixed some of the miss representation of logic and making it easier to read.

Old Camel Route
New Camel Route
On …

Fuse Integration Service - Setup JBDS and create first quickstart application

Before we go and start creating our first application, I want to show you how to setup your JBoss Developer Studio, create a small application from the quickstart example and then running it on Fuse Integration Service.

I am using JBoss Developer Studio version 9, you can find it here.
After download the

jboss-devstudio-9.0.0.GA-installer-eap.jar
double-click it, and start installing with default values.

After successful installation, we will need install the plugins for Fuse, on JBoss Central view, select software update, select enable early access.


And select JBoss Fuse Development for the plugin,


Click on install, and we are all set to go!

First thing first, we want to create a Fuse project to deploy on the base of Fuse Integration Service, which is OpenShift. If you have not installed it, please go back to my previous post for instructions. So on your JBDS, right click and start creating the project. Select new, maven project, if you have installed the plugin correctly, you should …

Red Hat JBoss Fuse - Getting Started with Fuse Integration Service 2.0 Tech preview

I just realized that I did not do a getting started for Fuse Integration Service 2.0 Tech preview before I did the pipeline demo, thanks for those of you who reminded me! :)

To get started with FIS 2.0, for people who has just getting to know the technology, here is how I interpret it. Basically, it's divide into two aspect,

1. Integration development, FIS uses Apache Camel as the core technology that creates, orchestrate, compose microservices into a super lightweight thin integration layer, and become the API provider and service orchestrator through exposing RESTful or messaging service endpoints. And you can choose to either package and run it with Spring-Boot or Karaf.


2. Application Deployment and Management, FIS takes advantages of OpenShift platform, and allows you to separately deploy the micro-integration service among distributed environment, at the same time takes care of the failover, high availability, load balancing and service lookup problem for you.


So, now we know …