如何監控

本文說明 Apigee Edge 的內部部署部署所支援的元件監控技術。

總覽

Edge 支援多種取得服務詳細資料及檢查狀態的方式。下表列出您可以對各項符合資格的服務執行的檢查類型:

管理 API
服務 記憶體用量 [JMX*] 服務檢查 使用者/機構/ 部署作業狀態 axstatus 資料庫檢查 apigee-service 狀態 apigee-monit**
管理伺服器
訊息處理器
Postgres
Qpid
路由器
更多資訊 更多資訊 更多資訊 更多資訊 更多資訊 更多資訊 更多資訊

* 您必須先按照「啟用 JMX」的說明啟用 JMX,才能使用 JMX。

** apigee-monit 服務會檢查元件是否已啟用,如果不存在,並嘗試重新啟動。詳情請參閱使用 apigee-monit 進行自我修復

JMX and Management API 監控通訊埠

每個元件都支援不同通訊埠的 JMX 和 Management API 監控呼叫。下表列出各個伺服器類型的 JMX 和 Management API 通訊埠:

元件 JMX 通訊埠 Management API 通訊埠
管理伺服器 1099 8080
路由器 1100 8081
訊息處理器 1101 8082
Qpid 1102 8083
Postgres 1103 8084

使用 JMX 進行監控

管理伺服器、訊息處理器、Qpid 和 Postgres 的監控程序全都使用 JMX。不過,只有 Cassandra 預設會啟用 JMX,所有其他 Edge 元件則預設為停用。因此,您必須先為每個元件個別啟用 JMX,才能監控這些元件。

根據預設,系統不會啟用 JMX 驗證。您可以為所有元件啟用 JMX 驗證。若為 Cassandra,請使用為 Cassandra 啟用 JMX 驗證一文中的說明。

啟用 JMX

根據預設,只有 Cassandra 會啟用 JMX,所有其他 Edge 元件則預設為停用。本節說明如何為其他 Edge 元件啟用 JMX。

如何啟用 JMX:

  1. 編輯元件的設定檔。這個檔案位於 opt/apigee/edge-component_name/bin/start。在實際工作環境中,這些設定檔位於不同的機器上。

    請針對每部伺服器選擇下列檔案位置:

    • 管理伺服器:/opt/apigee/edge-management-server/bin/start
    • 訊息處理器:/opt/apigee/edge-message-processor/bin/start
    • Postgres:/opt/apigee/edge-postgres-server/bin/start
    • Qpid:/opt/apigee/edge-qpid-server/bin/start
    • 路由器:/opt/apigee/edge-router/bin/start

    舉例來說,管理伺服器在伺服器上的設定檔位於 /opt/apigee/edge-management-server/bin/start

  2. 將下列 com.sun.management.jmxremote 選項新增至啟動元件的 exec 行:
    -Dcom.sun.management.jmxremote \
      -Dcom.sun.management.jmxremote.port=port_number \
      -Dcom.sun.management.jmxremote.local.only=false \
      -Dcom.sun.management.jmxremote.authenticate=false \
      -Dcom.sun.management.jmxremote.ssl=false

    其中 port_number 是服務的 JMX 通訊埠。如要取得服務的 JMX 通訊埠號碼,請參閱 JMX and Management API 監控通訊埠

    舉例來說,如要啟用管理伺服器的 JMX,請將以下內容新增至管理伺服器的設定檔:

    exec $JAVA -classpath "$classpath" -Xms$min_mem -Xmx$max_mem $xx_opts \
      -Djava.security.auth.login.config=$conf_path/jaas.config \
      -Dinstallation.dir=$install_dir $sys_props -Dconf.dir=$conf_path \
      -Ddata.dir=$data_dir \
      -Dcom.sun.management.jmxremote \
      -Dcom.sun.management.jmxremote.port=1099 \
      -Dcom.sun.management.jmxremote.local.only=false \
      -Dcom.sun.management.jmxremote.authenticate=false \
      -Dcom.sun.management.jmxremote.ssl=false \
       $* $debug_options com.apigee.kernel.MicroKernel

    這個範例說明如何指定管理伺服器的通訊埠 1099。如前所述,每項服務都有專屬的通訊埠編號。

    設定檔中編輯完成的行內容如下所示:

    exec $JAVA -classpath "$classpath" -Xms$min_mem -Xmx$max_mem $xx_opts -Djava.security.auth.login.config=$conf_path/jaas.config -Dinstallation.dir=$install_dir $sys_props -Dconf.dir=$conf_path -Ddata.dir=$data_dir -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false $* $debug_options com.apigee.kernel.MicroKernel
  3. 儲存設定檔。
  4. 請使用 restart 指令重新啟動元件。

    舉例來說,如要重新啟動管理伺服器,請執行下列指令:

    /opt/apigee/apigee-service/bin/apigee-service edge-management-server restart

根據預設,系統不會啟用 JMX 驗證功能。您可以按照「啟用 JMX 驗證」的說明,為所有元件啟用 JMX 驗證。如要啟用 Cassandra 的 JMX 驗證,請參閱為 Cassandra 啟用 JMX 驗證

啟用 JMX 驗證

根據預設,系統不會啟用 JMX 驗證。您可以為所有元件啟用 JMX 驗證。若為 Cassandra,請使用「為 Cassandra 啟用 JMX 驗證」一文中的說明

如要啟用 JMX 驗證,請在所有節點上執行以下 change_jmx_auth 動作:

/opt/apigee/apigee-service/bin/apigee-service component_name change_jmx_auth [options|-f config_file]

在此情況下:

  • component 是下列其中一項:
    • edge-management-server
    • edge-message-processor
    • edge-postgres-server
    • edge-qpid-server
    • edge-router
  • options 會指定以下項目:
    • -u username
    • -p password
    • -e [y|n] (啟用或停用)
  • config_file 指定您定義以下項目的設定檔位置:
    • JMX_USERNAME=username
    • JMX_ENABLED=y|n
    • JMX_PASSWORD=password (如未設定或未以 -p 傳入,系統會提示您)

您可以使用指令列選項或設定檔來定義使用者名稱、密碼以及啟用/停用狀態。您無法同時指定一組選項和設定檔。

以下範例會使用指令列選項為 Management Server 啟用 JMX 驗證:

/opt/apigee/apigee-service/bin/apigee-service edge-management-server
    change_jmx_auth -u foo -p bar -e y

以下範例使用設定檔,而非指令列選項:

/opt/apigee/apigee-service/bin/apigee-service edge-management-server
    change_jmx_auth -f /tmp/my-config-file

如果您是在多個節點上執行 Edge,請在所有節點上執行該指令,指定相同的使用者名稱和密碼。

如要在指令列上停用 JMX 驗證,請使用「-e n」選項,如以下範例所示:

/opt/apigee/apigee-service/bin/apigee-service edge-management-server
    change_jmx_auth -e n

使用 JConsole 監控

使用 JConsole (與 JMX 相容的工具) 管理及監控健康狀態檢查和處理統計資料。透過 JConsole,您可以使用伺服器公開的 JMX 統計資料,並在圖形介面中顯示這些統計資料。詳情請參閱「使用 JConsole」一文。

JConsole 會使用下列服務網址來監控透過 JMX 提供的 JMX 屬性 (MBeans):

service:jmx:rmi:///jndi/rmi://IP_address:port_number/jmxrmi

在此情況下:

  • IP_address 是您要監控的伺服器 IP 位址。
  • port_number 是您要監控的伺服器 JMX 通訊埠編號

舉例來說,如要監控管理伺服器,請發出如下所示的指令 (假設伺服器的 IP 位址為 216.3.128.12):

service:jmx:rmi:///jndi/rmi://216.3.128.12:1099/jmxrmi

請注意,本例指定通訊埠 1099,也就是管理伺服器 JMX 通訊埠。如需其他通訊埠,請參閱 JMX and Management API 監控通訊埠

下表顯示一般 JMX 統計資料:

JMX MBeans JMX 屬性

記憶體容量

HeapMemoryUsage

NonHeapMemoryUsage

使用方式

使用 Management API 進行監控

Edge 包含數個 API,可用於在伺服器上執行服務檢查,以及檢查使用者、機構和部署作業。本節將說明這些 API。

執行服務檢查

Management API 提供多個端點,用於監控及診斷服務的問題。這些端點包括:

端點 說明
/servers/self/up

檢查服務是否正在執行。這項 API 呼叫不需要您進行驗證。

如果服務正在執行,此端點會傳回下列回應:

<ServerField>
  <Up>true</Up>
</ServerField>

如果服務未執行,您會收到類似以下的回應 (視服務與檢查方式而定):

curl: Failed connect to localhost:port_number; Connection refused
/servers/self

傳回服務相關資訊,包括:

  • 設定屬性
  • 開始時間和啟動時間
  • 版本、RPM 和 UUID 資訊
  • 內部和外部主機名稱和 IP 位址
  • 區域與 Pod
  • <isUp> 屬性,表示服務是否正在執行

您必須利用 Apigee 管理員憑證進行驗證,才能使用這個 API 呼叫。

如要使用這些端點,請透過使用以下語法的指令叫用 curl 等公用程式:

curl http://host:port_number/v1/servers/self/up -H "Accept: [application/json|application/xml]"
curl http://host:port_number/v1/servers/self -u username:password -H "Accept: [application/json|application/xml]"

在此情況下:

  • host 是您要檢查的伺服器 IP 位址。如果您已登入伺服器,可以使用「localhost」。否則,請指定伺服器的 IP 位址,以及使用者名稱和密碼。
  • port_number 是您要檢查的伺服器的 Management API 通訊埠。每個元件類型都會有不同的通訊埠。舉例來說,管理伺服器的 Management API 通訊埠為 8080。如需要使用的 Management API 通訊埠號碼清單,請參閱 JMX and Management API 監控通訊埠

如要變更回應的格式,您可以將 Accept 標頭指定為「application/json」或「application/xml」。

以下範例會取得 localhost (通訊埠 8081) 上的路由器狀態:

curl http://localhost:8081/v1/servers/self/up -H "Accept: application/xml"

以下範例會取得位於 216.3.128.12 (通訊埠 8082) 的訊息處理器相關資訊:

curl http://216.3.128.12:8082/v1/servers/self -u sysAdminEmail:password
  -H "Accept: application/xml"

監控使用者、機構和部署狀態

您可以使用 Management API 發出下列指令,監控管理伺服器和訊息處理器上的 Proxy 使用者、機構及部署狀態:

curl http://host:port_number/v1/users -u sysAdminEmail:password
curl http://host:port_number/v1/organizations -u sysAdminEmail:password
curl http://host:port_number/v1/organizations/orgname/deployments -u sysAdminEmail:password

其中 port_number 為管理伺服器的 8080,或訊息處理器的 8082。

此呼叫需要透過系統管理使用者名稱和密碼進行驗證。

伺服器應會針對所有呼叫傳回「部署」狀態。如果這些失敗,請執行下列步驟:

  1. 查看伺服器記錄,瞭解是否有任何錯誤。記錄位置:
    • 管理伺服器:opt/apigee/var/log/edge-management-server
    • 訊息處理器:opt/apigee/var/log/edge-message-processor
  2. 呼叫伺服器,檢查是否正常運作。
  3. 從 ELB 中移除伺服器,然後重新啟動:
    /opt/apigee/apigee-service/bin/apigee-service service_name restart

    其中 service_name 為:

    • edge-management-server
    • edge-message-processor

使用 apigee-service 指令檢查狀態

登入執行服務的伺服器時,您可以使用 apigee-service 指令排解 Edge 服務問題。

如何使用 apigee-service 查看服務狀態:

  1. 登入伺服器並執行下列指令:
    /opt/apigee/apigee-service/bin/apigee-service service_name status

    其中 service_name 是下列其中一項:

    • 管理伺服器:edge-management-server
    • 訊息處理器:edge-message-processor
    • Postgres:edge-postgres-server
    • Qpid:edge-qpid-server
    • 路由器:edge-router

    例如:

    /opt/apigee/apigee-service/bin/apigee-service edge-message-processor status
  2. 如果服務並未執行,請啟動服務:
    /opt/apigee/apigee-service/bin/apigee-service service_name start
  3. 重新啟動服務後,請使用先前使用的 apigee-service status 指令,或使用 Management API 監控的 Management API,確認服務是否正常運作。

    例如:

    curl -v http://localhost:port_number/v1/servers/self/up

    其中 port_number 是服務的 Management API 通訊埠

    本範例假設您已登入伺服器,並使用「localhost」做為主機名稱。如要使用 Management API 從遠端檢查狀態,您必須指定伺服器的 IP 位址,並在 API 呼叫中加入系統管理員使用者名稱和密碼。

Postgres 監控

Postgres 支援多種公用程式,方便您查看其狀態。後續章節會說明這些公用程式。

檢查 Postgres 上的機構和環境

您可以發出以下 curl 指令,查看已登錄在 Postgres 伺服器上的機構和環境名稱:

curl -v http://postgres_IP:8084/v1/servers/self/organizations

系統應會顯示機構和環境名稱。

驗證數據分析狀態

您可以發出以下 curl 指令,驗證 Postgres 和 Qpid 分析伺服器的狀態:

curl -u userEmail:password http://host:port_number/v1/organizations/orgname/environments/envname/provisioning/axstatus

系統應顯示所有分析伺服器的成功狀態,如以下範例所示:

{
  "environments" : [ {
    "components" : [ {
      "message" : "success at Thu Feb 28 10:27:38 CET 2013",
      "name" : "pg",
      "status" : "SUCCESS",
      "uuid" : "[c678d16c-7990-4a5a-ae19-a99f925fcb93]"
     }, {
      "message" : "success at Thu Feb 28 10:29:03 CET 2013",
      "name" : "qs",
      "status" : "SUCCESS",
      "uuid" : "[ee9f0db7-a9d3-4d21-96c5-1a15b0bf0adf]"
     } ],
    "message" : "",
    "name" : "prod"
   } ],
  "organization" : "acme",
  "status" : "SUCCESS"
}

PostgreSQL 資料庫

本節說明監控 Postgres 資料庫時可以使用的技術。

使用 check_postgres.pl 指令碼

如要監控 PostgreSQL 資料庫,您可以使用標準監控指令碼 check_postgres.pl。詳情請參閱 http://bucardo.org/wiki/Check_postgres

執行指令碼之前:

  1. 您必須在每個 Postgres 節點上安裝 check_postgres.pl 指令碼。
  2. 請確認您已安裝 perl-Time-HiRes.x86_64,這個 Perl 模組可實作高解析度鬧鐘、睡眠、gettimeofday 和間隔計時器。舉例來說,您可以使用下列指令進行安裝:
    yum install perl-Time-HiRes.x86_64
  3. CentOS 7:在 CentOS v7 上使用 check_postgres.pl 之前,請先安裝 perl-Data-Dumper.x86_64 RPM。

check_postgres.pl 輸出內容

使用 check_postgres.pl 的 API 呼叫預設輸出內容與 Nagios 相容。安裝指令碼後,請進行下列檢查:

  1. 檢查資料庫大小:
    check_postgres.pl -H 10.176.218.202 -db apigee -u apigee -dbpass postgres -include=apigee -action database_size --warning='800 GB' --critical='900 GB'
  2. 檢查資料庫的連入連線數量,並與允許的連線數量上限進行比較:
    check_postgres.pl -H 10.176.218.202 -db apigee -u apigee -dbpass postgres -action backends
  3. 檢查資料庫是否正在運作且可供使用:
    check_postgres.pl -H 10.176.218.202 -db apigee -u apigee -dbpass postgres -action connection
  4. 檢查磁碟空間:
    check_postgres.pl -H 10.176.218.202 -db apigee -u apigee -dbpass postgres -action disk_space --warning='80%' --critical='90%'
  5. 查看在 Postgres 節點中登錄的機構和環境數量:
    check_postgres.pl -H 10.176.218.202 -db apigee -u apigee -dbpass postgres -action=custom_query --query="select count(*) as result from pg_tables where schemaname='analytics' and tablename like '%fact'" --warning='80' --critical='90' --valtype=integer

執行資料庫檢查

您可以驗證在 PostgreSQL 資料庫中建立適當的資料表。使用下列指令登入 PostgreSQL 資料庫:

psql -h /opt/apigee/var/run/apigee-postgresql/ -U apigee -d apigee

然後執行:

\d analytics."org.env.fact"

檢查 Postgres 程序的健康狀態

您可以叫用下列 curl 指令,對 Postgres 機器執行 API 檢查:

curl -v http://postgres_IP:8084/v1/servers/self/health

這個指令會在 Postgres 程序執行時傳回 ACTIVE 狀態。如果 Postgres 程序未啟動且執行,會傳回 INACTIVE 狀態。

Postgres 資源

如要進一步瞭解如何監控 Postgres 服務,請參閱以下資源:

Apache Cassandra

根據預設,Cassandra 會啟用 JMX,而 Cassandra 的遠端 JMX 存取權則不需要密碼。

為 Cassandra 啟用 JMX 驗證

您可以為 Cassandra 啟用 JMX 驗證。完成此操作後,您接著就必須將使用者名稱和密碼傳送至所有對 nodetool 公用程式的呼叫。

如何為 Cassandra 啟用 JMX 驗證:

  1. 建立及編輯 cassandra.properties 檔案:
    1. 編輯 /opt/apigee/customer/application/cassandra.properties 檔案。如果檔案不存在,請建立檔案。
    2. 在檔案中加入以下內容:
      conf_cassandra-env_com.sun.management.jmxremote.authenticate=true
      conf_cassandra-env_com.sun.management.jmxremote.password.file=${APIGEE_ROOT}/data/apigee-cassandra/jmxremote.password
      conf_cassandra-env_com.sun.management.jmxremote.access.file=${APIGEE_ROOT}/data/apigee-cassandra/jmxremote.access
    3. 儲存 cassandra.properties 檔案。
    4. 將檔案的擁有者變更為 apigee:apigee,如以下範例所示:
      chown apigee:apigee /opt/apigee/customer/application/cassandra.properties

    如要進一步瞭解如何使用屬性檔案設定符記,請參閱如何設定 Edge

  2. 建立及編輯 jmx_auth.sh
    1. 若檔案不存在,請在以下位置建立檔案:
      /opt/apigee/customer/application/jmx_auth.sh
    2. 在檔案中加入下列屬性:
      export CASS_JMX_USERNAME=JMX_USERNAME
      export CASS_JMX_PASSWORD=JMX_PASSWORD
    3. 儲存 jmx_auth.sh 檔案。
    4. 來源檔案:
      source /opt/apigee/customer/application/jmx_auth.sh
  3. 複製並編輯 jmxremote.password 檔案:
    1. 將下列檔案從 $JAVA_HOME 目錄複製到 /opt/apigee/data/apigee-cassandra/
      cp ${JAVA_HOME}/lib/management/jmxremote.password.template $APIGEE_ROOT/data/apigee-cassandra/jmxremote.password
    2. 編輯 jmxremote.password 檔案,並使用下列語法新增 JMX 使用者名稱和密碼:
      JMX_USERNAME JMX_PASSWORD

      其中 JMX_USERNAMEJMX_PASSWORD 是您先前設定的 JMX 使用者名稱和密碼。

    3. 確認檔案屬於「apigee」,且檔案模式為 400:
      chown apigee:apigee /opt/apigee/data/apigee-cassandra/jmxremote.password
      chmod 400 /opt/apigee/data/apigee-cassandra/jmxremote.password
  4. 複製並編輯 jmxremote.access 檔案:
    1. 將下列檔案從 $JAVA_HOME 目錄複製到 /opt/apigee/data/apigee-cassandra/
      cp ${JAVA_HOME}/lib/management/jmxremote.access $APIGEE_ROOT/data/apigee-cassandra/jmxremote.access
    2. 編輯 jmxremote.access 檔案,並新增下列角色:
      JMX_USERNAME readwrite
    3. 確認檔案屬於「apigee」,且檔案模式為 400:
      chown apigee:apigee /opt/apigee/data/apigee-cassandra/jmxremote.access
      chmod 400 /opt/apigee/data/apigee-cassandra/jmxremote.access
  5. 在 Cassandra 上執行 configure
    /opt/apigee/apigee-service/bin/apigee-service apigee-cassandra configure
  6. 重新啟動 Cassandra:
    /opt/apigee/apigee-service/bin/apigee-service apigee-cassandra restart
  7. 在其他 Cassandra 節點上重複執行這項程序。

啟用 JMX 密碼加密功能

如要啟用 JMX 密碼加密功能,請按照下列步驟操作:

  1. 開啟 source/conf/casssandra-env.sh 檔案。
  2. 將檔案中的下列幾行取消註解:
    • JVM_OPTS="$JVM_OPTS -Djava.security.auth.login.config={T}conf_cassandra-env_java.security.auth.login.config{/T}"
    • JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.login.config=ApigeeSecureFileLoginModule"
  3. 在指令列中輸入 echo -n 'Secret' | openssl dgst -sha1,產生所需密碼的 SHA1 雜湊
  4. 依據 jmxremote.password 的使用者名稱設定密碼。
  5. 在更新後將 cassandra-env.sh 檔案改回唯讀狀態。

為 Cassandra 啟用 JMX 搭配 SSL

透過 SSL 啟用 JMX,可為與 Cassandra 之間的 JMX 通訊提供額外的安全性和加密功能。如要啟用 JMX 的 SSL 功能,您必須將金鑰和憑證提供給 Cassandra,才能接受以 SSL 為基礎的 JMX 連線。您也需要設定 nodetool (以及任何透過 JMX 與 Cassandra 進行通訊的工具) 進行安全資料傳輸層 (SSL)。

啟用 SSL 的 JMX 同時支援明文和加密的 JMX 密碼。

如要為 Cassandra 啟用包含 SSL 的 JMX,請按照下列程序操作:

  1. 啟用 JMX。 如有需要,請啟用密碼加密功能。
  2. 啟用 Cassandra 的 JMX 驗證。。並確保 nodetool 使用設定好的使用者名稱和密碼。
    /opt/apigee/apigee-cassandra/bin/nodetool -u <JMX_USER> -pw <JMX_PASS> ring
  3. 準備 KeyStore 和 TrustStore。

    • KeyStore 應包含金鑰和憑證,並用於設定 Cassandra 伺服器。如果 KeyStore 包含多個金鑰組,Cassandra 會使用第一個金鑰組來啟用安全資料傳輸層 (SSL)。

      請注意,KeyStore 和金鑰的密碼應相同 (使用 keytool 產生金鑰時的預設值)。

    • Truststore 應僅包含憑證,供用戶端 (Apigee-service 型指令或 nodetool) 透過 JMX 連線。

    確認上述規定後:

    1. 將 KeyStore 檔案放入 /opt/apigee/data/apigee-cassandra 中。
    2. 輸入
      chown apigee:apigee /opt/apigee/data/apigee-cassandra/keystore.node1
      chmod 400 /opt/apigee/data/apigee-cassandra/keystore.node1
      ,確保只有 Apigee 使用者能夠讀取 KeyStore 檔案
  4. 透過下列步驟為 JMX 設定 Cassandra:
    1. 輸入
      apigee-service apigee-cassandra stop
      以停止 Cassandra 節點
    2. 開啟 /opt/apigee/customer/application/cassandra.properties 檔案並新增下列這行程式碼,在 Cassandra 中啟用 SSL:
      conf_cassandra-env_com.sun.management.jmxremote.ssl=true

      這個檔案的擁有者必須為 apigee:apigee

    3. 如下所示,在 Cassandra 中啟用 SSL 相關設定。開啟 /opt/apigee/apigee-cassandra/source/conf/cassandra-env.sh 檔案並取消註解下列幾行,視需要變更路徑 /opt/apigee/data/apigee-cassandra/keystore.node1 和 KeyStore 密碼。
      JVM_OPTS="$JVM_OPTS -Djavax.net.ssl.keyStore=/opt/apigee/data/apigee-cassandra/keystore.node1"
      JVM_OPTS="$JVM_OPTS -Djavax.net.ssl.keyStorePassword=keystore-password"
      JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.registry.ssl=true"
      請確認該檔案的擁有者為 apigee:apigee
    4. 輸入
      apigee-service apigee-cassandra start
      即可啟動 Cassandra 節點
  5. 設定 apigee-service Cassandra 指令。執行 apigee-service 指令時,您必須設定某些環境變數,包括下列變數:
    apigee-service apigee-cassandra stop
    apigee-service apigee-cassandra wait_for_ready
    apigee-service apigee-cassandra ring
    apigee-service apigee-cassandra backup

    您可以透過多種方式為 JMX 驗證和安全資料傳輸層 (SSL) 設定 apigee-service。請根據可用性和安全性做法選擇合適的方案。

    選項 1 (儲存在檔案中的 SSL 引數)

    設定下列環境變數:

    export CASS_JMX_USERNAME=ADMIN
    # Provide encrypted password here if you have setup JMX password encryption
    export CASS_JMX_PASSWORD=PASSWORD
    export CASS_JMX_SSL=Y

    在 Apigee 使用者的主目錄中 (/opt/apigee) 建立檔案。

    $HOME/.cassandra/nodetool-ssl.properties

    編輯檔案,並新增下列幾行內容:

    -Djavax.net.ssl.trustStore=<path-to-truststore.node1>
    -Djavax.net.ssl.trustStorePassword=<truststore-password>
    -Dcom.sun.management.jmxremote.registry.ssl=true

    請確認 Apigee 使用者能夠讀取信任的檔案。

    執行下列 apigee-service 指令。如果能在沒有錯誤的情況下執行,表示設定正確無誤。

    apigee-service apigee-cassandra ring

    選項 2 (儲存在環境變數中的 SSL 引數)

    設定下列環境變數:

    export CASS_JMX_USERNAME=ADMIN
    # Provide encrypted password here if you have setup JMX password encryption
    export CASS_JMX_PASSWORD=PASSWORD
    export CASS_JMX_SSL=Y
    # Ensure the truststore file is accessible by Apigee user.
    export CASS_JMX_TRUSTSTORE=<path-to-trustore.node1>
    export CASS_JMX_TRUSTSTORE_PASSWORD=<truststore-password>

    執行下列 apigee-service 指令。如果能在沒有錯誤的情況下執行,表示設定正確無誤。

    apigee-service apigee-cassandra ring

    選項 3 (直接傳遞至 apigee-service 的 SSL 引數)

    執行任何 apigee-service 指令,如下所示。您不需要設定任何環境變數。

    CASS_JMX_USERNAME=ADMIN CASS_JMX_PASSWORD=PASSWORD CASS_JMX_SSL=Y CASS_JMX_TRUSTSTORE=<path-to-trustore.node1> CASS_JMX_TRUSTSTORE_PASSWORD=<trustore-password> /opt/apigee/apigee-service/bin/apigee-service apigee-cassandra ring
  6. 設定 nodetool。必須將 JMX 參數傳送至 Nodetool。您可以透過兩種方式將 nodetool 設為在啟用 SSL 的 JMX 時執行,如以下設定選項所述:

    而安全資料傳輸層 (SSL) 相關設定傳送至 nodetool 的方式則有所不同。在這兩種情況下,執行 nodetool 的使用者必須具備信任儲存庫檔案的 READ 權限。請根據可用性和安全性做法選擇合適的選項。

    如要進一步瞭解 nodetool 參數,請參閱 DataStax 說明文件

    設定選項 1

    在執行 nodetool 的使用者主目錄中建立檔案。

    $HOME/.cassandra/nodetool-ssl.properties

    在檔案中新增下列幾行內容:

    -Djavax.net.ssl.trustStore=<path-to-truststore.node1>
    -Djavax.net.ssl.trustStorePassword=<truststore-password>
    -Dcom.sun.management.jmxremote.registry.ssl=true

    執行 nodetool 的任何使用者都可存取上方指定的信任儲存庫路徑。

    搭配 --ssl 選項執行 nodetool

    /opt/apigee/apigee-cassandra/bin/nodetool --ssl -u <jmx-user-name> -pw <jmx-user-password> -h localhost ring

    設定選項 2

    nodetool 當做單一指令執行,其中包含下列額外的參數。

    /opt/apigee/apigee-cassandra/bin/nodetool -Djavax.net.ssl.trustStore=<path-to-truststore.node1> -Djavax.net.ssl.trustStorePassword=<truststore-password> -Dcom.sun.management.jmxremote.registry.ssl=true -Dssl.enable=true -u <jmx-user-name> -pw <jmx-user-password> -h localhost ring

還原 SSL 設定

如果您需要還原上方程序所述的 SSL 設定,請按照下列步驟操作:

  1. 輸入「
    apigee-service apigee-cassandra stop
    」即可停止「apigee-cassandra
  2. 從檔案 /opt/apigee/customer/application/cassandra.properties 中移除這行 conf_cassandra-env_com.sun.management.jmxremote.ssl=true
  3. /opt/apigee/apigee-cassandra/source/conf/cassandra-env.sh
    # JVM_OPTS="$JVM_OPTS -Djavax.net.ssl.keyStore=/opt/apigee/data/apigee-cassandra/keystore.node0"
    # JVM_OPTS="$JVM_OPTS -Djavax.net.ssl.keyStorePassword=keypass"
    # JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.registry.ssl=true”
    中的下列幾行註解排除
  4. 輸入即可啟動「apigee-cassandra
  5. apigee-service apigee-cassandra start
  6. 移除環境變數 CASS_JMX_SSL (如有)。

    unset CASS_JMX_SSL
  7. 確認 apigee-service 型指令 (例如 ringstopbackup 等) 是否正常運作。
  8. 停止搭配 nodetool 使用 --ssl 開關

停用 Cassandra 的 JMX 驗證

如何停用 Cassandra 的 JMX 驗證:

  1. 編輯 /opt/apigee/customer/application/cassandra.properties
  2. 在檔案中移除以下這行內容:
    conf_cassandra-env_com.sun.management.jmxremote.authenticate=true
  3. 在 Cassandra 上執行設定:
    /opt/apigee/apigee-service/bin/apigee-service apigee-cassandra configure
  4. 重新啟動 Cassandra:
    /opt/apigee/apigee-service/bin/apigee-service apigee-cassandra restart
  5. 在其他 Cassandra 節點上重複執行這項程序。

使用 JConsole:監控工作統計資料

使用 JConsole 和下列服務網址,監控透過 JMX 提供的 JMX 屬性 (MBeans):

service:jmx:rmi:///jndi/rmi://IP_address:7199/jmxrmi

其中 IP_address 是 Cassandra 伺服器的 IP。

Cassandra JMX 統計資料

JMX MBeans JMX 屬性

ColumnFamilies/apprepo/環境

ColumnFamilies/apprepo/機構

ColumnFamilies/apprepo/apiproxy_revisions

資料欄系列/apprepo/apiproxies

資料欄系列/稽核/稽核

資料欄 Families/audit/audits_ref

PendingTasks

MemtableColumnsCount

MemtableDataSize

ReadCount

RecentReadLatencyMicros

TotalReadLatencyMicros

WriteCount

RecentWriteLatencyMicros

TotalWriteLatencyMicros

TotalDiskSpaceUsed

LiveDiskSpaceUsed

LiveSSTableCount

BloomFilterFalsePositives

RecentBloomFilterFalseRatio

BloomFilterFalseRatio

使用 nodetool 管理叢集節點

nodetool 公用程式是 Cassandra 的指令列介面,負責管理叢集節點。這個公用程式位於 /opt/apigee/apigee-cassandra/bin

下列呼叫可以對所有 Cassandra 叢集節點發出:

  1. 一般環形資訊 (單一 Cassandra 節點也可以):找出所有節點的「向上」和「一般」狀態。
    nodetool [-u username -pw password] -h localhost ring

    只有在為 Cassandra 啟用 JMX 驗證時,才需要傳送使用者名稱和密碼。

    上述指令的輸出內容如下所示:

    Datacenter: dc-1
    ==========
    Address            Rack     Status State   Load    Owns    Token
    192.168.124.201    ra1      Up     Normal  1.67 MB 33,33%  0
    192.168.124.202    ra1      Up     Normal  1.68 MB 33,33%  5671...5242
    192.168.124.203    ra1      Up     Normal  1.67 MB 33,33%  1134...0484

  2. 節點一般資訊 (每個節點的呼叫)
    nodetool [-u username -pw password]  -h localhost info

    上述指令的輸出內容如下所示:

    ID                     : e2e42793-4242-4e82-bcf0-oicu812
    Gossip active          : true
    Thrift active          : true
    Native Transport active: true
    Load                   : 273.71 KB
    Generation No          : 1234567890
    Uptime (seconds)       : 687194
    Heap Memory (MB)       : 314.62 / 3680.00
    Off Heap Memory (MB)   : 0.14
    Data Center            : dc-1
    Rack                   : ra-1
    Exceptions             : 0
    Key Cache              : entries 150, size 13.52 KB, capacity 100 MB, 1520781 hits, 1520923 requests, 1.000 recent hit rate, 14400 save period in seconds
    Row Cache              : entries 0, size 0 bytes, capacity 0 bytes, 0 hits, 0 requests, NaN recent hit rate, 0 save period in seconds
    Counter Cache          : entries 0, size 0 bytes, capacity 50 MB, 0 hits, 0 requests, NaN recent hit rate, 7200 save period in seconds
    Token                  : 0
  3. 二手伺服器狀態 (服務用戶端 API)
    nodetool [-u username -pw password] -h localhost statusthrift

    上述指令的輸出內容如下所示:

    running

  4. 資料串流作業狀態:觀察 Cassandra 節點流量:
    nodetool [-u username -pw password] -h localhost netstats

    上述指令的輸出內容如下所示:

    Mode: NORMAL
    Not sending any streams.
    Read Repair Statistics:
    Attempted: 151612
    Mismatch (Blocking): 0
    Mismatch (Background): 0
    Pool Name                    Active   Pending      Completed   Dropped
    Commands                        n/a         0              0         0
    Responses                       n/a         0              0       n/a

如要進一步瞭解 nodetool,請參閱「關於 nodetool 公用程式」。

Cassandra 資源

請參考下列網址:http://www.datastax.com/docs/1.0/operations/monitoring

Apache ZooKeeper

查看 ZooKeeper 狀態

  1. 確保 ZooKeeper 程序正在執行。ZooKeeper 將 PID 檔案寫入 opt/apigee/var/run/apigee-zookeeper/apigee-zookeeper.pid
  2. 測試 ZooKeeper 通訊埠,確保您可以在每個 ZooKeeper 伺服器上與通訊埠 2181 和 3888 之間建立 TCP 連線。
  3. 確認可以讀取 ZooKeeper 資料庫中的值。使用 ZooKeeper 用戶端程式庫 (或 /opt/apigee/apigee-zookeeper/bin/zkCli.sh) 進行連線,並讀取資料庫中的值。
  4. 查看狀態:
    /opt/apigee/apigee-service/bin/apigee-service apigee-zookeeper status

使用 ZooKeeper (四個字母組成的字詞)

您可以透過一組使用 netcat (nc) 或 telnet 傳送至通訊埠 2181 的一組指令 (四個字母的字詞),藉此監控 ZooKeeper。

如要進一步瞭解 ZooKeeper 指令,請參閱 Apache ZooKeeper 指令參考資料

例如:

  • srvr:列出伺服器的完整詳細資料。
  • stat:列出伺服器和已連線用戶端的簡短詳細資料。

下列指令可發出至 ZooKeeper 通訊埠:

  1. 執行四個字母的指令 ruok,測試伺服器是否處於非錯誤狀態。成功的回應會傳回「imok」。
    echo ruok | nc host 2181

    退貨:

    imok
  2. 執行四個字母組成的指令 stat,列出伺服器效能和已連線的用戶端統計資料:
    echo stat | nc host 2181

    退貨:

    Zookeeper version: 3.4.5-1392090, built on 09/30/2012 17:52 GMT
    Clients:
    /0:0:0:0:0:0:0:1:33467[0](queued=0,recved=1,sent=0)
    /192.168.124.201:42388[1](queued=0,recved=8433,sent=8433)
    /192.168.124.202:42185[1](queued=0,recved=1339,sent=1347)
    /192.168.124.204:39296[1](queued=0,recved=7688,sent=7692)
    Latency min/avg/max: 0/0/128
    Received: 26144
    Sent: 26160
    Connections: 4
    Outstanding: 0
    Zxid: 0x2000002c2
    Mode: follower
    Node count: 283
  3. 如果無法使用 netcat (nc),可將 Python 做為替代方案。建立名為 zookeeper.py 的檔案,其中含有以下內容:
          import time, socket, sys
          c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          c.connect((sys.argv[1], 2181))
          c.send(sys.argv[2])
          time.sleep(0.1)
          print c.recv(512)

    現在,請執行以下 Python 行:

    python zookeeper.py 192.168.124.201 ruok
    python zookeeper.py 192.168.124.201 stat

LDAP 等級測試

您可以監控 OpenLDAP,確認特定的要求是否正確提供。換句話說,請檢查是否有特定搜尋傳回正確的結果。

  1. 使用 ldapsearch (yum install openldap-clients) 查詢系統管理員的項目。這個項目可以用來驗證所有 API 呼叫。
    ldapsearch -b "uid=admin,ou=users,ou=global,dc=apigee,dc=com" -x -W -D "cn=manager,dc=apigee,dc=com" -H ldap://localhost:10389 -LLL

    系統會提示您輸入 LDAP 管理員密碼:

    Enter LDAP Password:

    輸入密碼後,您會看到以下表單回應:

    dn:
    uid=admin,ou=users,ou=global,dc=apigee,dc=com
    objectClass: organizationalPerson
    objectClass: person
    objectClass: inetOrgPerson
    objectClass: top
    uid: admin
    cn: admin
    sn: admin
    userPassword:: e1NTSEF9bS9xbS9RbVNXSFFtUWVsU1F0c3BGL3BQMkhObFp2eDFKUytmZVE9PQ=
     =
    mail: opdk@google.com
  2. 請使用下列指令,檢查管理伺服器是否仍與 LDAP 連線:
    curl -u userEMail:password http://localhost:8080/v1/users/ADMIN

    退貨:

    {
      "emailId" : ADMIN,
      "firstName" : "admin",
      "lastName" : "admin"
    }

您也可以監控 OpenLDAP 快取,這有助於減少磁碟存取次數,進而提升系統效能。監控並調整 OpenLDAP 伺服器中的快取大小,可能會大幅影響目錄伺服器的效能。您可以查看記錄檔 (opt/apigee/var/log) 來取得快取的相關資訊。