antony@notes:~/suse$ cat "Configure-and-Create-Cluster-Resources.md"
Configure and Create Cluster Resources
Configure and Create Cluster Resources
Preface
本篇文章會主要會採取 Step by Step 和 ScreenShot 的方式介紹,如何在 SUSE Linux Enterprise High Availability Extension 15 SP5 Cluster 中建立和設定 Cluster Resources。
可以透過點擊以下目錄,選擇想看的內容,跳轉至特定章節
:::warning
:::spoiler {state=“open”} 目錄
[TOC]
:::
Overview of Cluster Resouces
What is Cluster Resource?
- 由 Cluster 管理的 Linux Process 或 Resource
- Cluster 不會使用本機的
systemd來管理 Cluster Resouces
- Cluster 不會使用本機的
- Examples:
- IP Address
- Daemons/Services
- Filesystems
- Web Server
- Database
- VM
- 任何其他 server-based 的 applications 或 Service
- Cluster Resouces 被定義在 Cluster Information Database (CIB) 中
- Cluster 會使用 Resouce Agent scripts 來管理
- Active/Passive
- 一次在一個節點上運行
- Active/Active
- 同時在多個節點上運作,甚至是所有的節點
描述
假設把網站伺服器、IP Address 和 DataBase 都定義成 Cluster Resource,並將他們組成一個 Group ( 群組 ),此時 Cluster 會管理這些服務之間的關係,以及發生故障時如何管理這些服務。
Cluster Resource 命名規則
- A cluster resource naming convention is recommended
- Examples:
p-apache2_1- 程序名稱: apache2, 序號一 ( 本尊 )
g-apache2_1- 群組名稱: apache2, 序號一 ( 本尊 )
- 群組可能包含一個 ip address, apache2 和 database, for example:
p-IP_177p-apache2_1p-mariadb_1
loc_g-apache2_1_on_node4- 限制 apache2_1 這個群組包含的所有 Cluster Resource 都只能在 node4 上運作
Cluster Resources 的種類
Primitives
Primitive Resource 是在 SLE HAE 中最基本的資源類型,Process 在任何時間點都只在一台節點上執行,Process 沒有分身。
由 resource agent 管理和監控,因此叢集可以監控並確保它正在運行,如果它運作失敗、停止運作或因某種原因沒有回應,你就可以對其進行設定,例如嘗試重啟一次或重啟兩次。然後,在同一個節點上,我們會考慮將它移到另一個節點上。這些都是設定參數,其中包括 Timeout ( 超時 ) 的設定,譬如可以在設定檔中定義 Process 的啟動、停止和監控,超過某一段時間都沒有回應的時間。
要建立 Primitive Resource,需要定義一個 ID 和指定一些參數,像是 class, provider 和 type。
Groups
- 將一個或多個 Primitive 類型的 Cluster Resource 合併為一個 entity ( 實體 )
- Groups 包含一組需要一起定位、依序啟動和以相反順序停止的資源。
- 只要資源分組後,必須直接對群組來管理,而不是單一組員資源進行管理。
- 如果在群組中的一個資源在啟動時發生錯誤,排在後面的資源將不會運作。
- 可以為 group 設定 Constraints,而不是單獨設定在各個成員上。
Stickiness score= 所有群組組員資源的得分總和
舉例
假設要建立一個網站伺服器需要一個 IP address 和一個 file system
在 SLE HAE 叢集中,可以設定這 3 個獨立的 Primitive Resource :
- The Web server
- IP address
- File system
再將以上 3 個獨立的 Primitive Resource 組一個 Group Resource
這樣做的好處是,如果發生軟體或硬體故障,Group Resource 將切換到另一個叢集中的節點上繼續運作,類似於單一叢集資源的 failing over
Clones
- 在多個節點上同時運作的 Cluster Resource
- Clone types:
- Anonymous
- 每個節點上同時運作相同的 primitive Cluster Resource
- Globally Unique
- 每個節點上同時運作不相同的 primitive Cluster Resource
- Example: IP address
- Anonymous
- The number of clones per cluster can be limited
- Typically the same as the number of nodes
- To avoid all clones being stopped or started together use the option:
interleave=true
Multi-state Resource
- A specialized type of clone resource
- Instances are in one of two states
- Active
- Passive
resources 會同時在不同的 Node 上,不過只有 Active 狀態的 resources 會正在運作,Passive 狀態的 resources 不會運作。
- 可以使用 colocation rules 跟其他 resources 連接。
- Have additional operations:
- Promote ( 把 Passive 狀態的 resources 變成 Active )
- Demote ( 把 Active 狀態的 resources 變成 Passive )
- To avoid all clones being stopped or started together use the option:
interleave=true- Like clone resources
Promotable Resource
- Promotable resources are a specialization of clones.
- They allow the instances to be in one of two operating modes. When first starting up, the resource is considered promotable. A subset of instances can subsequently be promoted.
- To create a promotable resource, define an ID and select the child resource that you want to use for the promotable resource
Supported resource agent classes
對於新增的每個叢集資源,都需要定義 resource agent 所遵循的標準,resource agent 將它們提供的服務抽象為叢集可以理解的資訊,從而使叢集對其管理的資源不作承諾,叢集依靠 resource agent 在收到啟動、停止或監控命令時做出適當反應。
Resource Agent 通常以 shell script 的形式出現。
SUSE Linux Enterprise High Availability 支援以下類別的 resource agents:
Open Cluster Framework (OCF) resource agents
這個 agents 通常在 /usr/lib/ocf/resource.d/ 目錄區中,所有的 OCF Resource Agents 都必須至少具備 start, stop, status, monitor 和 meta-data 的 action,meta-data action 可取得有關如何設定 resource agents 的資訊。
Linux Standards Base (LSB) scripts
LSB resource agent 通常由作業系統提供,可在 /etc/init.d 中找到。 例如,它們必須執行若干操作,至少包括 start, stop, restart, reload, force-reload 和 status。
這些服務的設定並沒有標準化。 如果您打算在高可用性中使用 LSB 腳本,請確保您了解相關腳本的配置方式。 通常可以在 /usr/share/doc/packages/PACKAGENAME 中的相關套件檔案中找到相關資訊。
systemd
Pacemaker 可以管理 systemd 的服務。 systemd 有 unit files,而不是 init scripts。 一般來說,服務(或 unit files)由作業系統提供。
Service
目前有多種類型的系統服務同時存在: LSB ( 屬於 System V init )、systemd 和 upstart。 因此,Pacemaker 支援一種特殊的 alias ( 別名 ),它能找出特定叢集節點適用的系統服務。 當叢集包含 systemd、upstart 和 LSB 服務時,這一點尤其有用。 Pacemaker 會依照以下順序尋找已命名的服務:LSB (SYS-V) 啟動腳本、systemd unit file 或 upstart job。
Nagios
Monitoring plugins(以前稱為 Nagios plugins)允許監控遠端主機上的服務。
STONITH (fencing) resource agents
此類別專用於與 fencing 相關的資源。
Timeout values
resource 的超時值可受下列參數影響:
op_defaults( global timeout for operations )- resource template 中,特定定義的超時值
- 為 resource 定義的特定超時值
如果為 resource 定義了特定值,則該值優先於全域預設值,資源的特定值也優先於 resource template 中定義的值。
正確設定超時值非常重要。 設定過低的超時值會導致大量(不必要的)fencing 操作,原因如下:
- 如果資源逾時,則會發生故障,叢集會嘗試停止該資源。
- 如果停止資源也失敗(例如,由於停止超時設定過低),叢集就會 fences 該節點,叢集會認為發生這種情況的節點已失控。
您可以使用 crmsh 和 Hawk2 調整操作的全域預設值,並設定任何特定的逾時值。 確定和設定超時值的最佳做法如下:
- 檢查資源啟動和停止所需的時間。
- 如果需要,請新增
op_defaults參數並相應設定(預設)逾時值:- 例如,將
op_defaults設定為 60 秒:$ sudo crm configure op_defaults timeout=60 - 對於需要較長時間的資源,可定義單獨的逾時值。
- 例如,將
- 為資源設定操作時,新增單獨的
start和stop操作。 使用Hawk2設定操作時,它會為這些操作提供有用的超時建議。
建立 primitive resources
在群集中使用資源之前,必須先設定。 例如,要將 Apache 伺服器用作群集資源,請先設定 Apache 伺服器並完成 Apache 配置,然後再啟動群集中的相應資源。
如果資源有特定的環境要求,請確保所有群集節點上都有相同的環境需求。 SUSE Linux Enterprise High Availability 無法管理此類配置。 您必須自己完成這項工作。
您可以使用 Hawk2 或 crmsh 建立原始資源。
- 如果需要在服務已在叢集控制下執行測試或維護任務,請確保在手動觸控其中任何一個之前將資源、節點或整個叢集設為 maintenance 模式。
- Cluster resources 和 cluster nodes 的命名應有所不同。否則,
Hawk2將失效。