ZT文萃

          本博不原創(chuàng),轉(zhuǎn)帖自己感興趣那些事人物,什么入眼貼什么,隨心所欲。
          posts - 93, comments - 5, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          http://www.ibm.com/developerworks/cn/websphere/library/techarticles/1303_qiuxl_liberty/1303_qiuxl_liberty.html

          介紹

          WebSphere Liberty Profile Server 介紹

          Liberty 是一款全新的輕量級應(yīng)用服務(wù)器, 具有以下幾個方面的特點:

          1. 高 模塊化——該功能允許用戶根據(jù)自己應(yīng)用程序的需求啟用或者禁用相關(guān)的 feature(所謂 feature,在這里指的是運行應(yīng)用程序所需要的各種資源的支持。比如,應(yīng)用程序用到了 JSP,我們就需要啟動 JSP 這個 feature,如果不在需要此 feature,就可以將其禁用。通過這種模塊化的控制,我們可以按需啟動不同的 feature,包括 JSP, Servlet, JPA 等等,這種控制是實現(xiàn)輕量級應(yīng)用服務(wù)器的基礎(chǔ))。
          2. 輕量級—— Liberty 采用了多種技術(shù)進行瘦身和優(yōu)化(主要是 OSGi 的應(yīng)用),與傳統(tǒng)的 WAS 相比,極大的減少了運行時的內(nèi)存消耗。
          3. 高動態(tài)性——由于采用了 OSGi 的架構(gòu),程序員在開發(fā)的時候,可以動態(tài)修改配置文件,應(yīng)用程序以及服務(wù)器的運行時信息,這些修改都是實時生效的,不需要重啟服務(wù)器。
          4. 快速——由于采用了高模塊化的設(shè)計,Liberty 應(yīng)用服務(wù)器會“按需啟動”,自身消耗的系統(tǒng)資源很少,對執(zhí)行任務(wù)的反應(yīng)時間也非常短,例如,一般來說 Liberty 的啟動時間小于 5 秒。
          5. 配置簡單——在整個開發(fā)過程中,用戶只需要和一個配置文件(server.xml)打交道,而且配置的使用也非常靈活。

          WebSphere eXtreme Scale 介紹

          WebSphere eXtreme Scale 以內(nèi)存網(wǎng)格的方式運行,動態(tài)處理、分區(qū)、復(fù)制和管理數(shù)以萬計服務(wù)器上的應(yīng)用程序數(shù)據(jù)和業(yè)務(wù)邏輯。提供事務(wù)完整性和透明的故障恢復(fù)功能,從而確保高可用性、 高可靠性和一致的響應(yīng)時間。它可以監(jiān)控和管理自己,支持?jǐn)U大和縮小,可以自動從故障恢復(fù)。極大的擴大了應(yīng)用程序可以支持的用戶數(shù)量。用更少的時間服務(wù)更多 的用戶,或者在規(guī)定的、可接受的響應(yīng)時間內(nèi)為更多的用戶提供服務(wù)。

          回頁首

          前提

          • 安裝 Oracle 或者 IBM JDK,并配置好環(huán)境變量。
          • 如果使用 Eclipse,請安裝 WebSphere Application Server V8.5 Liberty Profile Developer Tools

          回頁首

          安裝配置

          安裝 IBM HTTP 服務(wù)器及插件

          本文將使用 IBM 安裝管理器來在測試機 A 中安裝 IBM HTTP 服務(wù)器以及插件。

          • 下載并安裝 IBM Installation Manager 1.5.2 或以上版本
          • 下載添加安裝路徑到 IBM 安裝管理器
          • 選中 IBM HTTP 服務(wù)器以及插件
          圖 1. 安裝成功界面
          圖 1. 安裝成功界面

          安裝 Liberty

          Liberty 支持兩種安裝方式:運行 JAR 文件、使用安裝管理器安裝。本文將介紹如何使用運行 JAR 文件安裝 Liberty 服務(wù)器。在此例中,將會在測試機 A、B 和 C 上安裝 Liberty 服務(wù)器。

          1. 下載 wlp-developers-8.5.0.0.jar 文件到本地機器。
          2. 打開命令行,找到下載的 jar 文件,例如 C:\Liberty。
          3. 執(zhí)行 java -jar wlp-developers-8.5.0.0.jar。
          4. 設(shè)定安裝路徑完成安裝。
          圖 2. Liberty 安裝界面
          圖 2. Liberty 安裝界面

          安裝 WebSphere eXtreme Scale

          WebSphere eXtreme Scale 支持兩種安裝方式:運行 JAR 文件、使用安裝管理器安裝。本文將介紹如何使用運行 JAR 文件安裝 WebSphere eXtreme Scale 插件。在此例中,將會在測試機 A 上安裝 WebSphere eXtreme Scale 插件。

          1. 下載 wxs-wlp_850.jar 文件到本地機器。
          2. 打開命令行,找到下載的 jar 文件,例如 C:\Liberty。
          3. 執(zhí)行 java -jar wlp-developers-8.5.0.0.jar。
          4. 設(shè)定安裝路徑完成安裝。
          圖 3. WebSphere eXtreme Scale 安裝界面
          圖 3. WebSphere eXtreme Scale 安裝界面

          創(chuàng)建 Liberty 服務(wù)器

          1. 進入 Liberty 安裝目錄下的 bin 文件夾
          2. 執(zhí)行服務(wù)器創(chuàng)建命令 server create 服務(wù)器名稱(例如:Test001)

          在本文中將會在測試機 A、B 和 C 上創(chuàng)建三個 Liberty 服務(wù)器實例,分別命名為 Test001,Test002 和 Test003.

          圖 4. Liberty 服務(wù)器創(chuàng)建界面
          圖 4. Liberty 服務(wù)器創(chuàng)建界面

          在 wlp_home/usr/servers 目錄下看到以服務(wù)器命名的文件夾則表示創(chuàng)建成功。

          圖 5. 服務(wù)器創(chuàng)建成功界面
          圖 5. 服務(wù)器創(chuàng)建成功界面

          配置 Liberty 服務(wù)器

          為每個 Liberty 服務(wù)器添加兩個新功能(在 Liberty 中運行嵌入式 XS 服務(wù)器,使用 XS 存儲 HTTP 會話)到 server.xml。添加代碼如下:

          清單 1. Feature 添加示例
              <!-- Enable features -->      <featureManager>          <feature>jsp-2.2</feature>          <feature>localConnector-1.0</feature>          <feature>eXtremeScale.web-1.0</feature>          <feature>eXtremeScale.server-1.0</feature>      </featureManager>

          更改 server.xml 中 HTTP 默認(rèn)端口,可以在 Test002 中使用 9080 端口,在 Test003 中使用 9081 端口。因為不同的服務(wù)器在不同的測試機上,此處我們使用默認(rèn)端口 9080 不會產(chǎn)生沖突。添加代碼如下:

          清單 2. HTTP 端口修改示例
           <httpEndpoint host="*"                httpPort="9080"                httpsPort="9443"                id="defaultHttpEndpoint">

          添加 WXS 配置文件到 Liberty 服務(wù)器,并將 Test001 作為 Catalog 服務(wù)器。Test002 和 Test003 不需要作為 Catalog 服務(wù)器,所以 <xsServer> 標(biāo)簽的 isCatalog 屬性設(shè)定為“false”。添加代碼如下:

          清單 3. XS Server 配置示例
              <!-- Configuration for XS Server -->      <xsServer isCatalog="true"                listenerPort="2809"                serverName="Server1"/>      <!-- Configuration for XS HTTP Session data storage -->   <xsWebApp catalogHostPort="localhost:2809"            objectGridType="REMOTE"            replicationInterval="0"            reuseSessionId="true"            securityEnabled="true"            sessionTableSize="0"/>

          在 Test001 服務(wù)器目錄下創(chuàng)建“grids”文件夾,導(dǎo)入 XML 配置文件 deployment.xml 和 objectgrid.xml

          deployment.xml 文件代碼如下:

          清單 4. deployment.xml 示例
           <?xml version="1.0" encoding="UTF-8"?>   <deploymentPolicy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://ibm.com/ws/objectgrid/   deploymentPolicy ../deploymentPolicy.xsd" 	 xmlns="http://ibm.com/ws/objectgrid/deploymentPolicy">   <objectgridDeployment objectgridName="session">   <mapSet name="sessionMapSet"              numberOfPartitions="47"              minSyncReplicas="0"              maxSyncReplicas="0"              maxAsyncReplicas="1"              developmentMode="false"              placementStrategy="FIXED_PARTITIONS">          <map ref="objectgridSessionMetadata"/>          <map ref="objectgridSessionAttribute.*"/>          <map ref="objectgridSessionTTL.*"/>      </mapSet>   </objectgridDeployment>   </deploymentPolicy>
          清單 5. objectgrid.xml 示例
           <?xml version="1.0" encoding="UTF-8"?>   <objectGridConfig xmlns:xsi="http://www.w3.org/2001/   XMLSchema-instance" xsi:schemaLocation="http://ibm.com/ws/   objectgrid/config ../objectGrid.xsd" xmlns="http://ibm.com/ws/objectgrid/config">   <objectGrids>      <objectGrid name="session" txTimeout="30">          <bean id="ObjectGridEventListener"                className="com.ibm.ws.xs.   sessionmanager.SessionHandleManager"/>          <backingMap name="objectgridSessionMetadata"                      pluginCollectionRef="objectgridSessionMetadata"                      readOnly="false"                      lockStrategy="PESSIMISTIC"                      ttlEvictorType="LAST_ACCESS_TIME"                      timeToLive="3600"                      copyMode="COPY_TO_BYTES"/>          <backingMap name="objectgridSessionAttribute.*"                      template="true"                      readOnly="false"                      lockStrategy="PESSIMISTIC"                      ttlEvictorType="NONE"                      copyMode="COPY_TO_BYTES"/>          <backingMap name="objectgridSessionTTL.*"                      template="true"                      readOnly="false"                      lockStrategy="PESSIMISTIC"                      ttlEvictorType="LAST_ACCESS_TIME"                      timeToLive="3600"                      copyMode="COPY_TO_BYTES"/>      </objectGrid>   </objectGrids>   <backingMapPluginCollections>      <backingMapPluginCollection id="objectgridSessionMetadata">   <bean id="MapEventListener"        className="com.ibm.ws.xs.sessionmanager.MetadataMapListener"/>      </backingMapPluginCollection>   </backingMapPluginCollections>   </objectGridConfig>

          在三個 Liberty 服務(wù)器中添加 <httpSession> 標(biāo)簽,使 Liberty 的會話管理器使用相同的會話 ID,添加代碼如下:

          清單 6. httpSession 重用設(shè)定示例
           <! — Configuration for httpSession resuse -->   <httpSession idReuse="true"/>

          Test002 和 Test003 不需要配置 XS 服務(wù)器,將設(shè)定 isCatalog 為"false", 同時 Test002 和 Test003 不需要創(chuàng)建“grids”文件夾。

          為方便起見,在此我們將 Test001、Test002 和 Test003 導(dǎo)入到 Eclipse(Indigo Service Release 2)。

          圖 6. Liberty 服務(wù)器導(dǎo)入界面
          圖 6. Liberty 服務(wù)器導(dǎo)入界面

          創(chuàng)建部署測試程序

          新建 Web Project,命名為 testApp

          在 WebContent 文件夾下創(chuàng)建 index.jsp 文件,文件代碼如下:

          清單 7. Index.jsp 頁面代碼示例
           <%@page contentType="text/html" pageEncoding="UTF-8"%>   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">     <html>   <head>   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">   <title> 在 Liberty 集群中共享內(nèi)存網(wǎng)格數(shù)據(jù) </title>   </head>   <body>   <h1> 在 Liberty 集群中共享內(nèi)存網(wǎng)格數(shù)據(jù)測試頁面 !</h1>   <%   Integer count;   Object obj_Count = session.getAttribute("COUNT");   if (obj_Count != null) {   count = (Integer) obj_Count;   count = count + 1;   } else {   count = 1;   }   session.setAttribute("COUNT", count);   %>   <h3> 計數(shù)器會在每次頁面加載時加 1</h3>   <h3><font color="#FF0000"> 計數(shù)器  = <%=count%></font></h3>   <h4><font color="#FF0000"><b> 頁面服務(wù)器 :   <%= System.getProperty("wlp.server.name") %></b></font></h4>   <br/>  頁面生成時間 = <%=new java.util.Date().toString()%><br/>   <br/>   </body>   </html>

          將 testApp 分別部署到 Test002 和 Test003,

          圖 7. 測試程序部署界面
          圖 7. 測試程序部署界面

          啟動 Test001 ,Test002 和 Test003 服務(wù)器

          可 以使用命令行啟停 Liberty 服務(wù)器。例如在 Liberty 的安裝目錄的 bin 文件夾下執(zhí)行 server start Test001 來啟動 Test001 服務(wù)器。將測試程序直接拷貝應(yīng)用程序(例如 war 文件)到 dropins 目錄,當(dāng) Liberty 啟動的時候,就會自動掃描,然后啟動文件夾內(nèi)的應(yīng)用程序。前提是在啟動前要配置好 server.xml 中關(guān)于應(yīng)用程序的相關(guān)信息,代碼如下:

          清單 8. 應(yīng)用程序部署示例
           <application id="testApp"               location="testApp.war"               name="testApp"               type="war"/>

          配置 HTTP 服務(wù)器

          為 Test002 和 Test003 生成 plugin-cfg.xml 配置文件。在此使用 JAVA 的 jconsole 生成配置文件

          在 JAVA 的安裝目錄的 bin 文件夾下運行 jconsole。

          圖 8. Jconsole 啟動命令界面
          圖 8. Jconsole 啟動命令界面
          圖 9. Jconsole 啟動界面
          圖 9. Jconsole 啟動界面

          選擇之前創(chuàng)建的 Liberty 服務(wù)器,連接

          在 MBeans 標(biāo)簽下點擊 generateDefaultPluginConfig 方法生成配置文件 .

          圖 10. 配置文件生成界面
          圖 10. 配置文件生成界面

          合并 Test002 和 Test003 的 plugin-cfg.xml 配置文件。文件代碼如下,其中的 IP 分別為測試機 B 和 C 的 IP。

          清單 9. plugin-cfg.xml 代碼示例
           <?xml version="1.0" encoding="UTF-8"?>   <!-- This config file was generated by plugin's merge tool v1.0.0.2 on 2012.10.16 at   16:03:42 CST -->   <Config ASDisableNagle="false"          AcceptAllContent="false"         AppServerPortPreference="HostHeader"          ChunkedResponse="false"         FIPSEnable="false"          IISDisableNagle="false"          IISPluginPriority="High"         IgnoreDNSFailures="false"          RefreshInterval="60"         ResponseChunkSize="64"          SSLConsolidate="false"         SSLPKCSDriver="REPLACE"          SSLPKCSPassword="REPLACE"         TrustedProxyEnable="false"          VHostMatchingCompat="false">      <Log LogLevel="Error" Name=".\logs\defaultServer\http_plugin.log"/>      <Property Name="ESIEnable" Value="true"/>      <Property Name="ESIMaxCacheSize" Value="1024"/>      <Property Name="ESIInvalidationMonitor" Value="false"/>      <Property Name="ESIEnableToPassCookies" Value="false"/>      <Property Name="PluginInstallRoot" Value="."/>      <!-- Server Clusters -->      <ServerCluster CloneSeparatorChange="false"                     GetDWLMTable="false"                    IgnoreAffinityRequests="true"                     LoadBalance="Round Robin"                    Name="Shared_2_Cluster_0"                     PostBufferSize="64"                     PostSizeLimit="-1"                    RemoveSpecialHeaders="true"                     RetryInterval="60">          <Server CloneID="Server3CloneID"             ConnectTimeout="0" ExtendedHandshake="false"             MaxConnections="-1" Name="Server3"             ServerIOTimeout="900" WaitForContinue="false">            <Transport Hostname="9.115.75.85"                       Port="9081"                       Protocol="http"/>          </Server>          <Server CloneID="Server2CloneID"                 ConnectTimeout="0"                  ExtendedHandshake="false"                 MaxConnections="-1"                  Name="Server2"                 ServerIOTimeout="900"                  WaitForContinue="false">                <Transport Hostname="9.111.97.74"                           Port="9081"                           Protocol="http"/>           </Server>           <PrimaryServers>               <Server Name="Server3"/>               <Server Name="Server2"/>           </PrimaryServers>      </ServerCluster>      <!-- Virtual Host Groups -->      <VirtualHostGroup Name="/cell/sharedCell_2/vHostGroup/shared_host_0">          <VirtualHost Name="*:443"/>          <VirtualHost Name="*:80"/>          <VirtualHost Name="*:9080"/>          <VirtualHost Name="*:9081"/>      </VirtualHostGroup>      <!-- URI Groups -->      <UriGroup Name="/cell/sharedCell_2/application/   default_host_defaultServer_default_node_Cluster_URIs">          <Uri AffinityCookie="JSESSIONID"              AffinityURLIdentifier="jsessionid"               Name="/test/*"/>      </UriGroup>      <!-- Routes -->      <Route ServerCluster="Shared_2_Cluster_0"            UriGroup="/cell/sharedCell_2/application/   default_host_defaultServer_default_node_Cluster_URIs"              VirtualHostGroup="/cell/sharedCell_2/vHostGroup/shared_host_0"/>   </Config>

          將合并后的 plugin-cfg.xml 配置文件拷貝到 IBM HTTP 服務(wù)器上。

          下邊所示代碼到 http.conf 文件使 plugin-cfg.xml 配置文件生效

          清單 10. plugin-cfg.xml 生效示例
           LoadModule was_ap22_module "path\to\mod_was_ap22_http.dll"  WebSpherePluginConfig "path\to\plugin-cfg.xml"

          回頁首

          測試

          訪問測試程序

          啟動 HTTP 服務(wù)器以及 Test001、Test002 和 Test003。在測試機 A 上打開瀏覽器,訪問 http://localhost/testApp/ 可以看到 Test002 訪問界面或者 Test003 訪問界面。這依賴于 HTTP 服務(wù)器將請求發(fā)送到 Test002 還是 Test003。

          圖 11. Test002 訪問界面
          圖 11. Test002 訪問界面
          圖 12. Test003 訪問界面
          圖 12. Test003 訪問界面

          以第一次訪問 Test002 為例,此時如果 Test002 發(fā)生故障停機了(在此手動停掉 Test002),當(dāng)再次訪問 http://localhost/testApp/ 時,HTTP 服務(wù)器會將請求發(fā)送到 Test003,如圖 13 所示。但此時計數(shù)器并沒有還原,由于兩個服務(wù)器共享內(nèi)存網(wǎng)格數(shù)據(jù),所以計數(shù)器在首次訪問 Test003 的時候已經(jīng)在 Test002 的基礎(chǔ)上加了一。

          圖 13. Test003 計數(shù)器增加界面
          圖 13. Test003 計數(shù)器增加界面

          參考資料

          主站蜘蛛池模板: 阿瓦提县| 金寨县| 郁南县| 桑植县| 仙游县| 称多县| 乌拉特前旗| 伊吾县| 准格尔旗| 怀化市| 迭部县| 甘谷县| 玉树县| 汉中市| 马边| 伽师县| 夹江县| 喀什市| 绥阳县| 喜德县| 永城市| 泰来县| 清原| 沧州市| 贵州省| 满洲里市| 陵川县| 石棉县| 治县。| 淮安市| 伊金霍洛旗| 渭南市| 东阳市| 绵阳市| 黄骅市| 女性| 昆山市| 得荣县| 巴彦淖尔市| 永兴县| 平塘县|