與 Apigee-monit 一起自我修復

Apigee Edge 私有雲包含 apigee-monit,這是以開放原始碼 monit 公用程式為基礎的工具。apigee-monit 會定期輪詢 Edge 服務。如果服務無法使用,則 apigee-monit 會嘗試重新啟動。

如要使用「apigee-monit」,您必須手動安裝。這不是標準安裝的一部分。

根據預設,apigee-monit 會每 60 秒檢查 Edge 服務的狀態。

快速入門

本節說明如何快速開始使用 apigee-monit

如果使用 Amazon Linux,請先安裝 Fedora。否則請略過這個步驟。

sudo yum install -y https://kojipkgs.fedoraproject.org/packages/monit/5.25.1/1.el6/x86_64/monit-5.25.1-1.el6.x86_64.rpm

如要安裝 apigee-monit,請按照下列步驟操作:

  安裝 apigee-monit
/opt/apigee/apigee-service/bin/apigee-service apigee-monit install
/opt/apigee/apigee-service/bin/apigee-service apigee-monit configure
/opt/apigee/apigee-service/bin/apigee-service apigee-monit start

根據預設,系統會安裝 apigee-monit 並開始監控節點中的所有元件。

  停止監控元件
/opt/apigee/apigee-service/bin/apigee-service apigee-monit unmonitor -c component_name
/opt/apigee/apigee-service/bin/apigee-service apigee-monit unmonitor -c all
  開始監控元件
/opt/apigee/apigee-service/bin/apigee-service apigee-monit monitor -c component_name
/opt/apigee/apigee-service/bin/apigee-service apigee-monit monitor -c all
  取得摘要狀態資訊
/opt/apigee/apigee-service/bin/apigee-service apigee-monit report
/opt/apigee/apigee-service/bin/apigee-service apigee-monit summary
  查看 apigee-monit 記錄檔
cat /opt/apigee/var/log/apigee-monit/apigee-monit.log

以下各節將詳細說明這些主題和其他主題。

apigee-monit 簡介

apigee-monit 有助於確保節點上的所有元件都能持續運作。方法是提供多項服務,包括:

  • 重新啟動失敗的服務
  • 顯示摘要資訊
  • Logging 監控狀態
  • 傳送通知
  • 監控非邊緣服務

Apigee 建議您監控 apigee-monit,確保一切運作正常。詳情請參閱監控 apigee-monit

apigee-monit 架構

在 Apigee Edge 安裝及設定期間,您可以選擇在叢集的每個節點上安裝 apigee-monit 的單獨執行個體。這些獨立的 apigee-monit 執行個體彼此獨立運作:這些執行個體不會將其元件的狀態與其他節點通訊,也不會將監控公用程式本身故障傳送至任何中央服務。

下圖顯示 5 節點叢集中的 apigee-monit 架構:

5 個節點叢集中 Apigee {0}monit 的架構
圖 1:在叢集中的每個節點上,獨立執行 apigee-monit 的個別執行個體

支援的平台

apigee-monit 支援下列私有 Cloud 叢集的平台。apigee-monit 支援的 OS 取決於 Private Cloud 版本。

作業系統 私有雲版本
v4.50.00 v4.51.00 v4.52.00
CentOS 7.5、7.6、7.7、7.8 7.5、7.6、7.7、7.8 7.5、7.6、7.7、7.8
RedHat Enterprise Linux (RHEL) 7.5、7.6、7.7、7.8 7.5、7.6、7.7、7.8、7.9、8.0 7.5、7.6、7.7、7.8、7.9、8.0
Oracle Linux 7.5、7.6、7.7、7.8 7.5、7.6、7.7、7.8 7.5、7.6、7.7、7.8
* 雖然技術不支援,但您可以在 CentOS/RHEL/Oracle 6.9 版中,為 Apigee Edge for Private Cloud 4.19.01 版安裝並使用 apigee-monit

元件設定

apigee-monit 會使用元件設定決定要監控的元件、要檢查的元件面向,以及失敗事件時要採取的動作。

根據預設,apigee-monit 會使用預先定義的元件設定監控節點上的所有 Edge 元件。如要查看預設設定,您可以查看 apigee-monit 元件設定檔。您無法變更預設元件設定。

apigee-monit 會根據所檢查的元件,檢查元件的不同層面。下表列出 apigee-monit 針對各元件檢查的內容,並顯示各元件設定的位置。請注意,部分元件會在單一設定檔中定義,其他元件有各自的設定。

元件 設定位置 監控的內容
管理伺服器 /opt/apigee/edge-management-server/monit/default.conf apigee-monit 會檢查:
  • 指定的通訊埠為開放且接受要求
  • 系統支援指定的通訊協定
  • 回應狀態

此外,針對這些元件 apigee-monit

  • 必須在指定的週期數內多次失敗後才能採取行動
  • 設定自訂要求路徑
訊息處理器 /opt/apigee/edge-message-processor/monit/default.conf
Postgres 伺服器 /opt/apigee/edge-postgres-server/monit/default.conf
Qpid 伺服器 /opt/apigee/edge-qpid-server/monit/default.conf
路由器 /opt/apigee/edge-router/monit/default.conf
Cassandra
Edge UI
OpenLDAP
Postgres
Qpid
Zookeeper
/opt/apigee/data/apigee-monit/monit.conf apigee-monit 會檢查:
  • 服務執行中

以下範例顯示 edge-router 元件的預設元件設定:

check host edge-router with address localhost
  restart program = "/opt/apigee/apigee-service/bin/apigee-service edge-router monitrestart"
  if failed host 10.1.1.0 port 8081 and protocol http
    and request "/v1/servers/self/uuid"
    with timeout 15 seconds
    for 2 times within 3 cycles
  then restart

  if failed port 15999 and protocol http
    and request "/v1/servers/self"
    and status < 600
    with timeout 15 seconds
    for 2 times within 3 cycles
  then restart

以下範例顯示傳統版 UI (edge-ui) 元件的預設設定:

check process edge-ui
 with pidfile /opt/apigee/var/run/edge-ui/edge-ui.pid
 start program = "/opt/apigee/apigee-service/bin/apigee-service edge-ui start" with timeout 55 seconds
 stop program = "/opt/apigee/apigee-service/bin/apigee-service edge-ui stop"

這適用於傳統版 UI,而非元件名稱為 edge-management-ui 的新 Edge UI。

您無法變更任何 Apigee Edge 私有雲元件的預設元件設定。但是,您可以為外部服務新增自己的元件設定,例如目標端點或 httpd 服務。詳情請參閱非 Apigee 元件設定

根據預設,apigee-monit 會監控執行節點時節點上的所有元件。您可以為所有元件或個別元件啟用或停用這項設定。詳情請參閱:

安裝 apigee-monit

根據預設,apigee-monit 不會安裝。升級或安裝 4.19.01 以上版本的 Apigee Edge for Private Cloud 之後,您可以手動安裝。

本節說明如何在支援的平台上安裝 apigee-monit

如要進一步瞭解如何uninstalling apigee-monit,請參閱解除安裝 apigee-monit

在支援的平台安裝 apigee-monit

本節說明如何在支援的平台上安裝 apigee-monit

如何在支援的平台上安裝 apigee-monit

  1. 透過下列指令安裝 apigee-monit
    /opt/apigee/apigee-service/bin/apigee-service apigee-monit install
  2. 透過下列指令設定 apigee-monit
    /opt/apigee/apigee-service/bin/apigee-service apigee-monit configure
  3. 透過下列指令啟動 apigee-monit
    /opt/apigee/apigee-service/bin/apigee-service apigee-monit start
  4. 對叢集中的每個節點重複執行這項程序。

停止及啟動監控元件

當服務因任何原因停止時,apigee-monit 會嘗試重新啟動服務。

如果您想「刻意」停止某個元件,這可能會造成問題。例如,您可能需要在需要備份或升級元件時停止元件。如果 apigee-monit 在備份或升級期間重新啟動服務,您的維護程序可能會中斷,也可能導致服務失敗。

以下各節說明停止監控元件的選項。

停止元件並解除監控

如要停止元件並解除監控,請執行下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit stop-component -c component_name
component_name 可以是下列任一值:
  • apigee-cassandra (Cassandra)
  • apigee-openldap (OpenLDAP)
  • apigee-postgresql (PostgreSQL 資料庫)
  • apigee-qpidd (魁北克)
  • apigee-sso (邊緣單一登入)
  • apigee-zookeeper (ZooKeeper)
  • edge-management-server (管理伺服器)
  • edge-management-ui (新版 Edge UI)
  • edge-message-processor (訊息處理器)
  • edge-postgres-server (Postgres 伺服器)
  • edge-qpid-server (快速伺服器)
  • edge-router (邊緣路由器)
  • edge-ui (傳統版 UI)

請注意,「all」不是 stop-component 的有效選項。使用 stop-component 時,您一次只能停止及解除監控一個元件。

如要重新啟動元件並繼續監控,請執行下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit start-component -c component_name

請注意,「all」不是 start-component 的有效選項。

如需停止及取消監控所有元件的操作說明,請參閱「停止所有元件並取消監控」。

取消監控元件 (但請勿停止)

如要解除監控元件 (但不停止),請執行下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit unmonitor -c component_name
component_name 可以是下列任一值:
  • apigee-cassandra (Cassandra)
  • apigee-openldap (OpenLDAP)
  • apigee-postgresql (PostgreSQL 資料庫)
  • apigee-qpidd (魁北克)
  • apigee-sso (邊緣單一登入)
  • apigee-zookeeper (ZooKeeper)
  • edge-management-server (管理伺服器)
  • edge-management-ui (新版 Edge UI)
  • edge-message-processor (訊息處理器)
  • edge-postgres-server (Postgres 伺服器)
  • edge-qpid-server (快速伺服器)
  • edge-router (邊緣路由器)
  • edge-ui (傳統版 UI)

如要繼續監控元件,請執行下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit monitor -c component_name

取消監控所有元件 (但不要停止這些元件)

如要解除監控所有元件 (但不停止元件),請執行下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit unmonitor -c all

如要繼續監控所有元件,請執行下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit monitor -c all

停止所有元件並解除監控

如要停止所有元件並解除監控,請執行下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit unmonitor -c all
/opt/apigee/apigee-service/bin/apigee-all stop

如要重新啟動所有元件並繼續監控,請執行下列指令:

/opt/apigee/apigee-service/bin/apigee-all start
/opt/apigee/apigee-service/bin/apigee-service apigee-monit monitor -c all

如要停止監控所有元件,您也可以停用 apigee-monit,詳情請參閱停止、開始及停用 apigee-monit

停止、啟動及停用 apigee-monit

就像任何服務一樣,您可以使用 apigee-service 指令停止及啟動 apigee-monit。此外,apigee-monit 支援 unmonitor 指令,可讓您暫時停止監控元件。

停止 apigee-monit

如要停止 apigee-monit,請使用下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit stop

啟動 apigee-monit

如要啟動 apigee-monit,請使用下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit start

停用 apigee-monit

您可以使用下列指令,暫停監控節點上的所有元件:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit unmonitor -c all

或者,您也可以按照解除安裝 apigee-monit 的說明,從節點解除安裝 apigee-monit,藉此永久停用。

解除安裝 apigee-monit

如何解除安裝 apigee-monit

  1. 如果您設定了 cron 工作來監控 apigee-monit,請先移除 cron 工作,再解除安裝 apigee-monit
    sudo rm /etc/cron.d/apigee-monit.cron
  2. 使用下列指令停止 apigee-monit
    /opt/apigee/apigee-service/bin/apigee-service apigee-monit stop
  3. 使用下列指令解除安裝 apigee-monit
    /opt/apigee/apigee-service/bin/apigee-service apigee-monit uninstall
  4. 對叢集中的每個節點重複執行這項程序。

監控新安裝的元件

如果您在執行 apigee-monit 的節點上安裝新元件,可以執行 apigee-monitrestart 指令開始監控該元件。這項操作會產生新的 monit.conf 檔案,並在其元件設定中納入新元件。

下列範例會重新啟動 apigee-monit

/opt/apigee/apigee-service/bin/apigee-service apigee-monit restart

自訂 apigee-monit

你可以自訂各種 apigee-monit 設定,包括:

  1. 預設的apigee-monit控制設定
  2. 通用配置設定
  3. 非 Apigee 元件設定

預設的 apigee-monit 控制設定

您可以自訂預設的 apigee-monit 控制項設定,例如狀態檢查頻率和 apigee-monit 檔案的位置。方法是使用含有 config 的程式碼技術來編輯屬性檔案。升級私有雲的 Apigee Edge 之後,屬性檔案仍會保留。

下表說明可自訂的預設 apigee-monit 控制項設定:

屬性 說明
conf_monit_httpd_port httpd Daemon 的通訊埠。apigee-monit 會將 httpd 用於資訊主頁應用程式,並啟用報表/匯總功能。預設值為 2812。
conf_monit_httpd_allow 對傳送至 httpd Daemon 的要求設下限制。apigee-monit 會使用 httpd 執行其資訊主頁應用程式,並啟用報表/摘要。這個值必須指向 localhost (執行 httpd 的主機)。

如要要求包含使用者名稱和密碼的要求,請使用以下語法:

conf_monit_httpd_allow=allow username:"password"\nallow 127.0.0.1

新增使用者名稱和密碼時,請在每項限制之間插入「\n」。請勿在值中插入實際換行符號或回車字元。

conf_monit_monit_datadir 儲存事件詳細資料的目錄。
conf_monit_monit_delay_time apigee-monit 在首次載入記憶體後等待的時間長度,再執行該記憶體。這只會影響 apigee-monit 的第一個程序檢查。
conf_monit_monit_logdir apigee-monit 記錄檔的位置。
conf_monit_monit_retry_time apigee-monit 嘗試檢查各項程序的頻率,預設值為 60 秒。
conf_monit_monit_rundir PID 和狀態檔案的位置,apigee-monit 會使用該檔案檢查程序。

如何自訂預設的 apigee-monit 控制項設定:

  1. 編輯下列檔案:
    /opt/apigee/customer/application/monit.properties

    如果檔案不存在,請建立檔案並將擁有者設為「apigee」使用者:

    chown apigee:apigee /opt/apigee/customer/application/monit.properties

    請注意,如果檔案已存在,則除了上表中所列的其他設定屬性,可能還有其他設定屬性。請勿修改上述屬性以外的屬性。

  2. 設定或替換屬性值。

    舉例來說,如要將記錄檔位置變更為 /tmp,請新增或編輯下列屬性:

    conf_monit_monit_logdir=/tmp/apigee-monit.log

  3. 將變更儲存至 monit.properties 檔案。
  4. 使用下列指令重新設定 apigee-monit
    /opt/apigee/apigee-service/bin/apigee-service apigee-monit configure
  5. 使用下列指令重新載入 apigee-monit
    /opt/apigee/apigee-service/bin/apigee-service apigee-monit reload

    如果您無法重新啟動 apigee-monit,請檢查記錄檔中是否有錯誤,如「存取 apigee-monit 記錄檔」所述。

  6. 對叢集中的每個節點重複執行這項程序。

通用配置設定

您可以為 apigee-monit 定義全域設定;例如,您可以新增快訊的電子郵件通知。方法是在 /opt/apigee/data/apigee-monit 目錄中建立設定檔,然後重新啟動 apigee-monit

如何定義 apigee-monit 的全域配置設定:

  1. 請在下列位置建立新的元件設定檔:
    /opt/apigee/data/apigee-monit/filename.conf

    其中 filename 可以是任何有效的檔案名稱,「monit」除外。

  2. 將新設定檔的擁有者變更為「apigee」使用者,如以下範例所示:
    chown apigee:apigee /opt/apigee/data/apigee-monit/my-mail-config.conf
  3. 將全域組態設定新增至新檔案。以下範例會設定郵件伺服器,並設定快訊收件者:
    SET MAILSERVER smtp.gmail.com PORT 465
      USERNAME "example-admin@gmail.com" PASSWORD "PASSWORD"
      USING SSL, WITH TIMEOUT 15 SECONDS
    
    SET MAIL-FORMAT {
      from: edge-alerts@example.com
      subject: Monit Alert -- Service: $SERVICE $EVENT on $HOST
    }
    SET ALERT fred@example.com
    SET ALERT nancy@example.com

    如需完整的全域設定選項清單,請參閱 Monit 說明文件

  4. 將變更儲存至元件設定檔。
  5. 使用下列指令重新載入 apigee-monit
    /opt/apigee/apigee-service/bin/apigee-service apigee-monit reload

    如果 apigee-monit 未重新啟動,請檢查記錄檔中是否有錯誤,如「存取 apigee-monit 記錄檔」所述。

  6. 對叢集中的每個節點重複執行這項程序。

非 Apigee 元件設定

您可以為 apigee-monit 新增自己的設定,以便檢查不屬於 Apigee Edge for Private Cloud 的服務。舉例來說,您可以使用 apigee-monit 傳送要求至目標端點,藉此檢查 API 是否正在運作。

如何新增非 Apigee 元件設定:

  1. 請在下列位置建立新的元件設定檔:
    /opt/apigee/data/apigee-monit/filename.conf

    其中 filename 可以是任何有效的檔案名稱,「monit」除外。

    您可以視需要建立多個元件設定檔,數量不限。舉例來說,您可以為要在節點上監控的每個非 Apigee 元件,建立個別的設定檔。

  2. 將新設定檔的擁有者變更為「apigee」使用者,如以下範例所示:
    chown apigee:apigee /opt/apigee/data/apigee-monit/my-config.conf
  3. 將自訂設定新增至新檔案。以下範例會檢查本機伺服器上的目標端點:
    CHECK HOST localhost_validate_test WITH ADDRESS localhost
      IF FAILED
        PORT 15999
        PROTOCOL http
        REQUEST "/validate__test"
        CONTENT = "Server Ready"
        FOR 2 times WITHIN 3 cycles
      THEN alert

    如需可能配置設定的完整清單,請參閱 Monit 說明文件

  4. 儲存對設定檔所做的變更。
  5. 使用下列指令重新載入 apigee-monit
    /opt/apigee/apigee-service/bin/apigee-service apigee-monit reload

    如果 apigee-monit 未重新啟動,請檢查記錄檔中是否有錯誤,如「存取 apigee-monit 記錄檔」所述。

  6. 對叢集中的每個節點重複執行這項程序。

請注意,這僅適用於非 Edge 元件。無法自訂 Edge 元件的元件設定。

存取 apigee-monit 記錄檔

apigee-monit 會將所有活動記錄在記錄檔中,包括事件、重新啟動、設定變更和快訊。

記錄檔的預設位置如下:

/opt/apigee/var/log/apigee-monit/apigee-monit.log

您可以自訂 apigee-monit 控制項設定來變更預設位置。

記錄檔項目的格式如下:

'edge-message-processor' trying to restart
[UTC Dec 14 16:20:42] info     : 'edge-message-processor' trying to restart
'edge-message-processor' restart: '/opt/apigee/apigee-service/bin/apigee-service edge-message-processor monitrestart'

您無法自訂 apigee-monit 記錄檔項目的格式。

使用 apigee-monit 查看匯總狀態

apigee-monit 包含下列指令,可提供節點上元件的匯總狀態資訊:

指令 使用方法
report
/opt/apigee/apigee-service/bin/apigee-service apigee-monit report
summary
/opt/apigee/apigee-service/bin/apigee-service apigee-monit summary

我們會在後續章節中詳細說明這些指令。

報表

report 指令會顯示匯總摘要,說明節點上向上、向下、正在初始化或目前「未受監控」的元件數量。下列範例叫用 report 指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit report

以下範例顯示 AIO (全方位) 設定上的 report 輸出內容:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit report
up:            11 (100.0%)
down:           0 (0.0%)
initialising:   0 (0.0%)
unmonitored:    1 (8.3%)
total:         12 services

在此範例中,apigee-monit 回報了 12 項服務中的 11 項服務。一項服務目前並未受到監控。

首次執行 report 指令時,可能會收到 Connection refused 錯誤。在這種情況下,請等待 conf_monit_monit_delay_time 屬性的持續時間,然後再試一次。

摘要

summary 指令會列出每個元件並提供其狀態。下列範例會叫用 summary 指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit summary

以下範例顯示 AIO (全方位) 設定上的 summary 輸出內容:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit summary
Monit 5.25.1 uptime: 4h 20m
 Service Name                     Status                      Type
 host_name                        OK                          System
 apigee-zookeeper                 OK                          Process
 apigee-cassandra                 OK                          Process
 apigee-openldap                  OK                          Process
 apigee-qpidd                     OK                          Process
 apigee-postgresql                OK                          Process
 edge-ui                          OK                          Process
 edge-qpid-server                 OK                          Remote Host
 edge-postgres-server             OK                          Remote Host
 edge-management-server           OK                          Remote Host
 edge-router                      OK                          Remote Host
 edge-message-processor           OK                          Remote Host

如果您在首次執行 summary 指令時收到 Connection refused 錯誤,請嘗試等待 conf_monit_monit_delay_time 屬性的時間,然後再試一次。

監控 apigee-monit

最佳做法是定期檢查 apigee-monit 是否在每個節點上執行。

如要檢查 apigee-monit 是否正在執行,請使用下列指令:

/opt/apigee/apigee-service/bin/apigee-service apigee-monit monitor_monit

Apigee 建議您在每個執行 apigee-monit 的節點上定期發出這個指令。其中一個做法是使用 cron 等公用程式,按預先定義的間隔執行排程工作。

如何使用cron監控 apigee-monit

  1. apigee-monit.cron 目錄複製到 /etc/cron.d 目錄,藉此新增 cron 支援,如以下範例所示:
    cp /opt/apigee/apigee-monit/cron/apigee-monit.cron /etc/cron.d/
  2. 開啟 apigee-monit.cron 檔案進行編輯。

    apigee-monit.cron 檔案會定義要執行的 cron 工作,以及執行工作的頻率。以下範例顯示預設值:

    # Cron entry to check if monit process is running. If not start it
    */2 * * * * root /opt/apigee/apigee-service/bin/apigee-service apigee-monit monitor_monit

    這個檔案使用下列語法,其中前五個欄位定義了 apigee-monit 執行動作的時間:

    min hour day_of_month month day_of_week task_to_execute

    舉例來說,預設的執行時間為 */2 * * * *,指示 cron 每 2 分鐘檢查 apigee-monit 程序一次。

    每分鐘執行「cron」工作的頻率不可以超過一次。

    如要進一步瞭解如何使用 cron,請參閱伺服器 OS 說明文件或手冊頁面。

  3. 請配合貴機構的政策變更「cron」設定。舉例來說,如要將執行頻率變更為每 5 分鐘一次,請將工作定義設為以下內容:
    */5 * * * * root /opt/apigee/apigee-service/bin/apigee-service apigee-monit monitor_monit
  4. 儲存 apigee-monit.cron 檔案。
  5. 對叢集中的每個節點重複執行這項程序。

如果 cron 尚未開始觀看 apigee-monit,請檢查:

  • cron 工作定義後方有空白行。
  • 檔案中只定義了一項 cron 工作。(加註行不含註解)。

如果您要停止或暫時停用 apigee-monit,則必須停用這項 cron 工作,否則 cron 會重新啟動 apigee-monit

如要停用 cron,請執行下列其中一項操作:

  • 刪除 /etc/cron.d/apigee-monit.cron 檔案:
    sudo rm /etc/cron.d/apigee-monit.cron

    如果之後想重新啟用 cron 觀看 apigee-monit,必須重新複製這個檔案。

  • 編輯 /etc/cron.d/apigee-monit.cron 檔案並在該行開頭加上「#」,即可註解排除工作定義,例如:
    # 10 * * * * root /opt/apigee/apigee-service/bin/apigee-service apigee-monit monitor_monit