配置 Liberty 群體
您可以將 Liberty 伺服器組織成群體,以支援能夠作用於多部 Liberty 伺服器的叢集作業、管理作業及其他作業,群體可讓您有效率又精確地將應用程式服務交付給您的應用程式。
開始之前
安裝具有管理特性的 Liberty。如需安裝指示,請參閱利用群體來設定 Liberty 的伺服器管理環境的「開始之前」區段。Liberty 管理特性針對群體、叢集、調整、動態遞送以及「管理中心」,提供多重伺服器管理特性。
關於這項作業
Liberty 群體是配置在相同管理及作業網域中的一組 Liberty 伺服器。
Liberty 群體的配置和狀態資料存放在作用中的作業儲存庫中。
Liberty 群體中的成員資格是選用的。 Liberty 伺服器加入群體,是透過向群體控制器登錄而為成員。 成員會透過控制器的作業儲存庫來共用它們自己的相關資訊。
- Liberty 伺服器可以是單一群體的成員。
- 相同主機上的不同 Liberty 伺服器可以在不同群體中。
- 在相同主機上是某一群體成員的 Liberty 伺服器,可以與不是群體成員的 Liberty 伺服器同時存在。
- 群體的所有成員都必須位於相同的資料中心。群體不得跨越多個資料中心。
程序
- 建立及配置控制器。
- 建立伺服器用來作為群體控制器。
wlp/bin/server create myController
- 建立群體控制器配置。
群體控制器配置主要是由管理網域安全配置(用來維護控制器與成員之間的通訊安全)所組成。
wlp/bin/collective create myController --keystorePassword=controllerKSPassword
依預設,這個群體指令會將所有輸出寫到主控台畫面中。 下一步是將配置輸出複製到 server.xml 中。 如果要將配置寫到檔案中,而不是寫到主控台畫面,請指定 --createConfigFile=outputFilePath 參數;例如:
執行 create 指令之後,會顯示要使用的 include 陳述式。如果要將輸出的檔案包含在群體配置中,請將 include 陳述式新增至 server.xml 檔,如下列範例所示:wlp/bin/collective create myController --keystorePassword=controllerKSPassword --createConfigFile=c:/wlp/usr/servers/myController/collective-create-include.xml
<include location="c:\wlp\usr\servers\myController\collective-create-include.xml" />
- 更新群體控制器的 server.xml 檔。
- 複製並貼上輸出。
如果指令將輸出寫入到主控台畫面,請繼續執行下列步驟。
- 複製群體指令的輸出,將它貼到 server.xml 檔中。
- 指定群體的管理使用者 ID 和密碼值。例如,變更:
為:<quickStartSecurity userName="" userPassword="" />
<quickStartSecurity userName="adminUser" userPassword="adminPassword" />
群體控制器 server.xml 檔的預設路徑是 ${wlp.install.dir}/usr/servers/myController/server.xml,或者如果在 server.env 檔或指令視窗中設定了 $WLP_USER_DIR 變數,則預設路徑是 $WLP_USER_DIR/servers/myController/server.xml。編輯之後的檔案類似下列範例:<server description="controller server"> <!-- Enable features --> <featureManager> <feature>jsp-2.2</feature> </featureManager> <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443" /> <featureManager> <feature>collectiveController-1.0</feature> </featureManager> <!-- Define the host name for use by the collective. If the host name needs to be changed, the server should be removed from the collective and re-joined or re-replicated. --> <variable name="defaultHostName" value="controllerHostname" /> <!-- TODO: Set the security configuration for Administrative access --> <quickStartSecurity userName="adminUser" userPassword="adminPassword" /> <!-- clientAuthenticationSupported set to enable bidirectional trust --> <ssl id="defaultSSLConfig" keyStoreRef="defaultKeyStore" trustStoreRef="defaultTrustStore" clientAuthenticationSupported="true" /> <!-- inbound (HTTPS) keystore --> <keyStore id="defaultKeyStore" password="yourPassword" location="${server.config.dir}/resources/security/key.jks" /> <!-- inbound (HTTPS) truststore --> <keyStore id="defaultTrustStore" password="yourPassword" location="${server.config.dir}/resources/security/trust.jks" /> <!-- server identity keystore --> <keyStore id="serverIdentity" password="yourPassword" location="${server.config.dir}/resources/collective/serverIdentity.jks" /> <!-- collective trust keystore --> <keyStore id="collectiveTrust" password="yourPassword" location="${server.config.dir}/resources/collective/collectiveTrust.jks" /> <!-- collective root signers keystore --> <keyStore id="collectiveRootKeys" password="yourPassword" location="${server.config.dir}/resources/collective/rootKeys.jks" /> </server>
- 新增 include 陳述式。如果您使用 --createConfigFile=outputFilePath 參數,將輸出寫入至檔案,請新增 include 陳述式到 $WLP_USER_DIR/servers/myController/server.xml,以便將輸出的檔案包含在群體配置中。 在編輯之後,檔案的內容類似下列範例:
<server description="controller server"> <!-- Enable features --> <featureManager> <feature>jsp-2.2</feature> </featureManager> <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443" /> <include location="c:\wlp\usr\servers\myController\collective-create-include.xml" /> </server>
請確定輸出的檔案會設定群體的管理使用者 ID 和密碼值,如下列範例所示:<quickStartSecurity userName="adminUser" userPassword="adminPassword" />
- 複製並貼上輸出。
- 啟動群體控制器伺服器。
wlp/bin/server start myController
圖 1. 一個成員的群體 - 驗證群體控制器伺服器啟動正確,並可準備接收成員。
- 在編輯器中開啟群體控制器的訊息日誌 ($WLP_USER_DIR/servers/myController/logs/messages.log)。
- 尋找下列訊息:
CWWKX9003I: CollectiveRegistration MBean 可供使用。
- 建立伺服器用來作為群體控制器。
- 建立及配置成員,以加入群體中。
控制器和成員可以在不同主機上。在這個範例中,控制器和成員是在相同主機上。
- 建立一個成員伺服器。
wlp/bin/server create myMember
- 加入成員。
執行群體 join 指令,將伺服器加入群體中成為成員。從成員主機上的 Liberty 安裝架構,執行 join 指令。
join 指令需要一條指向群體控制器的網路連線,以及能夠在控制器上執行 MBean 作業的管理使用者 ID 和密碼。請查看群體控制器的 server.xml 檔,找出 --host、--port、--user 和 --password 參數的值。對於 --keystorePassword,請設定一值,以用於成員金鑰儲存庫密碼,例如 memberKSPassword。您可以為加入群體的每一部伺服器,指定不同的 --keystorePassword 值。
wlp/bin/collective join myMember --host=controllerHostname --port=9443 --user=adminUser --password=adminPassword --keystorePassword=memberKSPassword
選用參數 --hostname 指定要用於系統的主機名稱。 只有當系統有多個主機名稱,或未配置其主機名稱時,才需要設定 --hostname。 如果設定的話,則值必須符合 server.xml 檔中所定義的 defaultHostName 變數。
如果要減少所需要的選項數目,請使用 --controller 選項,而不使用 --user、--password、--host 和 --port。
wlp/bin/collective join myMember --controller=user[:password]@host:HttpsPort --keystorePassword=memberKSPassword
您可以使用選用參數 genDeployVariable 指定部署變數。如需相關資訊,請參閱將成員伺服器加入至群體時產生部署變數。
如果要將這個群體指令的輸出寫入檔案中,而不是寫入到主控台畫面,請指定選用的 --createConfigFile=outputFilePath 參數。然後新增 include 陳述式至成員的 server.xml 檔案,以便將輸出的檔案包含在群體配置中。<include location=outputFilePath />
依預設,join 作業維持不定義遠端程序呼叫 (RPC) 認證。您必須指定 rpcUser 和 rpcUserPassword 的值,以及成員伺服器所在主機的作業系統登入使用者和密碼。 如果已向群體控制器登錄成員主機,且成員主機未啟用 SSH,請指定 --useHostCredentials 選用參數,讓成員繼承控制器上其主機登錄中的 RPC 認證。 一般而言,Linux 主機會啟用 SSH,Windows 主機不會啟用 SSH;因此,--useHostCredentials 參數對 Windows 成員主機很有用。 如果指定 --useHostCredentials,會將 <hostAuthInfo useHostCredentials="true" /> 新增至成員的 server.xml 檔。之後您就可以執行群體成員伺服器指令,例如 start 或 stop,而不需指定 RPC 認證,因為成員會繼承其主機的認證。如需 hostAuthInfo、--useHostCredentials 參數,以及將群體控制器連接至伺服器的相關資訊,請參閱置換 Liberty 伺服器主機資訊。如需在主機上啟用 SSH 的相關資訊,請參閱設定 RXA 以執行 Liberty 群體作業。
如需這些必要參數和其他選用參數的相關資訊,請在指令行執行 collective help join。
- 如果提示您接受憑證鏈,請輸入 y(是)。
- 更新成員的 server.xml 檔。
- 複製並貼上輸出。
如果指令將輸出寫入到主控台畫面,請繼續執行下列步驟:
- 複製群體指令的輸出,將它貼到成員的 server.xml 檔中。
- 修改埠,使伺服器可以開啟它的 HTTP 埠。請確定成員的 server.xml 已設定其主機上的唯一 HTTP 埠號。比方說,如果成員位於群體控制器的相同主機上,請變更 HTTP 埠號:
如果要選擇性地從遠端用戶端存取成員伺服器,也請在 httpEndpoint 元素中設定 host="*"。<httpEndpoint id="defaultHttpEndpoint" httpPort="9081" httpsPort="9444" />
在編輯之後,$WLP_USER_DIR/servers/myMember/server.xml 檔類似下列範例:<server description="member server"> <!-- Enable features --> <featureManager> <feature>jsp-2.2</feature> </featureManager> <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9081" httpsPort="9444" /> <featureManager> <feature>collectiveMember-1.0</feature> </featureManager> <!-- Define the host name for use by the collective. If the host name needs to be changed, the server should be removed from the collective and re-joined or re-replicated. --> <variable name="defaultHostName" value="memberHostname" /> <!-- Remote host authentication configuration --> <hostAuthInfo rpcUser="admin_user_id" rpcUserPassword="admin_user_password" /> <!-- Connection to the collective controller --> <collectiveMember controllerHost="controllerHostname" controllerPort="9443" /> <!-- clientAuthenticationSupported set to enable bidirectional trust --> <ssl id="defaultSSLConfig" keyStoreRef="defaultKeyStore" trustStoreRef="defaultTrustStore" clientAuthenticationSupported="true" /> <!-- inbound (HTTPS) keystore --> <keyStore id="defaultKeyStore" password="yourPassword" location="${server.config.dir}/resources/security/key.jks" /> <!-- inbound (HTTPS) truststore --> <keyStore id="defaultTrustStore" password="yourPassword" location="${server.config.dir}/resources/security/trust.jks" /> <!-- server identity keystore --> <keyStore id="serverIdentity" password="yourPassword" location="${server.config.dir}/resources/collective/serverIdentity.jks" /> <!-- collective truststore --> <keyStore id="collectiveTrust" password="yourPassword" location="${server.config.dir}/resources/collective/collectiveTrust.jks" /> </server>
- 新增 include 陳述式。如果您使用 --createConfigFile=outputFilePath 參數,將輸出寫入至檔案,請新增 include 陳述式到 $WLP_USER_DIR/servers/myMember/server.xml,以便包含輸出的檔案,如下列範例所示:
<server description="member server"> <!-- Enable features --> <featureManager> <feature>jsp-2.2</feature> </featureManager> <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9081" httpsPort="9444" /> <include location="c:\wlp\usr\servers\myMember\collective-join-include.xml" /> </server>
- 複製並貼上輸出。
- 如果未在 join 指令中指定 --useHostCredentials,且成員主機未啟用 SSH,請在成員的 server.xml 檔或輸出的檔案中設定 hostAuthInfo 的 RPC 認證。 為成員伺服器設定 RPC 認證的方式有兩種:
- 設定 hostAuthInfo RPC 使用者和密碼值。將 rpcUser 設為成員伺服器所在主機的作業系統登入使用者 ID,將 rpcUserPassword 設為該使用者 ID 的作業系統登入密碼。比方說,如果您使用使用者 test1 和密碼 test1pwd 登入成員電腦,請變更 hostAuthInfo 元素:
<hostAuthInfo rpcUser="test1" rpcUserPassword="test1pwd" />
- 如果成員主機已向群體控制器登錄,請將成員伺服器的 hostAuthInfo useHostCredentials 設為 true,以繼承其主機的 RPC 認證。
<hostAuthInfo useHostCredentials="true" />
如需 hostAuthInfo 設定的相關資訊,以及顯示如何登錄成員主機和執行 join 指令時使用 --useHostCredentials 的範例,請參閱置換 Liberty 伺服器主機資訊。
- 設定 hostAuthInfo RPC 使用者和密碼值。將 rpcUser 設為成員伺服器所在主機的作業系統登入使用者 ID,將 rpcUserPassword 設為該使用者 ID 的作業系統登入密碼。比方說,如果您使用使用者 test1 和密碼 test1pwd 登入成員電腦,請變更 hostAuthInfo 元素:
- 僅針對 z/OS,請發出 updateHost 指令來指定控制器的成員 JAVA_HOME 目錄。
wlp/bin/collective updateHost controllerHostname --host=controllerHostname --port=9443 --user=adminUser --password=adminPassword --hostWritePath=/dir1 --rpcUser=rpcUser --rpcUserPassword=rpcUserPassword --hostJavaHome=JAVA_HOME
如果要減少所需要的選項數目,請使用 --controller 選項,而不使用 --user、--password、--host 和 --port:
wlp/bin/collective updateHost controllerHostname --controller=adminUser:adminPassword@controllerHostname:9443 --hostWritePath=/dir1 --rpcUser=rpcUser --rpcUserPassword=rpcUserPassword --hostJavaHome=JAVA_HOME
hostWritePath 參數指定群體控制器可寫入的目錄。 參數所指定的路徑也可供讀取。
hostWritePathhostJavaHome 參數指定 JVM 在系統上所在以及成員伺服器執行所在的絕對路徑,例如,/usr/lpp/java/java_1.7_64。
如需指定 JAVA_HOME 的相關資訊,請參閱設定 Liberty 群體成員和控制器的 JAVA_HOME 變數。
- 啟動成員伺服器。
wlp/bin/server start myMember
圖 2. 簡式群體 - 驗證成員伺服器啟動正確,並且正在發佈資訊到控制器。
- 在編輯器中開啟成員的訊息日誌 $WLP_USER_DIR/servers/myMember/logs/messages.log。
- 尋找下列訊息(順序不拘):
CWWKX8112I: 已順利將伺服器的主機資訊發佈到群體儲存庫。CWWKX8114I: 已順利將伺服器的路徑發佈到群體儲存庫。CWWKX8116I: 已順利將伺服器的「已啟動」狀態發佈到群體儲存庫。
- 選擇性的:
使用 testConnection 指令來驗證連線功能。 這個指令會驗證控制器與成員所在主機之間的 RXA 連線功能。它也會驗證群體控制器與群體成員之間的 JMX 安全連線功能。
其中 hostName,usrDirPath,serverName 是一個值組,用來說明剛才加入的成員伺服器:hostName 是群體成員所在主機的名稱。 userDirPath 是群體成員的 usr 目錄。serverName 是群體成員的名稱。wlp/bin/collective testConnection hostName,usrDirPath,serverName --host=controllerHost --port=controllerHTTPSPort --user=controllerAdmin --password=controllerAdminPassword--autoAcceptCertificates
另外,請使用簡化的 --controller 選項,來提供控制器的特定資訊。
wlp/bin/collective testConnection hostName,usrDirPath,serverName --controller=user[:password]@host:HttpsPort --autoAcceptCertificates
- 建立一個成員伺服器。
次主題
- 使用開發人員工具來配置 Liberty 群體
您可以在開發人員工具中,利用 Liberty 的公用程式功能表,來建立群體控制器或加入群體。 - 將成員伺服器加入至群體時產生部署變數
當您將成員伺服器加入至群體時,您可以使用群體 join 指令的 genDeployVariables 選項,來配置部署變數(埠)。

檔名:tagt_wlp_configure_collective.html