Linux下配置WebLogic Server集羣

Linux下配置WebLogic Server集羣

=====================Linux下配置WebLogic Server集羣 ================================

本文講述如何在WebLogic Server 8.1上配置集羣,以及通過Proxy Server來訪問集羣,可以參照這個文檔進行linux下weblogic羣集的配置,羣集啓動和節點啓動,發佈應用,同步應用,session的複製共享,測試應用的自動分發功能,自動接管功能。

#######預備知識###########

什麼是Domain和Server

Domain

Domain是WebLogic Server實例的基本管理單元。所謂Domain就是,由配置爲Administrator Server的WebLogic Server實例管理的邏輯單元,這個單元是有所有相關資源的集合。

Server

Server是一個相對獨立的,爲實現某些特定功能而結合在一起的單元。

Domain and Server的關係

一個Domain 可以包含一個或多個WebLogic Server實例,甚至是Server集羣。一個Domain中有一個且只能有一個Server 擔任管理Server的功能,其它的Server具體實現一個特定的邏輯功能。

######本文環境############

? 平臺:Linux as 4

? 軟件:Bea WebLogic Server 8.1 SP5

------配置WebLogic Server集羣------

WebLogic集羣的體系結構

單層混合型的集羣架構(Cluster)

這種架構將所有的Web應用以及相關的服務應用全部置於集羣中的單一WLS實例中,這種架構的優勢在於:

? 易於管理

? 靈活的負載平衡機制

? 更強的安全控制

多層結構的集羣架構(Cluster)

這種架構使用兩個WLS集羣,一個放置表靜態內容和集羣Servlet,另一個放置集羣EJB。一般應用於下面這些情況:

? 在負載平衡機制需要調用集羣EJB中的方法時;

? 在提供內容與提供對象的服務之間需要更大的機動性時;

? 在需要更高的系統穩定性時;

-------配置集羣應用的必要條件-----------

? 集羣中的所有Server必須位於同一網段,並且必須是IP廣播(UDP)可到達的

? 集羣中的所有Server必須使用相同的版本,包括Service Pack

? 集羣中的Server必須使用永久的靜態IP地址。動態IP地址分配不能用於集羣環境。如果服務器位於防火牆後面,而客戶機位於防火牆外面,那麼服務器必須有公共的靜態IP地址,只有這樣,客戶端才能訪問服務器

? 要以CLUSTER方式運行,必須有包含CLUSTER許可的LICENSE才行(從Bea網站上下載的試用版本就可以進行Cluster配置)

-------配置前的準備工作----------------------

在配置集羣應用前要對集羣的配置信息有一個良好的設計,下面就是我們這次配置的集羣信息:

在同一網段內的不同機器上配置集羣,以下是以2臺機器做羣集,

機器類型     操作系統        硬件配置                                角色                          備註

普通PC     Linux as 4   IP:10.3.15.85 PORT:7001   Administrator Server    Pc1

普通PC     Linux as 4   IP:10.3.15.85 PORT:80       Proxy Server                   Pc1

普通PC     Linux as 4   IP:10.3.15.85 PORT:7080   Managed Server            Pc1

普通PC     Linux as 4   IP:10.3.15.84 PORT:7080   Managed Server            Pc2

使用Domain Configuration Wizard進行配置

創建新的Domain

############第一步:#########################

進入到weblogic安裝目下的 /usr/local/wblogic/webloic81/common/bin下面執行 ./config.sh 啓動域配置程序

<----------------------------------------------- BEA WebLogic Configuration Wizard ----------------------------------------------->

Create or Extend a Configuration:

---------------------------------

Choose between creating and extending a configuration. Based on your selection, the Configuration Wizard guides you through the

steps to generate a new or extend an existing configuration.

->1|Create a new WebLogic configuration

| Start here to create a WebLogic configuration in your projects directory.

2|Extend an existing WebLogic configuration

| Start here to extend an existing WebLogic configuration. Use this option to add applications and services, including

|Database access (JDBC) and Messaging (JMS). This option also enables you to extend functionality by enabling WebLogic

|Workshop.

Enter index number to select OR [Exit][Next]> [root@localhost bin]# 1

############第二步:選擇模版 ##################

系統提示選擇一個建立域的模版,資料上講配置嚮導的配置過程可以另存爲模版,以便下次配置的時候使用,沒試過下次回去試試。

<----------------------------------------------- BEA WebLogic Configuration Wizard ----------------------------------------------->

Select a Domain Template:

-------------------------

Please select a template from the list or select another directory of templates.

* [/usr/local/weblogic/weblogic81/common/templates/domains]

1|WebLogic Server Examples Domain 8.1.5.0

| BEA Systems, Inc.

| Create the WebLogic Server Examples domain in a directory outside of the installed kit. The Examples domain contains a

|collection of examples to show best practices for coding individual J2EE APIs.

2|Basic WebLogic Workshop Domain 8.1.5.0

| BEA Systems, Inc.

| Create a basic WebLogic Workshop domain, without installing sample applications. Domains created from this template will

|support the WebLogic Server and WebLogic Workshop runtime functionality, including support for J2EE applications, Web

|applications, Web Services and custom controls. Use domains created from this template for development of WebLogic Workshop

|applications.

->3|Basic WebLogic Server Domain 8.1.5.0

| BEA Systems, Inc.

| Create a basic WebLogic Server domain without installing sample applications.

4|Avitek Medical Records Sample Domain 8.1.5.0

| BEA Systems, Inc.

| Create the Avitek Medical Records domain in a directory outside of the installed kit. The Avitek Medical Records is a

|WebLogic Server sample a1pplication suite that concisely demonstrates all aspects of the J2EE platform.

5|Select another directory location

Enter index number to select OR [Exit][Previous][Next]> 3

這裏我們選擇3,使用基礎的模版

###########第三步:是否以快速模式進行##################

第三步系統提示是否以快速模式進行配置,這裏選擇2。這一步是關鍵!!!!

<----------------------------------------------- BEA WebLogic Configuration Wizard ----------------------------------------------->

Choose Configuration Option:

----------------------------

*Do you want to run the wizard in express mode?

1|Yes

->2|No

Enter index number to select OR [Exit][Previous][Next]> 2

############第四步:配置管理服務器#####################

現在系統提示我們配置管理服務器,把管理服務器的名字改一下,改成adminServer就可以了。

<------- BEA WebLogic Configuration Wizard -------->

Configure the Administration Server:

------------------------------------

Enter adminstration server configurations. Each WebLogic Server domain must have one Administration Server. The

Administration Server hosts the Administration Console which is used to perform administrative tasks.

| Name | Value |

_|__________________|_____________________|

1| *Name: | myserver |

2| Listen address: | All Local Addresses |

3| Listen port: | 7001 |

4| SSL listen port: | N/A |

5| SSL enabled: | false |

Select Option:

1 - Modify "Name"

2 - Modify "Listen address"

3 - Modify "Listen port"

4 - Modify "SSL enabled"

Enter option number to select OR [Exit][Previous][Next]> 1

輸入1之後,根據系統提示輸入新的管理服務器的名稱adminServer

###########第五步:配置被管服務器########################

根據下面系統的提示,配置被管服務器,這一步同樣關鍵!!!!!!!!!!!

<----------------------------------------------- BEA WebLogic Configuration Wizard ----------------------------------------------->

Choose Configuration Option:

----------------------------

*Do you want to configure Managed Servers, Clusters and Machines?

->1|Yes

2|No

Enter index number to select OR [Exit][Previous][Next]> 1

根據提示配置如下信息:

<----------------------------------------------- BEA WebLogic Configuration Wizard ----------------------------------------------->

Configure Managed Servers:

--------------------------

Add or delete configuration information for managed servers. A typical production environment has one or more managed servers. Each managed server is an instance of WebLogic Server used to host enterprise applications.

| Name* | Listen address | Listen port | SSL listen port | SSL enabled |

_|__________|________________|_____________|_________________|_____________|

1| mServer1 | 10.3.15.85 | 7080 | N/A | false |

->2| mServer2 | 10.3.15.84 | 7080 | N/A | false |

然後執行下一步

#########第六步:配置集羣  #################################

輸入集羣的名字testCluster,其他默認即可!!!

<----BEA WebLogic Configuration Wizard ------>

Configure Clusters:

-------------------

A cluster contains multiple WebLogic Server instances (servers) that run simultaneously and work together to provide

increased scalability and reliability. A cluster appears to be a single WebLogic Server instance to clients.

| Name* | Multicast address | Multicast port | Cluster address |

_|_______|___________________|________________|_________________|

Enter name for a new Cluster OR [Exit][Previous][Next]> testCluster

輸入集羣的名字testCluster,其他的默認就行了,配置完成後如下:

| Name* | Multicast address | Multicast port | Cluster address |

_|_____________|___________________|________________|_________________|

->1| testCluster | 237.0.0.1 | 7777 | |

#########第七步:將服務器組織到集羣中########################

根據系統的提示,將mServer1和mServer2放入集羣testCluster中去,配置完成後如下:

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Assign Servers to Clusters:

---------------------------

Assign managed servers to a cluster in the domain.

    Cluster

    |_____testcluster [1]

Enter number exactly as it appears in brackets to toggle selection OR [Exit][Previous][Next]> 1

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Assign Servers to Clusters:

---------------------------

Assign managed servers to a cluster in the domain.

    *Select WebLogic Servers and assign them to a cluster. testcluster

   1|mserver1

   2|mserver2

Select Option:

    1 - Select

    2 - Select All

Enter option number to select OR [Exit][Discard][Accept]>

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Assign Servers to Clusters:

---------------------------

Assign managed servers to a cluster in the domain.

    *Select WebLogic Servers and assign them to a cluster. testcluster

 ->1|mserver1

 ->2|mserver2

Select Option:

    1 - Unselect

    2 - Unselect All

    3 - Reset

Enter option number to select OR [Exit][Discard][Accept]> 回車

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Assign Servers to Clusters:

---------------------------

Assign managed servers to a cluster in the domain.

    Cluster

    |_____testcluster [1]

         |_____mserver1

         |_____mserver2

Enter number exactly as it appears in brackets to toggle selection OR [Exit][Previous][Next]>

##############下面這兩步不知道該怎麼設,暫且略過#############

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Configure Machines:

-------------------

A machine is the logical representation of the system that hosts one or more WebLogic Server instances (servers). The Administration Server and Node Manager application use the machine definition to start remote servers.

    | Name* | Node manager listen address | Node manager listen port |

   _|_______|_____________________________|__________________________|

Enter name for a new Machine OR [Exit][Previous][Next]>

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Configure Unix Machines:

------------------------

A machine is the logical representation of the system that hosts one or more WebLogic Server instances (servers). The Administration Server and Node Manager application use the machine definition to start remote servers.

    | Name |

   _|______|

Enter name for a new Unix Machine OR [Exit][Previous][Next]>

############第八步:配置機器、jdbc、jms、安全等###############

接下來幾步系統提示配置Machines,jdbc,jms,安全,這裏都不用配置,全部回車就行了。

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Choose Configuration Option:

----------------------------

    *Do you want to configure JDBC (Java Database Connectivity)?

   1|Yes

 ->2|No

Enter index number to select OR [Exit][Previous][Next]>

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Choose Configuration Option:

----------------------------

    *Do you want to configure JMS (Java Messaging Service)?

   1|Yes

 ->2|No

Enter index number to select OR [Exit][Previous][Next]>

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Choose Configuration Option:

----------------------------

    *Do you want to configure Advanced Security?

   1|Yes

 ->2|No

Enter index number to select OR [Exit][Previous][Next]>

#######第九步:輸入管理服務器的用戶名和密碼###################

系統提示如下畫面,可以配置管理服務器的用戶名和密碼:

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Configure Administrative Username and Password:

-----------------------------------------------

Create a user automatically assigned to the Administrative Role. This user is the default administrator used to start development

mode servers.

    |          Name           |              Value              |

   _|_________________________|_________________________________|

   1|       *User name:       |            weblogic             |

   2|     *User password:     |                                 |

   3| *Confirm user password: |                                 |

   4|      Description:       | The default administration user |

Select Option:

    1 - Modify "User name"

    2 - Modify "User password"

    3 - Modify "Confirm user password"

    4 - Modify "Description"

Enter option number to select OR [Exit][Previous][Next]>

#########第十步:選擇啓動模式,jdk和存放目錄###################

啓動模式,jdk和域文件存放目錄的設置比較簡單,根據大家的愛好設置就行了。

這裏啓動模式選擇生產開發模式,jdk使用jRockit,存放目錄默認。

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Domain Mode Configuration:

--------------------------

Enable Development or Production Mode for this domain.

 ->1|Development Mode

   2|Production Mode

Enter index number to select OR [Exit][Previous][Next]>

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Java SDK Selection:

-------------------

 ->1|JRockit SDK 1.4.2_10-8160 @ /opt/software/bea/jrockit81sp6_142_10

   2|Sun SDK 1.4.2_11 @ /opt/software/bea/jdk142_11

   3|Other Java SDK

Enter index number to select OR [Exit][Previous][Next]> 2

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Select the target domain directory for this configuration:

----------------------------------------------------------

    "Target Location" = [/opt/software/bea/user_projects/domains]

Input new Target Location OR [Exit][Previous][Next]> /opt/software/bea/projects

##########十一步:配置域名稱##################################

<------------------------------------------------ BEA WebLogic Configuration Wizard ----------------------------------------------->

Edit Domain Information:

------------------------

| Name | Value |

_|________|__________|

1| *Name: | mydomain |

Enter value for "Name" OR [Exit][Previous][Next]> testClusterDomain

設置域的名稱爲testClusterDomain。

###########十二步:域建立結束#################################

以上步驟都完成後,系統會自動建立這個域,並會生成一些文件等等,完成的界面如下:

<----- BEA WebLogic Configuration Wizard --------->

Creating Domain...

0% 25% 50% 75% 100%

[------------|------------|------------|------------]

[***************************************************]

**** Domain Created Successfully! ****

#########十三步:在另一臺機器上配置節點服務器managed server####

配置過程和上面的一樣,一定要保證參數和上面所設定的參數是一樣的,包括 域名,mServer2的ip 、port ,還有名字一定要和配置第一臺機器時保持一致。否則會導致節點服務器不能啓動

#########十四步: 啓動管理服務器###############################

進入/usr/local/weblogic/weblogic81/user_projects/domains/testClusterDomain/目錄

鍵入./startWebLogic.sh

啓動managed server用如下命令:

在10.3.15.85上啓動mServer1

./startManagedServer mServer1 10.3.15.85:7001

在10.3.15.84上啓動mServer2

./startManagedServer mServer2 10.3.15.85:7001

##########說明:如果沒有提及或特殊說明的步驟都直接按回車即可,以下步驟均可不做

##########十五步: 添加代理服務器proxyServer###################

啓動Administrator Server,

然後進入Console控制檯(http://10.3.15.85:7001/console/),在此我們將代理Server與Administrator Server置於同一臺主機之上。

進入console控制檯後,在&rdquor;Server”結點上單擊右鍵,在彈出菜單上選擇&rdquor;Configure a New Server”,然後配置代理Server的相關信息。(在這裏只要指定名稱,監聽地址,監聽端口就可以了)

代理服務器的名字是 proxyServer 監聽地址: 10.3.15.85 監聽端口 80

&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;&emdash;?????????

通過HttpClusterServlet實現請求的自動分發處理

HttpClusterServlet通過一個WebLogic服務器代理對WebLogic集羣中的其他服務器成員的HTTP請求, 同時HttpClusterServlet還爲代理的HTTP請求提供負載平衡與容錯處理。

實際上實現是很簡單的,遵循下面幾個步驟就可以輕鬆實現請求的自動分發功能:

? 創建一個代理Server(在此我們稱這proxyServer)

? 生成配置文件web.xml

? 生成配置文件weblogic.xml

? 打包生成Web應用

? 在proxyServer上部署應用,並將該應用作爲缺省的Web應用

創建代理Server

啓動Administrator Server,然後進入Console控制檯(http://10.3.15.85:7001/console/),在此我們將代理Server與Administrator Server置於同一臺主機之上。

進入console控制檯後,在&rdquor;Server”結點上單擊右鍵,在彈出菜單上選擇&rdquor;Configure a New Server”,然後配置代理Server的相關信息。(在這裏只要指定名稱,監聽地址,監聽端口就可以了)

 

HttpClusterServlet的部署,主要是Servlet的聲明和映射,並設置初始化參數,可以創建一個Web App,然後直接在web.xml中添加或在管理控制檯上設置HttpClusterServlet的部署信息。最後將它發佈給用來做代理的Server,並將這個Web App設置爲這個Server的缺省WEB應用。

web.xml文件示例

weblogic.xml文件示例

打包WEB應用

可以使用jar命令將proxy應用打包成war文件,我們建一個臨時目錄temp,然後在其中建立如下目錄結構:

使用如下的命令操作,就可完成web應用的打包操作:

JAR &endash;參數 WEB應用名稱 要打包的目錄

當然我們也可以直接部署該目錄,而無需打包,這在項目的開發階段是很有幫助的,便於修改。

部署proxy應用

啓動Administrator Server,然後進入Console控制檯(http://10.3.15.85:7001/console/),在此我們將代理Server與Administrator Server置於同一臺主機之上。

進入console控制檯後,在&rdquor;Web Application Modules”結點上單擊右鍵,在彈出菜單上選擇&rdquor;Deploy a new Web Application Module”,然後選擇要部署的文件或目錄,單擊&rdquor;Target Module”按鈕,然後選擇&rdquor;proxyServer”,單擊&rdquor;Continue”按鈕,到了下一步,單擊&rdquor;Deploy”按鈕,完成部署工作。

部署完成後,查看WEB應用的狀態是&rdquor;FAILS”,造成這種情況的原因是&rdquor;proxyServer”還沒有啓動,我們可以通過下面的命令啓動&rdquor;proxyServer”:

./startManagedServer proxyServer

然後點擊&rdquor;ReDeploy”,重新部署應用,狀態值將變爲&rdquor;Success”。

將WEB應用配置成缺省的WEB應用,weblogic8.1與weblogic6.1有很大的不同,8.1不再支持從console控制檯完成配置的工作,而是在weblogic.xml中通過下面的結點,完成配置的工作。

<context-root> / </context-root>

測試proxy應用

修改web.xml文件,加入下面的結點,然後重啓服務。

<init-param>

<param-name>DebugConfigInfo</param-name>

<param-value>ON</param-value>

</init-param>

打開瀏覽器,訪問下面的地址,會得到下圖所示的結果,這就說明你的配置是成功的。

http://10.3.15.85:8080/placeholder.jsp?__WebLogicBridgeConfig

myserver爲服務地址(在這裏是10.3.15.85)

port爲proxy服務的端口(在這裏是8080)

placeholder.jsp(這是一個不存在的JSP文件,您也可以隨意指定文件名)

__WebLogicBridgeConfig(這個可千萬不能寫錯呦!)

測試集羣的分發功能

編寫測試WEB應用並部署

我們來編寫一個簡單的WEB應用,它會在控制檯和瀏覽器上同時打印出&rdquor;OK”字樣,然後將這個WEB應用部署到集羣中所有Managed Server上面。(代碼見附件)

在這裏我們將通過Apache中所帶的ab包來進行併發訪問的模擬測試,使用如下的命令就可以完成壓力測試。

ab &endash;n 100 &endash;c 10 http://10.3.15.85:8080/index.jsp

ab是測試程序的名稱

參數n代表請求的總數量

參數c代表併發的請求數

url爲要測試壓力的頁面

注:使用這個命令時,一定要在系統路徑中能夠找到該程序,否則不能執行。

壓力測試完成後,我們從Managed Server的控制檯上可以看到,mServer1,mServer2都打印出了&rdquor;OK”字樣,這說明,在併發請求的情況下,集羣能夠將請求進行分發,以達到負載平衡的目的。

測試應用的目錄結構如下,部署與proxy應用的部署一樣,要注意的是要將它部署在Managed Server上面。

可以通過關閉其中的任意一個節點服務器,然後繼續發送請求,就會發現雖然有一個節點關閉,但還是很快的得到響應。可以反覆的關閉其中的任意一臺節點服務器,會發現是同樣的效果。這就是一個節點失敗後其他節點自動接管服務請求。

 

同一網段內不同機器部署集羣

在另外一臺機器上配置&rdquor;Managed Server”時,要指定&rdquor;Admin Server”的名稱,監聽地址,監聽端口。

另外要注意的是,&rdquor;Managed Server”上的配置信息要與&rdquor;Admin Server”中Cluster所指定的配置信息一致。

啓動&rdquor;Managed Server”的命令與上面的一樣,如下所示:

./startManagedServer mServer2 10.3.15.85:7001

集羣配置中要注意的問題

? Admin Server只用於集羣的管理,而不能參與集羣事務。

? Web應用應該部署到集羣上,文件的同步是由WebLogic來完成的。

附錄

Weblogic8.1文檔 http://e-docs.bea.com/wls/docs81/

dev2dev在線 http://dev2dev.bea.com.cn

 

<script type="text/javascript"></script>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章