管理及監控 AlloyDB Omni

選取說明文件版本:

本頁面說明如何管理 AlloyDB Omni 使用者角色、監控 AlloyDB Omni 伺服器的活動,以及更新或移除 AlloyDB Omni 安裝項目。

管理使用者角色

AlloyDB Omni 使用與 AlloyDB for PostgreSQL 相同的預先定義 PostgreSQL 使用者角色集,但有以下差異:

  • AlloyDB Omni 包含名為 alloydbadmin 的超級使用者角色,以及名為 alloydbmetadata 的非超級使用者角色。

  • 預設 postgres 使用者具有超級使用者角色。

  • 其他所有預先定義的使用者角色都沒有權限。保留供日後使用。

設定 AlloyDB Omni 資料庫

與 AlloyDB 相同,設定資料庫時,建議遵循下列步驟:

  1. 使用 postgres 使用者角色定義或匯入資料庫。在新安裝中,這個角色具有超級使用者權限,且不需要密碼。

  2. 使用 postgres 使用者角色,建立具有應用程式表格適當存取層級的新使用者角色。

  3. 設定應用程式,使用這些新的有限存取權角色連線至資料庫。

您可以視需要建立及定義任意數量的新使用者角色。請勿修改或刪除 AlloyDB Omni 隨附的任何使用者角色。

詳情請參閱「管理 AlloyDB Omni 使用者和角色」。

監控 AlloyDB Omni

監控 AlloyDB Omni 安裝作業時,需要讀取及分析 AlloyDB Omni 記錄檔。

Kubernetes 上執行的 AlloyDB Omni 提供一組基本指標,可做為 Prometheus 端點。如需可用指標清單,請參閱 AlloyDB Omni 指標

此外,在 Kubernetes 上執行的 AlloyDB Omni 會透過 kube-state-metrics (KSM) 運用自訂資源,公開指標。如要啟用自訂資源指標,請參閱「監控 AlloyDB Omni Kubernetes 運算子自訂資源」。

單一伺服器

根據預設,如要擷取 AlloyDB Omni 記錄,請執行下列指令:

Docker

  docker logs CONTAINER_NAME

CONTAINER_NAME 替換為 AlloyDB Omni 容器名稱。

如要設定 AlloyDB Omni 的記錄行為,請參閱「自訂 AlloyDB Omni 安裝作業」。

Podman

  podman logs CONTAINER_NAME

CONTAINER_NAME 替換為 AlloyDB Omni 容器名稱。

如要設定 AlloyDB Omni 的記錄行為,請參閱「自訂 AlloyDB Omni 安裝作業」。

Kubernetes

找出資料庫叢集記錄檔

postgresql.auditpostgresql.log 檔案位於資料庫 Pod 的檔案系統中。只有在啟用 pgaudit 時,才會顯示 postgresql.audit

如要存取這些檔案,請按照下列步驟操作:

  1. 定義包含資料庫 Pod 名稱的環境變數。

    export DB_POD=`kubectl get pod -l alloydbomni.internal.dbadmin.goog/dbcluster=DB_CLUSTER_NAME,alloydbomni.internal.dbadmin.goog/task-type=database -o jsonpath='{.items[0].metadata.name}'`

    請將 DB_CLUSTER_NAME 替換成資料庫叢集的名稱。也就是您建立資料庫叢集時宣告的名稱。

  2. 以根使用者身分在資料庫 Pod 上執行 Shell。

    kubectl exec ${DB_POD} -it -- /bin/bash
  3. /obs/diagnostic/ 目錄中找出記錄檔:

    • /obs/diagnostic/postgresql.audit
    • /obs/diagnostic/postgresql.log

列出監控服務

v1.0

建立資料庫叢集時,AlloyDB Omni 會在相同命名空間中,為資料庫叢集的每個執行個體 CR 建立下列監控服務:

al-INSTANCE_NAME-monitoring-system

如要列出監控服務,請執行下列指令。

kubectl get svc -n NAMESPACE | grep monitoring

NAMESPACE 替換為叢集所屬的命名空間。

以下範例回應顯示 al-1060-dbc-monitoring-systemal-3de6-dbc-monitoring-systemal-4bc0-dbc-monitoring-system 服務。每項服務對應一個執行個體。

al-1060-dbc-monitoring-system   ClusterIP   10.0.15.227   <none>        9187/TCP   7d20h
al-3de6-dbc-monitoring-system   ClusterIP   10.0.5.205    <none>        9187/TCP   7d19h
al-4bc0-dbc-monitoring-system   ClusterIP   10.0.15.92    <none>        9187/TCP   7d19h

1.0 以下版本

建立資料庫叢集時,AlloyDB Omni 會在與資料庫叢集相同的命名空間中,建立下列監控服務:

  • DB_CLUSTER-monitoring-db

  • DB_CLUSTER-monitoring-system

如要列出監控服務,請執行下列指令。

kubectl get svc -n NAMESPACE | grep monitoring

NAMESPACE 替換為叢集所屬的命名空間。

以下範例回應顯示 al-2953-dbcluster-foo7-monitoring-systemal-2953-dbcluster-foo7-monitoring-db 服務。

al-2953-dbcluster-foo7-monitoring-db           ClusterIP   10.36.3.243    <none>        9187/TCP   44m
al-2953-dbcluster-foo7-monitoring-system       ClusterIP   10.36.7.72     <none>        9187/TCP   44m

透過指令列查看 Prometheus 指標

所有監控服務的通訊埠 9187 都命名為 metricsalloydbomni

  1. 設定從本機環境到監控服務的通訊埠轉送。

    kubectl port-forward service/MONITORING_SERVICE -n NAMESPACE MONITORING_METRICS_PORT:metricsalloydbomni
    

    更改下列內容:

    • MONITORING_SERVICE:要轉送的監控服務名稱,例如 al-1060-dbc-monitoring-system

    • NAMESPACE:叢集所屬的命名空間。

    • MONITORING_METRICS_PORT:本機可用的 TCP 通訊埠。

    下列回應顯示服務正在轉送。

    Forwarding from 127.0.0.1:9187 -> 9187
    Forwarding from [::1]:9187 -> 9187
    
  2. 執行上一個指令時,您可以在指定的通訊埠上透過 HTTP 存取監控指標。舉例來說,您可以使用 curl 以純文字格式查看所有指標:

    curl http://localhost:MONITORING_METRICS_PORT/metrics
    

使用 Prometheus API 查看指標

alloydbomni.internal.dbadmin.goog/task-type 標籤鍵和 metricsalloydbomni 連接埠預設適用於 AlloyDB Omni 中的所有監控服務。您可以將這些資源與單一 serviceMonitor 自訂資源搭配使用,為資料庫叢集中的所有命名空間選取所有服務。

如要進一步瞭解如何使用 Prometheus API,請參閱 Prometheus Operator 說明文件

以下是 serviceMonitor 自訂資源的 spec 欄位範例,當中包含 alloydbomni.internal.dbadmin.gdc.goog/task-type 標籤鍵和 metricsalloydbomni 連接埠。serviceMonitor 自訂資源會監控及收集所有命名空間中的所有 Kubernetes 服務,

如要進一步瞭解完整的 ServiceMonitor 定義,請參閱 ServiceMonitor 自訂資源定義

v1.0

    spec:
      selector:
        matchLabels:
          alloydbomni.internal.dbadmin.goog/task-type: monitoring
      namespaceSelector:
        any: true
      endpoints:
        - port: metricsalloydbomni

1.0 以下版本

    spec:
      selector:
        matchExpressions:
        - key: alloydbomni.internal.dbadmin.gdc.goog/task-type
          operator: Exists
          values: []
      namespaceSelector:
        any: true
      endpoints:
      - port: metricsalloydbomni

使用 Grafana 查看指標

如要以視覺化方式呈現 Kubernetes 上 AlloyDB Omni 的指標,請使用監控資訊主頁。監控資訊主頁採用由 Prometheus 和 Grafana 組成的基本可觀測性堆疊。如要設定監控資訊主頁,從 AlloyDB Omni 收集指標,請按照下列步驟操作:

  1. 如要下載 Grafana 資訊主頁,請使用 wget 指令:

    wget https://raw.githubusercontent.com/GoogleCloudPlatform/alloydb-omni-samples/refs/heads/main/monitoring-dashboards/grafana/alloydbomni_dashboard.yaml
    
  2. 您必須先下載並安裝 grafana-operator,才能在 Kubernetes 中部署 Grafana。如需詳細操作說明,請參閱「安裝」。

  3. 在安裝資訊主頁的 Grafana 執行個體中新增 monitoring.dashboard/product=alloydb-omni 標籤:

    kubectl label grafana/GRAFANA_INSTANCE_NAME monitoring.dashboard/product=alloydb-omni -n NAMESPACE
    

    更改下列內容:

    • GRAFANA_INSTANCE_NAME:您放置資訊主頁的 Grafana 執行個體名稱。
    • NAMESPACE:部署 Grafana 運算子的命名空間。
  4. 如要將 Grafana 資訊主頁設定套用至 Kubernetes 上的 AlloyDB Omni 叢集,請使用下列指令:

    kubectl apply -f alloydbomni_dashboard.yaml -n NAMESPACE
    

    如要瞭解如何使用 Grafana 運算子,請參閱 Grafana 運算子說明文件

  5. 如要設定 Grafana 使用 Prometheus 做為資料來源,請參閱「資料來源」。

  6. 如要確認 Grafana 設定正確無誤,請執行下列任一操作:

    • 查看 AlloyDB Omni 資訊主頁上的 Grafana 面板集合。
    • 在 Kubernetes 叢集中擷取 Grafana 資訊主頁的相關資訊:

      kubectl get grafanadashboard alloydb-omni-dashboard -n NAMESPACE -o jsonpath='{.status.conditions[?(@.type=="DashboardSynchronized")].status}'
      

      如果指令傳回 True,表示 alloydb-omni-dashboard 已成功部署至 Grafana 執行個體。

升級 AlloyDB Omni

如要從 AlloyDB Omni 15.5.2 或更早版本升級至 15.5.4,請按照「從舊版 AlloyDB Omni 遷移至最新版本」中的操作說明進行。

如要從 15.5.4 以上版本升級:

  1. 使用新的映像檔版本重新啟動 AlloyDB Omni。

  2. 請務必指定資料目錄,使其路徑與舊版 AlloyDB Omni 中使用的路徑相同。

解除安裝 AlloyDB Omni

單一伺服器

如要解除安裝 AlloyDB Omni,請使用下列指令停止並刪除 AlloyDB Omni 容器:

Docker

 docker container stop CONTAINER_NAME
   docker container rm CONTAINER_NAME

CONTAINER_NAME 替換為 AlloyDB Omni 容器名稱。

Podman

 podman container stop CONTAINER_NAME
   podman container rm CONTAINER_NAME

CONTAINER_NAME 替換為 AlloyDB Omni 容器名稱。

Podman

 podman container stop CONTAINER_NAME
   podman container rm CONTAINER_NAME

CONTAINER_NAME 替換為 AlloyDB Omni 容器名稱。

您可以視要保留資料的方式,在解除安裝 AlloyDB Omni 後移動、封存或刪除外部資料目錄。

Kubernetes

刪除資料庫叢集

如要刪除資料庫叢集,請在資訊清單中將 isDeleted 設為 true。 您可以使用下列指令完成這項操作。

kubectl patch dbclusters.alloydbomni.dbadmin.goog DB_CLUSTER_NAME -p '{"spec":{"isDeleted":true}}' --type=merge

請將 DB_CLUSTER_NAME 替換為資料庫叢集名稱。也就是您建立資料庫叢集時宣告的名稱。

解除安裝 AlloyDB Omni 運算子

如要從 Kubernetes 叢集解除安裝 AlloyDB Omni Kubernetes 運算子,請按照下列步驟操作:

  1. 刪除所有資料庫叢集:

    for ns in $(kubectl get dbclusters.alloydbomni.dbadmin.goog --all-namespaces -o=jsonpath='{range .items[*]}{.metadata.namespace}{"\n"}{end}'); do
    for cr in $(kubectl get dbclusters.alloydbomni.dbadmin.goog -n $ns -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'); do
    kubectl patch dbclusters.alloydbomni.dbadmin.goog $cr -n $ns --type=merge -p '{"spec":{"isDeleted":true}}'
    done
    done
  2. 等待 AlloyDB Omni Kubernetes 運算子刪除所有資料庫叢集。 使用下列指令檢查是否還有任何資料庫資源:

    kubectl get dbclusters.alloydbomni.dbadmin.goog --all-namespaces
  3. 刪除 AlloyDB Omni Kubernetes 運算子建立的其他資源:

    kubectl delete failovers.alloydbomni.dbadmin.goog --all --all-namespaces
    kubectl delete restores.alloydbomni.dbadmin.goog --all --all-namespaces
    kubectl delete switchovers.alloydbomni.dbadmin.goog --all --all-namespaces
  4. 解除安裝 AlloyDB Omni Kubernetes 運算子:

    helm uninstall alloydbomni-operator --namespace alloydb-omni-system
  5. 清除與 AlloyDB Omni Kubernetes 運算子相關的密鑰、自訂資源說明和命名空間:

    kubectl delete certificate -n alloydb-omni-system --all
    kubectl get secrets --all-namespaces -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,ANNOTATION:.metadata.annotations.cert-manager\.io/issuer-name | grep -E 'alloydbomni|dbs-al' | awk '{print $1 " " $2}' | xargs -n 2 kubectl delete secret -n
    kubectl delete crd -l alloydb-omni=true
    kubectl delete ns alloydb-omni-system

調整 Kubernetes 型資料庫叢集的大小

如要調整 Kubernetes 型資料庫叢集的 CPU、記憶體或儲存空間大小,請更新定義 Pod 的資訊清單 resources 欄位。AlloyDB Omni 運算子會立即將新規格套用至資料庫 Pod。

如要進一步瞭解 AlloyDB Omni 運算子資訊清單語法,請參閱「建立資料庫叢集」。

修改執行中資料庫叢集資源時,須遵守下列限制:

  • 只有在指定的 storageClass 支援擴充磁碟區時,您才能增加磁碟大小。
  • 無法縮減磁碟大小。