System Center Operations Manager 中的 Linux 記錄檔監視

重要

此版本的 Operations Manager 已終止支援。 建議您 升級至 Operations Manager 2022

注意

System Center Operations Manager 在 OMS 代理程式淘汰時,不支援 FluentD 型記錄檔監視,此記錄檔已排定於 2024 年 8 月。

System Center Operations Manager 現在已利用使用 Fluentd 的最新版代理程式,來增強 Linux 伺服器的記錄檔監視功能。 此更新基於先前的記錄檔監視提供下列改良功能:

  • 記錄檔名稱和路徑中的萬用字元。
  • 適用於可自訂記錄搜尋的新比對模式,例如,簡單比對、獨佔比對、相互關聯的比對、重複的相互關聯,以及獨佔的相互關聯。
  • 支援 Fluentd 社群所發佈的一般 Fluentd 外掛程式。

基本作業

Linux 中記錄檔監視的基本作業包含下列步驟:

  1. 記錄 (record) 會寫入到 Linux 代理程式上的記錄 (log)。
  2. Fluentd 會收集記錄,並建立模式比對的事件。
  3. 事件會傳送至管理伺服器上的 OMED 服務,並記錄到管理伺服器上的 System Center OMED 服務 事件記錄檔。 (只有在成功從 Fluentd 代理程式傳送事件時, 才會建立 System Center OMED 服務 事件記錄檔)
  4. 自訂管理組件的規則和監視器會收集事件,並在 Operations Manager 中建立警示。

設定概觀

需要執行下列步驟,才能在 Linux 代理程式上啟用記錄檔監視。 下列各節將詳細討論這其中每個步驟。

  1. 匯入最新的 Linux 管理組件。
  2. 在每部要監視的 Linux 電腦上,安裝最新版的 Linux 代理程式。
  3. 建立 Fluentd 設定檔來收集記錄。
  4. 將設定檔複製到 Linux 代理程式。
  5. 使用管理組件範例來建立規則和監視器,以便從記錄收集事件並建立警示。

安裝最新版的 Linux 代理程式

最新版的 Linux 代理程式支援增強記錄檔監視所需的 Fluentd。 您可以在從命令列將代理程式安裝在 UNIX 和 Linux 上取得新代理程式的詳細資料和安裝程序。

設定 Linux 記錄檔監視

Linux 管理組件套件組合具有最新的 Operations Manager 代理程式 (含 Fluentd)。 若要設定 Linux 記錄檔監視,使用者應該執行下列作業:

  1. 使用安裝管理組件的標準程序來匯入最新的 Linux 管理組件。
  2. 在 Linux 伺服器上安裝新的 Linux 代理程式,這可透過探索精靈或以手動方式完成。
  3. 在管理 Linux 代理程式的資源集區中,於每部管理伺服器上啟用 OMED 服務。

OMED 服務會從 Fluentd 收集事件,並將它們轉換成 Operations Manager 事件。 使用者應該匯入自定義管理元件,根據從Linux伺服器收到的事件產生警示。

您可以從 Operations 主控台或手動從管理伺服器或閘道伺服器來啟用 OMED。

從 Operations 主控台

  1. 從 Operations 控制台,移至 [監視>Operations Manager>管理伺服器管理伺服器>狀態]。
  2. 在 [管理伺服器] 狀態窗格中選取管理伺服器。
  3. 在 [工作] 窗格中,選取 [健全狀況服務工作]>[啟用 System Center OMED Server]

手動

  1. 選取 [開始],在 [ 開始搜尋 ] 方塊中,輸入 services.msc ,然後按 Enter
  2. 在詳細數據窗格中,以滑鼠右鍵按下 System Center Operations Manager 外部 DataSource 服務的服務,然後選取 [ 屬性]。
  3. 在 [ 一般] 索引標籤的 [ 啟動 類型] 中,選取 [ 自動],然後選取 [ 確定]。
  4. 在詳細數據窗格中,以滑鼠右鍵按兩下服務,然後選取 [ 啟動]。

建立 FluentD 設定檔

您可以使用設定檔來設定 Fluentd 作業。 針對記錄監視,您需要建立設定檔 (其中包含像是來源記錄檔名稱,以及路徑和篩選等資訊),以定義要收集哪些資料。

主要的 Fluentd 設定檔 omsagent.conf 位於 /etc/opt/microsoft/omsagent/scom/conf/。 您可以直接將記錄檔監視設定新增至此檔案,但您應該建立不同的設定檔,更妥善地管理不同的設定。 您接著要在主檔案中使用 @include 指示詞來包含自訂檔案。

例如,如果您在 /etc/opt/microsoft/omsagent/scom/conf/omsagent.d 中建立 logmonitoring.conf,您會將下列其中一行新增至 fluent.conf

  #Include all configuration files
  @include omsagent.d/*.conf

  #include single configuration file
  @include omsagent.d/logmonitoring.conf

您可以在 Fluentd 設定檔語法 \(英文\) 中取得 Fluentd 設定檔的詳細資料。 下列各節將說明對記錄檔監視而言是唯一之設定檔不同指示詞中的設定。 每一個均包含您可以貼到設定檔並針對您的需求加以修改的範例設定。

完整的用於記錄檔監視的設定檔範例可供您在檢閱和評估之前自行建立。

Source

Source 指示詞定義所收集之資料的來源。 這是您定義記錄檔詳細資料的位置。 Fluentd 會挑選已寫入至來源的每筆記錄,並將其事件提交至 Fluentd 的路由引擎。 您需要在此指示詞中指定標記。 該標記是用來作為 Fluentd 內部路由引擎之指示的字串,可相互關聯不同的指示詞。

此範例顯示所收集並標記為待 Operations Manager 處理的 syslog 記錄。

  <source>

      # Specifies input plugin. Tail is a fluentd input plugin - http://docs.fluentd.org/v0.12/articles/in_tail
      type tail

      # Specify the log file path. Supports wild cards.
      path /var/log/syslog

      # Recommended so that Fluentd will record the position it last read into this file.
      pos_file /home/user1/fluent-test/demo_syslog.log.pos

      # Used to correlate the directives.
      tag scom.log.syslog

      format /(?<message>.*)/

  </source>

相符項目

match 指示詞定義如何使用相符的標記,來處理收集自來源的事件。 系統只會將標記符合模式的事件傳送至輸出目的地。 當一個 match 標記內列出多個模式時,事件就可以比對任何列出的模式。 Type 參數指定要針對這些事件使用哪一個外掛程式。

此範例會處理具有標記比對 scom.log的事件。** 和 scom.alert (** 符合零或多個標記部分) 。 它會指定 out_scom 外掛程式,讓 Operations Manager 管理元件能夠收集事件。

  <match scom.log.** scom.event>

      # Output plugin to use
      type out_scom

      log_level trace
      num_threads 5

      # Size of the buffer chunk. If the top chunk exceeds this limit or the time limit flush_interval, a new empty chunk is pushed to the top of the  
      queue and bottom chunk is written out.
      buffer_chunk_limit 5m
      flush_interval 15s

      # Specifies the buffer plugin to use.
      buffer_type file

      # Specifies the file path for buffer. Fluentd must have write access to this directory.
      buffer_path /var/opt/microsoft/omsagent/scom/state/out_scom_common*.buffer

      # If queue length exceeds the specified limit, events are rejected.
      buffer_queue_limit 10

      # Control the buffer behavior when the queue becomes full: exception, block, drop_oldest_chunk
      buffer_queue_full_action drop_oldest_chunk

      # Number of times Fluentd will attempt to write the chunk if it fails.
      retry_limit 10

      # If the bottom chunk fails to be written out, it will remain in the queue and Fluentd will retry after waiting retry_wait seconds
      retry_wait 30s

      # The retry wait time doubles each time until max_retry_wait.
      max_retry_wait 9m

  </match>

注意

若要停用使用 Fluentd 通訊之 Linux 機器上的「伺服器驗證」,請將 enable_server_auth false 參數新增到 Fluentd 的 SCOM 輸出外掛程式,如下所示:

  <match scom.log.** scom.event>
  type out_scom

  max_retry_wait 9m
  enable_server_auth false
  </match>

篩選

filter 指示詞的語法與相符專案相同,但允許更複雜的篩選要處理哪些數據。 收集的事件必須符合要新增至輸出之所有篩選條件的準則。

此處說明六個適用於記錄檔監視的篩選外掛程式。 使用這其中一或多個篩選,來定義您想要從記錄檔收集的事件。

簡單比對:filter_scom_simple_match

最多接受 20 個輸入模式。 每當有任何模式相符時,傳送一個事件到 Operations Manager。

  <filter tag>
      type filter_scom_simple_match
      regexp1 <key> <pattern>
      event_id1 <event ID>
      regexp2 <key> <pattern>
      event_id2 <event ID>
      .
      .
      .
      regexp20 <key> <pattern>
      event_id20 <event ID>
  </filter>

獨佔比對:filter_scom_excl_match

接受兩個輸入模式。 當單一記錄符合模式 1 但不符合模式 2 時,將事件傳送至 Operations Manager。

  <filter tag>
      type filter_scom_excl_match
      regexp1 <key> <pattern1>
      regexp2 <key> <pattern2>
      event_id <event ID>
  </filter>

重複的相互關聯:filter_scom_repeated_cor

接受三個輸入:模式、時間間隔和多次出現。 找到第一個模式的相符項目時,計時器就會啟動。 如果模式在計時器結束之前符合指定的次數,就會傳送一個事件到 Operations Manager。

  <filter tag>
      type filter_scom_repeated_cor
      regexp <key> <pattern>
      event_id <event ID>
      time_interval <interval in seconds>
      num_occurences <number of occurrences>
  </filter>

相互關聯的比對:filter_scom_cor_match

接受三個輸入:兩個模式和一個時間間隔。 找到第一個模式的相符項目時,計時器就會啟動。 如果定時器結束前第二個模式的相符專案,就會將事件傳送至 Operations Manager。

  <filter tag>
      type filter_scom_cor_match
      regexp1 <key> <pattern1>
      regexp2 <key> <pattern2>
      event_id <event ID>
      time_interval <interval in seconds>
  </filter>

獨佔的相互關聯:filter_scom_excl_correlation

接受三個輸入:兩個模式和一個時間間隔。 找到第一個模式的相符項目時,計時器就會啟動。 如果定時器結束前第二個模式沒有相符專案,就會將事件傳送至 Operations Manager。

  <filter tag>
      type filter_scom_excl_correlation
      regexp1 <key> <pattern1>
      regexp2 <key> <pattern2>
      event_id <event ID>
      time_interval <interval in seconds>
  </filter>

Operations Manager 轉換器:filter_scom_converter

針對接收的所有記錄,將事件傳送至 Operations Manager。 傳送指定的事件識別碼和描述作為事件的一部分。

  <filter tag>
      type filter_scom_converter
      event_id <event ID>
      event_desc <event description>
  </filter>

將設定檔複製到代理程式

Fluentd 設定檔必須複製到您想要監視之所有 Linux 電腦上的 /etc/opt/microsoft/omsagent/scom/conf/omsagent.d。 您也必須在主要設定檔中新增 @include 指示詞,如上所述。

建立規則和監視器

Linux MP 不提供模組以從 FluentD 收集事件。 Linux MP 與 Linux 代理程式綁定。 它是 Linux 代理程式和閘道伺服器上的 Fluentd 模組,可提供增強記錄檔監視的功能。

您必須使用使用 Microsoft.Linux.OMED.EventDataSource 模組建立自己的管理元件,以從 Fluentd 收集事件。

下表列出 Microsoft.Linux.OMED.EventDataSource 的參數。

參數 類型 Description
ComputerName String 必要。 指定要讀取其事件的 Linux 電腦名稱。 儘管可將 ComputerName 參數指定為任何字串,但此參數最常使用 $Target 標記法傳遞到模組。 此模組會嘗試讀取由指定之 Linux 電腦產生的事件。
ManagedEntityId String 必要。 指定受監視實體之受管理的實體識別碼。 ManagedEntityId 參數最常使用 $Target\Id$ 傳遞到模組。
EventNumber 整數 選擇性。 表示要擷取之事件的事件編號。 如果省略此選項,模組會傳回針對該計算機和受控實體產生的所有事件。

設定概觀

需要執行下列步驟,才能在 Linux 代理程式上啟用記錄檔監視。 下列各節將詳細討論這其中每個步驟。

  1. 匯入最新的 Linux 管理組件。
  2. 在每部要監視的 Linux 電腦上,安裝最新版的 Linux 代理程式。
  3. 建立 Fluentd 設定檔來收集記錄。
  4. 將設定檔複製到 Linux 代理程式。
  5. 使用管理組件範例來建立規則和監視器,以便從記錄收集事件並建立警示。

安裝最新版的 Linux 代理程式

最新版的 Linux 代理程式支援增強記錄檔監視所需的 Fluentd。 您可以在從命令列將代理程式安裝在 UNIX 和 Linux 上取得新代理程式的詳細資料和安裝程序。

設定 Linux 記錄檔監視

Linux 管理組件套件組合具有最新的 Operations Manager 代理程式 (含 Fluentd)。 若要設定 Linux 記錄檔監視,使用者應該執行下列作業:

  1. 使用安裝管理組件的標準程序來匯入最新的 Linux 管理組件。
  2. 在 Linux 伺服器上安裝新的 Linux 代理程式,這可透過探索精靈或以手動方式完成。
  3. 在管理 Linux 代理程式的資源集區中,於每部管理伺服器上啟用 OMED 服務。

OMED 服務會從 Fluentd 收集事件,並將它們轉換成 Operations Manager 事件。 使用者應該匯入自定義管理元件,以根據從Linux伺服器收到的事件產生警示。

您可以從 Operations 主控台或手動從管理伺服器或閘道伺服器來啟用 OMED。

從 Operations 主控台

  1. 從 Operations 控制台,移至 [監視>Operations Manager>管理伺服器管理伺服器>狀態]。
  2. 在 [管理伺服器] 狀態窗格中選取管理伺服器。
  3. 在 [工作] 窗格中,選取 [健全狀況服務工作]>[啟用 System Center OMED Server]

手動

  1. 選取 [開始],在 [ 開始搜尋 ] 方塊中,輸入 services.msc ,然後按 Enter
  2. 在詳細數據窗格中,以滑鼠右鍵按下 System Center Operations Manager 外部 DataSource 服務,然後選取 [ 屬性]。
  3. 在 [ 一般] 索引標籤的 [ 啟動 類型] 中,選取 [ 自動],然後選取 [ 確定]。
  4. 在詳細數據窗格中,以滑鼠右鍵按兩下服務,然後選取 [ 啟動]。

建立 FluentD 設定檔

您可以使用設定檔來設定 Fluentd 作業。 針對記錄監視,您需要建立設定檔 (其中包含像是來源記錄檔名稱,以及路徑和篩選等資訊),以定義要收集哪些資料。

主要的 Fluentd 設定檔 omsagent.conf 位於 /etc/opt/microsoft/omsagent/scom/conf/。 您可以直接將記錄檔監視設定新增至此檔案,但您應該建立不同的設定檔,更妥善地管理不同的設定。 您接著要在主檔案中使用 @include 指示詞來包含自訂檔案。

例如,如果您在 /etc/opt/microsoft/omsagent/scom/conf/omsagent.d 中建立 logmonitoring.conf,您會將下列其中一行新增至 fluent.conf

  #Include all configuration files
  @include omsagent.d/*.conf

  #include single configuration file
  @include omsagent.d/logmonitoring.conf

您可以在 Fluentd 設定檔語法 \(英文\) 中取得 Fluentd 設定檔的詳細資料。 下列各節將說明對記錄檔監視而言是唯一之設定檔不同指示詞中的設定。 每一個均包含您可以貼到設定檔並針對您的需求加以修改的範例設定。

完整的用於記錄檔監視的設定檔範例可供您在檢閱和評估之前自行建立。

Source

Source 指示詞定義所收集之資料的來源。 這是您定義記錄檔詳細資料的位置。 Fluentd 會挑選已寫入至來源的每筆記錄,並將其事件提交至 Fluentd 的路由引擎。 您需要在此指示詞中指定標記。 該標記是用來作為 Fluentd 內部路由引擎之指示的字串,可相互關聯不同的指示詞。

此範例顯示所收集並標記為待 Operations Manager 處理的 syslog 記錄。

  <source>

      # Specifies input plugin. Tail is a fluentd input plugin - http://docs.fluentd.org/v0.12/articles/in_tail
      type tail

      # Specify the log file path. Supports wild cards.
      path /var/log/syslog

      # Recommended so that Fluentd will record the position it last read into this file.
      pos_file /home/user1/fluent-test/demo_syslog.log.pos

      # Used to correlate the directives.
      tag scom.log.syslog

      format /(?<message>.*)/

  </source>

相符項目

match 指示詞定義如何使用相符的標記,來處理收集自來源的事件。 系統只會將標記符合模式的事件傳送至輸出目的地。 當一個 match 標記內列出多個模式時,事件就可以比對任何列出的模式。 Type 參數指定要針對這些事件使用哪一個外掛程式。

此範例會處理具有標籤比對 scom.log的事件。** 和 scom.alert (** 符合零或多個標記部分) 。 它會指定 out_scom 外掛程式,以允許 Operations Manager 管理元件收集事件。

  <match scom.log.** scom.event>

      # Output plugin to use
      type out_scom

      log_level trace
      num_threads 5

      # Size of the buffer chunk. If the top chunk exceeds this limit or the time limit flush_interval, a new empty chunk is pushed to the top of the  
      queue and bottom chunk is written out.
      buffer_chunk_limit 5m
      flush_interval 15s

      # Specifies the buffer plugin to use.
      buffer_type file

      # Specifies the file path for buffer. Fluentd must have write access to this directory.
      buffer_path /var/opt/microsoft/omsagent/scom/state/out_scom_common*.buffer

      # If queue length exceeds the specified limit, events are rejected.
      buffer_queue_limit 10

      # Control the buffer behavior when the queue becomes full: exception, block, drop_oldest_chunk
      buffer_queue_full_action drop_oldest_chunk

      # Number of times Fluentd will attempt to write the chunk if it fails.
      retry_limit 10

      # If the bottom chunk fails to be written out, it will remain in the queue and Fluentd will retry after waiting retry_wait seconds
      retry_wait 30s

      # The retry wait time doubles each time until max_retry_wait.
      max_retry_wait 9m

  </match>

注意

若要停用使用 Fluentd 通訊之 Linux 機器上的「伺服器驗證」,請將 enable_server_auth false 參數新增到 Fluentd 的 SCOM 輸出外掛程式,如下所示:

  <match scom.log.** scom.event>
  type out_scom

  max_retry_wait 9m
  enable_server_auth false
  </match>

篩選

filter 指示詞的語法與相符專案相同,但允許更複雜的篩選要處理哪些數據。 收集的事件必須符合要新增至輸出之所有篩選條件的準則。

此處說明六個適用於記錄檔監視的篩選外掛程式。 使用這其中一或多個篩選,來定義您想要從記錄檔收集的事件。

簡單比對:filter_scom_simple_match

最多接受 20 個輸入模式。 每當有任何模式相符時,傳送一個事件到 Operations Manager。

  <filter tag>
      type filter_scom_simple_match
      regexp1 <key> <pattern>
      event_id1 <event ID>
      regexp2 <key> <pattern>
      event_id2 <event ID>
      .
      .
      .
      regexp20 <key> <pattern>
      event_id20 <event ID>
  </filter>

獨佔比對:filter_scom_excl_match

接受兩個輸入模式。 當單一記錄符合模式 1 但不符合模式 2 時,將事件傳送至 Operations Manager。

  <filter tag>
      type filter_scom_excl_match
      regexp1 <key> <pattern1>
      regexp2 <key> <pattern2>
      event_id <event ID>
  </filter>

重複的相互關聯:filter_scom_repeated_cor

接受三個輸入:模式、時間間隔和多次出現。 找到第一個模式的相符項目時,計時器就會啟動。 如果模式在計時器結束之前符合指定的次數,就會傳送一個事件到 Operations Manager。

  <filter tag>
      type filter_scom_repeated_cor
      regexp <key> <pattern>
      event_id <event ID>
      time_interval <interval in seconds>
      num_occurences <number of occurrences>
  </filter>

相互關聯的比對:filter_scom_cor_match

接受三個輸入:兩個模式和一個時間間隔。 找到第一個模式的相符項目時,計時器就會啟動。 如果定時器結束前第二個模式的相符專案,就會將事件傳送至 Operations Manager。

  <filter tag>
      type filter_scom_cor_match
      regexp1 <key> <pattern1>
      regexp2 <key> <pattern2>
      event_id <event ID>
      time_interval <interval in seconds>
  </filter>

獨佔的相互關聯:filter_scom_excl_correlation

接受三個輸入:兩個模式和一個時間間隔。 找到第一個模式的相符項目時,計時器就會啟動。 如果定時器結束前第二個模式沒有相符專案,就會將事件傳送至 Operations Manager。

  <filter tag>
      type filter_scom_excl_correlation
      regexp1 <key> <pattern1>
      regexp2 <key> <pattern2>
      event_id <event ID>
      time_interval <interval in seconds>
  </filter>

Operations Manager 轉換器:filter_scom_converter

針對接收的所有記錄,將事件傳送至 Operations Manager。 傳送指定的事件識別碼和描述作為事件的一部分。

  <filter tag>
      type filter_scom_converter
      event_id <event ID>
      event_desc <event description>
  </filter>

將設定檔複製到代理程式

Fluentd 設定檔必須複製到您想要監視之所有 Linux 電腦上的 /etc/opt/microsoft/omsagent/scom/conf/omsagent.d。 您也必須在主要設定檔中新增 @include 指示詞,如上所述。

建立規則和監視器

Linux MP 不提供從 FluentD 收集事件的模組。 Linux MP 與 Linux 代理程式綁定。 它是 Linux 代理程式和閘道伺服器上的 Fluentd 模組,可提供增強記錄檔監視的功能。

您必須使用使用 Microsoft.Linux.OMED.EventDataSource 模組的自定義規則和監視器建立自己的管理元件,以從 Fluentd 收集事件。

下表列出 Microsoft.Linux.OMED.EventDataSource 的參數。

參數 類型 Description
ComputerName String 必要。 指定要讀取其事件的 Linux 電腦名稱。 儘管可將 ComputerName 參數指定為任何字串,但此參數最常使用 $Target 標記法傳遞到模組。 此模組會嘗試讀取由指定之 Linux 電腦產生的事件。
ManagedEntityId String 必要。 指定受監視實體之受管理的實體識別碼。 ManagedEntityId 參數最常使用 $Target\Id$ 傳遞到模組。
EventNumber 整數 選擇性。 表示要擷取之事件的事件編號。 如果省略此選項,模組會傳回針對該計算機和受控實體產生的所有事件。

設定概觀

記錄檔監視需要下列步驟。 下列各節提供詳細資訊:

  1. 匯入 最新的 System Center Operations Manager 2019 Linux 管理元件
  2. 在每部要監視的 Linux 電腦上,安裝最新版的 Linux 代理程式。
  3. 在每個要監視的 Linux 計算機上安裝最新的 OMSAgent
  4. 建立 Fluentd 設定檔來收集記錄。
  5. 將設定檔複製到 Linux 代理程式。
  6. 使用管理組件範例來建立規則和監視器,以便從記錄收集事件並建立警示。
  1. 匯入 最新的 System Center Operations Manager 2022 Linux 管理元件
  2. 在每部要監視的 Linux 電腦上,安裝最新版的 Linux 代理程式。
  3. 在每個要監視的 Linux 計算機上安裝最新的 OMSAgent
  4. 建立 Fluentd 設定檔來收集記錄。
  5. 將設定檔複製到 Linux 代理程式。
  6. 使用管理組件範例來建立規則和監視器,以便從記錄收集事件並建立警示。

安裝記錄監視管理元件

安裝 Microsoft.Linux.Log.Monitoring 管理元件以啟用 Linux 記錄檔監視。

注意

如果您已設定 OMS 代理程式,並嘗試從控制台卸載 UNIX 和 LINUX 代理程式,則不會從代理程式卸載 OMS 元件。

設定 Linux 記錄檔監視

若要設定 Linux 記錄檔監視,請執行下列步驟:

  1. 使用標準程式安裝管理元件,匯入 最新的 System Center Operations Manager 2019 Linux 管理元件

  2. 手動或在Linux伺服器上手動安裝新的Linux代理程式,或使用探索精靈 (/system-center/System Center Operations Manager/manage-deploy-crossplat-agent-console) 。

  3. 在您想要監視的每個 Linux 電腦上安裝最新的 OMSAgent。 使用下列命令:

    # Download latest OMS Agent from GitHub
    wget https://raw.githubusercontent.com/Microsoft/OMS-Agent-for-Linux/master/installer/scripts/onboard_agent.sh
    
    # Run onboarding script
    sh onboard_agent.sh
    

    在 Linux 代理程序上執行下列步驟:

  1. 使用標準程式來安裝管理元件,匯入 最新的 System Center Operations Manager 2022 Linux 管理元件

  2. 手動或在Linux伺服器上手動安裝新的Linux代理程式,或使用探索精靈 (/system-center/System Center Operations Manager/manage-deploy-crossplat-agent-console) 。

  3. 在您想要監視的每個 Linux 電腦上安裝最新的 OMSAgent。 使用下列命令:

    # Download latest OMS Agent from GitHub
    wget https://raw.githubusercontent.com/Microsoft/OMS-Agent-for-Linux/master/installer/scripts/onboard_agent.sh
    
    # Run onboarding script
    sh onboard_agent.sh
    

    在 Linux 代理程序上執行下列步驟:

  1. 使用下列命令在下列路徑中建立資料夾:

    # Create omsagent.d folder
    mkdir -p /etc/opt/microsoft/omsagent/scom/conf/omsagent.d
    
    # Create certs folder
    mkdir /etc/opt/microsoft/omsagent/scom/certs
    
    # Create log folder
    mkdir -p /var/opt/microsoft/omsagent/scom/log
    
    # Create run folder
    mkdir /var/opt/microsoft/omsagent/scom/run
    
    # Create state folder
    mkdir /var/opt/microsoft/omsagent/scom/state
    
    # Create tmp folder
    mkdir /var/opt/microsoft/omsagent/scom/tmp
    
    # Create fluent-logging folder (used for log file position file, this location is flexible)
    mkdir -p /home/omsagent/fluent-logging
    
  2. 將這些每個資料夾的擁有權設定為 omsagent:omiusers

    # Change owner of System Center Operations Manager folder
    chown omsagent:omiusers /etc/opt/microsoft/omsagent/scom
    
    # Change owner of log folder
    chown omsagent:omiusers /var/opt/microsoft/omsagent/scom/log
    
    # Change owner of run folder
    chown omsagent:omiusers /var/opt/microsoft/omsagent/scom/run
    
    # Change owner of state folder
    chown omsagent:omiusers /var/opt/microsoft/omsagent/scom/state
    
    # Change owner of tmp folder
    chown omsagent:omiusers /var/opt/microsoft/omsagent/scom/tmp
    
    # Change owner of fluent-logging folder (used for log file position file, this location is flexible)
    chown omsagent:omiusers /home/omsagent/fluent-logging
    

    記錄檔監視的螢幕快照。

  3. 建立 omsagent 和 omsconfig 檔案:

    # Create omsadmin.conf file
    touch /etc/opt/microsoft/omsagent/scom/conf/omsadmin.conf
    
    # Create omsagent.conf file
    touch /etc/opt/microsoft/omsagent/scom/conf/omsagent.conf
    
  4. 將這些每個檔案的擁有權設定為 omsagent:omiusers

    # Change owner of omsadmin.conf file
    chown omsagent:omiusers /etc/opt/microsoft/omsagent/scom/conf/omsadmin.conf
    
    # Change owner of omsagent.conf file
    chown omsagent:omiusers /etc/opt/microsoft/omsagent/scom/conf/omsagent.conf
    
  5. 編輯檔案 /etc/opt/microsoft/omsagent/scom/conf/omsadmin.conf,並在變更反白顯示的信息之後新增下列資訊。

    WORKSPACE_ID=scom
    System Center Operations Manager_ENDPOINT=https://<mark>\<MSFQDN\></mark>:8886
    MONITORING_ID={274F8D7B-DBCA-8FC3-1451-8DCD55092156}
    
  6. 重新啟動 OMSAgent:

    /opt/microsoft/omsagent/bin/service_control restart
    
  7. 確認 omsagent 記錄檔中的狀態:

    tail -100 /var/opt/microsoft/omsagent/scom/log/omsagent.log
    

啟用 OMED 服務

在資源集區中的每個管理伺服器上啟用 OMED 服務,並管理 Linux 代理程式。

OMED 服務會從 Fluentd 收集事件,並將它們轉換成 Operations Manager 事件。 您匯入自定義管理元件,可根據從Linux伺服器收到的事件產生警示。

您可以從 Operations 控制台或在管理伺服器或閘道伺服器上手動啟用 OMED 服務。

  1. 從 Operations 控制台,移至 [監視>Operations Manager>管理伺服器管理伺服器>狀態]。
  2. 選取 [ 管理伺服器] 狀態中的管理伺服器。
  3. 從 [ 工作] 中,選取 [ 健全狀況服務工作>啟用 System Center OMED 伺服器]。

新增 OMED 防火牆規則

若要啟用 OMED 防火牆規則,您有兩個選項,請透過 PowerShell 自動新增埠 (TCP/8886) 。

請遵循下列步驟,使用 PowerShell 自動新增規則:

下列命令可讓您自動新增防火牆規則:

Set-NetFirewallRule -DisplayName "System Center Operations Manager External DataSource Service" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8886

指派 OMSAgent 的客戶端憑證

指派 OMSAgent 的用戶端憑證時,您有兩個選項。

  1. 從 OMI 代理程式連結至已簽署的憑證。
  2. 手動產生 OMS 代理程式的客戶端憑證。

選取必要索引標籤,以取得從 OMI 代理程式連結至已簽署憑證的步驟,或從 OMS 代理程式手動產生用戶端憑證:

  1. 將與 omikey.pem 檔案的omi.pem擁有權設定為 omsagent:omiusers

    # Change owner of System Center Operations Manager-cert.pem file
    chown omsagent:omiusers /etc/opt/microsoft/omsagent/scom/certs/scom-cert.pem
    
    # Change owner of System Center Operations Manager-key.pem file
    chown omsagent:omiusers /etc/opt/microsoft/omsagent/scom/certs/scom-key.pem
    
  2. 在 Linux 計算機上執行下列命令,將 OMS 代理程式用戶端憑證設定為 OMI 憑證, (Operations Manager Linux 代理程式憑證) :

    # Link file omi.pem to System Center Operations Manager-cert.pem
    ln -s /etc/opt/omi/ssl/omi.pem /etc/opt/microsoft/omsagent/scom/certs/scom-cert.pem
    
    # Link file omikey.pem to System Center Operations Manager-key.pem
    ln -s /etc/opt/omi/ssl/omikey.pem /etc/opt/microsoft/omsagent/scom/certs/scom-key.pem
    

建立 Fluentd 組態檔

您可以使用組態檔來設定 Fluentd 作業。 若要利用記錄監視,您必須建立組態檔。 組態檔包含來源記錄檔名稱、路徑和篩選等資訊,以定義要收集的數據。

主要 Fluentd 組態檔 omsagent.conf 位於 /etc/opt/microsoft/omsagent/scom/conf/。 您可以直接將記錄檔監視組態新增至此檔案,但應該建立個別的組態檔,以更妥善地管理不同的設定。 您接著要在主檔案中使用 @include 指示詞來包含自訂檔案。

例如,如果您在 中/etc/opt/microsoft/omsagent/scom/conf/omsagent.d建立 logmonitoring.conf,您會將下列其中一行新增至 omsagent.d 檔案:

# Include all configuration files
@include omsagent.d/*.conf

# Include single configuration file
@include omsagent.d/logmonitoring.conf

如需 Fluentd 組態檔的詳細資訊,請參閱 Fluentd 組態檔語法

下列各節描述組態檔監視唯一之組態檔不同指示詞中的設定。 每一個均包含您可以貼到設定檔並針對您的需求加以修改的範例設定。

完整的用於記錄檔監視的設定檔範例可供您在檢閱和評估之前自行建立。

Source

Source 指示詞會定義您要收集的數據來源,這是您定義記錄檔詳細數據的位置。 Fluentd 會挑選已寫入至來源的每筆記錄,並將其事件提交至 Fluentd 的路由引擎。 在此指示詞中指定標記。 標記是字串,用來做為 Fluentd 內部路由引擎的指示,使不同的指示詞相互關聯。

下列範例顯示由 Operations Manager 收集並標記要處理的 syslog 記錄。

<source>

    # Specifies input plugin. Tail is a fluentd input plugin - http://docs.fluentd.org/v0.12/articles/in\_tail
    type tail

    # Specify the log file path. Supports wild cards.
    path /var/log/syslog

    # Recommended so that Fluentd will record the position it last read into this file.
    pos_file /home/user1/fluent-test/demo_syslog.log.pos

    # Used to correlate the directives.
    tag System Center Operations Manager.log.syslog

    format /(?<message>.*)/

</source>

篩選

篩選指示詞的語法與 Match 相同,但允許更複雜的篩選要處理哪些數據。 收集的事件必須符合要新增至輸出之所有篩選條件的準則。

此處說明六個適用於記錄檔監視的篩選外掛程式。 使用這其中一或多個篩選,來定義您想要從記錄檔收集的事件。

  • 簡單比對:filter_System Center Operations Manager_simple_match
  • 獨佔比對:filter_System Center Operations Manager_excl_match
  • 重複相互關聯:filter_System Center Operations Manager_repeated_cor
  • 相互關聯的比對:filter_System Center Operations Manager_cor_match
  • 獨佔相互關聯:filter_System Center Operations Manager_excl_correlation
  • Operations Manager 轉換器:filter_System Center Operations Manager_converter

選取必要的索引標籤,以複製個別篩選外掛程式的程式代碼:

最多接受 20 個輸入模式。 每當有任何模式相符時,傳送一個事件到 Operations Manager。

<filter tag>

    type filter_System Center Operations Manager_simple_match
    regexp1 <key> <pattern>
    event_id1 <event ID>
    regexp2 <key> <pattern>
    event_id2 <event ID>
    .
    .
    .
    regexp20 <key> <pattern>
    event_id20 <event ID>
</filter>

相符項目

match 指示詞定義如何使用相符的標記,來處理收集自來源的事件。 只有符合模式標記的事件才會傳送至輸出目的地。 當一個 match 標記內列出多個模式時,事件就可以比對任何列出的模式。 type 參數會指定要用於這些事件的外掛程式類型。

此範例會處理具有符合 System Center Operations Manager.log 標記的事件。** 和 System Center Operations Manager.alert (** 符合零或多個標籤) 。 它會指定 out_System Center Operations Manager 外掛程式,讓 Operations Manager 管理元件能夠收集事件。

<match System Center Operations Manager.log.** System Center Operations Manager.event>

    # Output plugin to use
     type out_System Center Operations Manager

    log_level trace
    num_threads 5

    # Size of the buffer chunk. If the top chunk exceeds this limit or the time limit flush_interval, a new empty chunk is pushed to the top of the
    queue and bottom chunk is written out.
    buffer_chunk_limit 5m
    flush_interval 15s

    # Specifies the buffer plugin to use.
    buffer_type file

    # Specifies the file path for buffer. Fluentd must have write access to this directory.
    buffer_path /var/opt/microsoft/omsagent/scom/state/out_System Center Operations Manager_common*.buffer

    # If queue length exceeds the specified limit, events are rejected.
    buffer_queue_limit 10

    # Control the buffer behavior when the queue becomes full: exception, block, drop_oldest_chunk
    buffer_queue_full_action drop_oldest_chunk

    # Number of times Fluentd will attempt to write the chunk if it fails.
    retry_limit 10

    # If the bottom chunk fails to be written out, it will remain in the queue and Fluentd will retry after waiting retry_wait seconds
    retry_wait 30s

    # The retry wait time doubles each time until max_retry_wait.
    max_retry_wait 9m

</match>

注意

若要停用使用 Fluentd 通訊之 Linux 電腦上的伺服器驗證,請將參數 enable_server_auth false 新增至 Fluentd 的 Operations Manager 外掛程式,如下所示:

<match System Center Operations Manager.log.** System Center Operations Manager.event>
type out_System Center Operations Manager

max_retry_wait 9m
enable_server_auth false

</match>

將設定檔複製到代理程式

Fluentd 組態檔必須複製到您想要監視之所有 Linux 計算機上的 /etc/opt/microsoft/omsagent/scom/conf/omsagent.d 。 您也必須在主要設定檔中新增 @include 指示詞,如上所述。

重新啟動 omsagent

您可以執行下列命令來重新啟動 omsagent:

/opt/microsoft/omsagent/bin/service_control restart

檢查 System Center Operations Manager 工作區的狀態

執行下列命令,以檢查 OMSAgent 上的 System Center Operations Manager 工作區:

sh /opt/microsoft/omsagent/bin/omsadmin.sh -l

注意

在執行 OMED 服務的 Management Server 上,確定埠 8886 上的防火牆已開啟,且中繼證書頒發機構單位憑證存放區只包含中繼證書頒發機構單位。

System Center Operations Manager 外部 DataSource Service 的事件記錄檔

只有在成功將事件傳送至 System Center Operations Manager 外部 DataSource Service (OMED) Service 時,才會建立 System Center OMED Service 事件記錄檔。

建立規則和監視器

Linux 管理元件不提供從 FluentD 收集事件的模組,Linux 管理元件會與 Linux 代理程式配套。 它是 Linux 代理程式和閘道伺服器上的 Fluentd 模組,可提供增強記錄檔監視的功能。

您必須使用使用 Microsoft.Linux.OMED.EventDataSource 模組從 Fluentd 收集事件的自定義規則和監視器來建立自己的管理元件。 請注意,透過 System Center OMED 服務 事件記錄檔傳送之事件中的電腦名稱必須符合 UNIX/Linux 電腦檢視中的電腦名稱。 如果計算機名稱不符合,您就不會收到任何警示。

下表列出 Microsoft.Linux.OMED.EventDataSource 的參數。

參數 類型 Description
ComputerName String 必要。 指定要讀取事件的 Linux 計算機名稱。 儘管可將 ComputerName 參數指定為任何字串,但此參數最常使用 $Target 標記法傳遞到模組。 此模組會嘗試讀取由指定之 Linux 電腦產生的事件。
ManagedEntityId String 必要。 指定受監視實體之受管理的實體識別碼。 ManagedEntityId 參數最常使用 $Target\Id$ 傳遞到模組。
EventNumber 整數 選擇性。 表示要擷取之事件的事件編號。 如果省略此選項,模組會傳回針對該計算機和受控實體產生的所有事件

下一步