建立叢集

選取文件版本:

建立資料庫叢集,即可開始使用 AlloyDB Omni。

限制

限制如下:

  • AlloyDB Omni 會在連接埠 5432 上執行。系統不支援設定自訂連接埠。

  • 建立叢集前,請確認所有資料庫參數設定都正確無誤。叢集建立完成後,您將無法修改任何資料庫參數。

事前準備

建立叢集前,請先完成下列步驟:

  • 安裝 AlloyDB Omni 自動調度管理工具

  • 安裝 AlloyDB Omni 元件

  • 設定傳輸層安全標準 (TLS) 憑證

  • 將外部磁碟區 (DataDisk) 掛接到協調器中佈建的所有資料庫節點上的 PG_DATA_DIR。

  • 如果您打算使用 alloydbctl 而非 Ansible,請確保所有 VM 都已安裝必要的 policycoreutils-python-utils 套件。如要安裝這個套件,請執行下列指令:

    sudo dnf install policycoreutils-python-utils
  • 如果您使用 Google Cloud 環境,請將 ENVIRONMENT_TYPE 設為 gcp。 然後,您必須以 root 使用者身分執行 gcloud auth login,驗證 gcloud CLI 帳戶。此外,通過驗證的帳戶必須具備下列權限:

    • compute.instances.get
    • compute.instances.list
    • compute.instances.updateNetworkInterface

準備叢集規格

如要建立叢集,AlloyDB Omni 必須知道如何設定叢集。如要建立必要規格,請使用 DBCluster 格式建立 YAML 檔案:

Secret:
  metadata:
    name: db-pw-DBCLUSTER_NAME
  spec:
    type: Opaque
    data:
      DBCLUSTER_NAME: BASE64_PASSWORD
---
DBCluster:
  metadata:
    name: DBCLUSTER_NAME
  spec:
    databaseVersion: 18.3.0
    mode: ""
    availability:
      numberOfStandbys: NUM_STANDBY_NODES
      enableAutoFailover: true
      enableAutoHeal: true
      autoFailoverTriggerThreshold: AUTOFAILOVER_TRIGGER_THRESHOLD
      autoHealTriggerThreshold: AUTOHEAL_TRIGGER_THRESHOLD
      healthcheckPeriodSeconds: HEALTHCHECK_PERIOD
      replayReplicationSlotsOnStandbys: false
    primarySpec:
      adminUser:
        passwordRef:
          name: db-pw-DBCLUSTER_NAME
      resources:
        cpu: CPU_LIMIT
        memory: MEMORY_LIMIT
        disks:
        - name: DataDisk
          path: PG_DATA_DIR
      parameters:
        max_connections: "MAX_CONNECTIONS"
        max_wal_size: "MAX_WAL_SIZE"
      dbLoadBalancerOptions:
        DB_LOAD_BALANCER_TYPE:
          loadBalancerIP: "VIRTUAL_IP"
          loadBalancerType: "internal"
          loadBalancerInterface: "VIRTUAL_IP_INTERFACE"

請替換下列變數:

  • DBCLUSTER_NAME:資料庫叢集的名稱。例如:my-dbcluster。

  • BASE64_PASSWORD: 用於 postgres 管理員使用者的 base64 編碼密碼。

  • NUM_STANDBY_NODES:叢集中的待命節點數量。例如:2。

  • (選用) AUTOFAILOVER_TRIGGER_THRESHOLD: 健康狀態檢查失敗次數上限 (一旦超出上限,即啟動容錯移轉)。預設值為 3。最小值為 0,但如果值設為 0,AlloyDB Omni 會使用預設值。

    如果健康狀態檢查失敗 AUTOFAILOVER_TRIGGER_THRESHOLD 次,或健康狀態檢查的累計時間達到 HEALTHCHECK_PERIOD * AUTOFAILOVER_TRIGGER_THRESHOLD 秒,就會發生自動容錯移轉。

  • (選用) AUTOHEAL_TRIGGER_THRESHOLD:健康狀態檢查可失敗的次數,達到此次數後就會啟動自動修復功能。預設值為 3。最小值為 0,但如果值設為 0,AlloyDB Omni 會使用預設值。

    如果健康狀態檢查失敗 AUTOHEAL_TRIGGER_THRESHOLD 次,或健康狀態檢查的累計時間達到 HEALTHCHECK_PERIOD * AUTOHEAL_TRIGGER_THRESHOLD 秒,就會自動復原。

  • (選用) HEALTHCHECK_PERIOD: 每次健康狀態檢查之間要等待的秒數。預設值為 30。最小值為 1。最大值為 86400 (一天)。

  • CPU_LIMIT:要分配給資料庫容器的 CPU 數量。例如:4。

  • MEMORY_LIMIT:要分配給資料庫容器的記憶體量。例如 32Gi、500Mi。

  • PG_DATA_DIR:主機路徑,資料庫資料會儲存在這個目錄中。

  • (選用) MAX_CONNECTIONS: PostgreSQL 資料庫的並行連線數上限。預設值為 50。支援的值最小值也是 50。詳情請參閱 PostgreSQL max_connections 參考資料。

  • (選用) MAX_WAL_SIZE: 自動檢查點期間,允許預先寫入記錄 (WAL) 成長的最大大小。預設值為 1GB。詳情請參閱 PostgreSQL max_wal_size 參考資料。

  • (選用) ENVIRONMENT_TYPE: 決定叢集設定的環境,可以是 onprem 或 gcp。

  • (選用) VIRTUAL_IP:負載平衡器使用的虛擬 IP 位址。如果您定義 dbLoadBalancerOptions,則必須提供這項資訊。詳情請參閱「管理高可用性」。

  • (選用) VIRTUAL_IP_INTERFACE: 設定 VIRTUAL_IP 的網路介面。 預設值為 eth0。

建立叢集

如要建立叢集,請選取與環境相符的分頁,然後按照指示操作。

Ansible

如要建立叢集,請完成下列操作說明:

  1. 為資料庫叢集規格建立劇本。

    - name: Create DBCluster
      hosts: localhost
      become: true
      vars:
        ansible_user: ANSIBLE_USER
        ansible_ssh_private_key_file: ANSIBLE_SSH_PRIVATE_KEY_FILE
      roles:
      - role: google.alloydbomni_orchestrator.bootstrap
    
    

    請替換下列變數:

    • ANSIBLE_USER:作業系統使用者,Ansible 會用這個使用者登入 AlloyDB Omni 節點。

    • ANSIBLE_SSH_PRIVATE_KEY_FILE: Ansible 用於透過 SSH 連線至 AlloyDB Omni 節點的私密金鑰。

  2. 執行應對手冊。

    ansible-playbook DBCLUSTER_PLAYBOOK -i "DEPLOYMENT_SPEC" \
          -e resource_spec="DBCLUSTER_SPECIFICATIONS"

    請替換下列變數:

    • DBCLUSTER_PLAYBOOK:為資料庫叢集建立的劇本路徑。

    • DEPLOYMENT_SPEC: 您在安裝 AlloyDB Omni 元件中建立的部署規格路徑。

    • DBCLUSTER_SPECIFICATIONS:叢集規格的路徑。

alloydbctl

如要建立叢集,請執行下列指令:

alloydbctl apply -d "DEPLOYMENT_SPEC" -r "DBCLUSTER_SPECIFICATIONS"

請替換下列變數:

  • DEPLOYMENT_SPEC: 您在安裝 AlloyDB Omni 元件中建立的部署規格路徑。

  • DBCLUSTER_SPECIFICATIONS:叢集規格的路徑。

刪除叢集

如要刪除叢集,請選取與環境相符的分頁標籤,然後按照指示操作。

Ansible

如要使用 Ansible 刪除叢集,請完成下列步驟:

  1. 建立名為「teardown.yaml」的應對手冊:

    - name: Tear down AlloyDB Omni cluster
      hosts: localhost
      become: true
      vars:
        ansible_user: ANSIBLE_USER
        ansible_ssh_private_key_file: ANSIBLE_SSH_PRIVATE_KEY_FILE
      roles:
      - role: google.alloydbomni_orchestrator.delete
    
  2. 使用 ansible-playbook 執行應對手冊。您必須將 DBCluster 指定為 resource_type,並將要刪除的叢集名稱指定為 resource_name。

    ansible-playbook -i "DEPLOYMENT_SPEC" teardown.yaml \
      -e `resource_type`=`DBCluster` -e `resource_name`="DBCLUSTER_NAME"

如果叢集狀態不一致 (例如節點無法連線),導致拆除程序失敗,您可以將 -e force=true 新增至指令,嘗試強制刪除叢集。這會指示協調器在拆除程序期間忽略錯誤,並盡可能移除資源。

  ansible-playbook -i "DEPLOYMENT_SPEC" teardown.yaml \
    -e resource_type=DBCluster -e resource_name="DBCLUSTER_NAME" -e force=true

alloydbctl

如要使用 alloydbctl 刪除叢集,請執行下列指令:

alloydbctl delete -d "DEPLOYMENT_SPEC" \
      --resource_type DBCluster --resource_name "DBCLUSTER_NAME"

請替換下列變數:

  • DEPLOYMENT_SPEC: 您在安裝 AlloyDB Omni 元件中建立的部署規格路徑。

  • DBCLUSTER_NAME:資料庫叢集的名稱。例如:my-dbcluster。

附錄:SELinux 政策規格

下表列出為各節點上執行的每個元件設定的 SELinux 政策規則和存取權限。這些政策定義了在 SELinux 強制執行模式下執行主機時,程序隔離、網路通訊端繫結和儲存空間存取權的強制界限。

AlloyDB Omni

來源網域 目標資源 / 類型 安全等級 授予的權限 安全理由和限制條件
init_t (systemd) postgresql_exec_t file getattr、open、read、execute 允許 systemd 服務管理員執行 PostgreSQL 二進位檔。
init_t postgresql_t process transition 強制將網域從 systemd 轉換為受限的 postgresql_t 網域。
postgresql_t postgresql_exec_t file entrypoint、execute、read、map 嚴格限制網域項目,僅限官方 PostgreSQL 可執行檔。
postgresql_t lib_t file/dir read、open、getattr、map 授權動態連結器存取共用資料庫程式庫。
postgresql_t postgresql_db_t dir open、read、write、create、rmdir、search、getattr、setattr、add_name、remove_name 管理資料目錄和表空間的完整儲存目錄生命週期。
postgresql_t postgresql_db_t file open、read、write、create、unlink、lock、append、getattr、setattr、map 授權堆積資料表、WAL 區段、目錄和索引的讀取/寫入作業。
postgresql_t postgresql_var_run_t dir/sock_file open,read,write,create,unlink,search,getattr 管理 /var/run/postgresql 中的執行階段 PID 檔案和 Unix 網域通訊端。
postgresql_t postgresql_port_t tcp_socket name_bind 將 TCP 網路繫結嚴格限制為指派的 PostgreSQL 通訊埠 (預設為 TCP 5432)。
alloydbomni_nm_t postgresql_exec_t file execute、execute_no_trans、getattr、open、read、map 授權 Node Manager 執行健康狀態探查和控制工具,例如 pg_isready 或 pg_ctl。
alloydbomni_nm_t postgresql_db_t dir/file open,read,write,create,unlink,relabelto,relabelfrom 授予 Node Manager 初始化目錄及套用 SELinux 標籤的權限。

AlloyDB Omni 監控

來源網域 目標資源 / 類型 安全等級 授予的權限 安全理由和限制條件
postgresql_t unreserved_port_t tcp_socket name_bind 授權繫結至高位未保留的通訊埠,以匯出 Prometheus 指標和健康狀態。
postgresql_t net_conf_t file open、read、getattr 具備 /etc/resolv.conf 的唯讀存取權,可進行 DNS 和主機名稱解析。
postgresql_t sysfs_t file/dir open、read、getattr、search 檢查主機指標,不必授予 Root 或管理員權限。

Keepalived

來源網域 目標資源 / 類型 安全等級 授予的權限 安全理由和限制條件
keepalived_t keepalived_script_exec_t file execute、execute_no_trans、getattr、open、read、map、setattr、ioctl 將 VIP 追蹤指令碼的執行作業限制在專用的受限指令碼環境中。
keepalived_t hostname_exec_t file execute、execute_no_trans、getattr、open、read、map 在容錯移轉期間,叫用標準系統 hostname 來驗證節點身分。
keepalived_t ifconfig_exec_t file execute、execute_no_trans、getattr、open、read、map 在實體網路介面上指派及釋放虛擬 IP。
keepalived_t systemd_systemctl_exec_t file execute、execute_no_trans、getattr、open、read、map 使用 systemctl 查詢服務依附元件狀態,不必修改服務設定。
keepalived_t system_dbusd_t unix_stream_socket connectto 連線至系統 DBus Daemon,接收程序間的通知。
keepalived_t system_dbusd_t/init_t dbus send_msg 將 DBus 狀態轉換事件廣播至 init_t systemd 網域。
keepalived_t haproxy_unit_file_t/systemd_unit_file_t service status 檢查 HAProxy 和相關服務的運作狀態。
keepalived_t haproxy_var_lib_t dir / file / sock_file open、read、write、search、getattr 部署時,檢查 /var/lib/haproxy 中共置的 HAProxy 統計資料通訊端。
keepalived_t keepalived_var_run_t dir/file open,read,write,create,unlink,search,getattr 在 /var/run/keepalived 中維護執行階段狀態和 PID 追蹤檔案。
alloydbomni_nm_t keepalived_t process signal、signull 讓 Node Manager 使用 POSIX 信號管理精靈生命週期。

HAProxy

來源網域 目標資源 / 類型 安全等級 授予的權限 安全理由和限制條件
haproxy_t postgresql_port_t tcp_socket name_bind、name_connect 監聽 5432 連接埠,並將資料庫連線轉送至後端資料庫節點。
haproxy_t unreserved_port_t tcp_socket name_bind、name_connect 接聽自訂負載平衡器通訊埠,並連線至上游讀取/寫入端點。
haproxy_t haproxy_conf_t file/dir open、read、search、getattr /etc/haproxy/haproxy.cfg 的唯讀設定存取權。
haproxy_t haproxy_var_lib_t dir / file / sock_file open,read,write,create,unlink,search,getattr 管理 /var/lib/haproxy 中的執行階段通訊端和統計資料表。
haproxy_t haproxy_var_run_t dir/file open,read,write,create,unlink,search,getattr 管理 /var/run/haproxy 中的 PID 和控制通訊端。
alloydbomni_nm_t haproxy_unit_file_t service start、stop、status、reload、enable、disable 授權 Node Manager 控制 HAProxy systemd 服務生命週期。
alloydbomni_nm_t haproxy_t process signal、signull 授權 Node Manager 在設定變更時傳送重新載入信號。

PgBouncer

來源網域 目標資源 / 類型 安全等級 授予的權限 安全理由和限制條件
init_t pgbouncer_exec_t file getattr、open、read、execute 允許 systemd 叫用 PgBouncer 可執行檔 (/usr/bin/pgbouncer)。
init_t pgbouncer_t process transition 自動將網域從 systemd 轉換為獨立的 pgbouncer_t。
pgbouncer_t pgbouncer_exec_t file entrypoint、execute、read、map 將可執行進入點限制為 /usr/bin/pgbouncer。
pgbouncer_t unreserved_port_t tcp_socket name_bind 監聽連入的用戶端資料庫連線,例如 TCP 通訊埠 6432。
pgbouncer_t node_t tcp_socket node_bind 將網路通訊端繫結至節點網路介面。
pgbouncer_t postgresql_port_t/unreserved_port_t tcp_socket name_connect 啟動與後端 AlloyDB Omni 資料庫執行個體的 TCP 連線。
pgbouncer_t self unix_stream_socket create,bind,listen,accept,read,write,connectto 透過 Unix 網域通訊端提供本機用戶端連線。
pgbouncer_t pgbouncer_conf_t file/dir open、read、getattr、search /etc/pgbouncer/pgbouncer.ini 和使用者驗證檔案的唯讀設定存取權。
pgbouncer_t pgbouncer_var_run_t/tmp_t dir/sock_file open,read,write,create,unlink,search,getattr 在 /var/run/pgbouncer 和 /tmp 中建立及管理執行階段通訊端檔案。
pgbouncer_t self netlink_route_socket create、bind、read、write、nlmsg_read、getattr 探索網路路徑,以解析資料庫和用戶端端點。
pgbouncer_t self udp_socket create,connect,read,write,getattr,setopt,getopt 執行 DNS 名稱解析。
pgbouncer_t init_t/kernel_t unix_dgram_socket sendto 將 sd_notify 心跳和就緒信號傳送至 systemd。
pgbouncer_t sysfs_t file/dir open、read、getattr、search 讀取 CPU 拓撲,以最佳化背景工作執行緒。

pgBackRest

來源網域 目標資源 / 類型 安全等級 授予的權限 安全理由和限制條件
postgresql_t/alloydbomni_nm_t pgbackrest_exec_t file execute、getattr、open、read、map 允許 Postgres 和節點管理員分別執行 /usr/bin/pgbackrest,進行 WAL 封存和備份。
postgresql_t/alloydbomni_nm_t pgbackrest_t process transition、signal、sigkill、signull 受控程序會轉換至受限的 pgbackrest_t 網域。
pgbackrest_t pgbackrest_exec_t file entrypoint,execute,execute_no_trans,read,map,getattr,open 限制 pgBackRest 二進位檔進入點。
pgbackrest_t postgresql_db_t dir / file / lnk_file open、read、write、create、unlink、lock、append、search、getattr、setattr、map 在實體備份和時間點復原 (PITR) 期間讀取/寫入資料庫檔案。
pgbackrest_t postgresql_t unix_stream_socket connectto 使用本機通訊端連線至正在執行的 PostgreSQL 引擎,觸發備份檢查點。
pgbackrest_t postgresql_var_run_t dir / sock_file / file open、read、write、search、getattr 存取 /var/run/postgresql 中的 PostgreSQL 連線通訊端。
pgbackrest_t http_port_t tcp_socket name_connect 嚴格輸出:輸出 TCP 連線嚴格限制為雲端物件儲存空間 (GCS/S3) 的 HTTPS (443)。禁止使用內送接聽器。
pgbackrest_t cert_t dir / file / lnk_file open、read、search、getattr、map 讀取系統信任存放區憑證 (/etc/pki/tls),驗證與物件儲存空間的 TLS 連線。
pgbackrest_t pgbackrest_conf_t file/dir open、read、getattr、search、map /etc/pgbackrest/pgbackrest.conf 的唯讀設定存取權。
pgbackrest_t pgbackrest_log_t file/dir open、read、write、create、unlink、append、lock、getattr、setattr 在「/var/log/pgbackrest」中管理稽核記錄。
pgbackrest_t pgbackrest_tmp_t dir / file / sock_file open、read、write、create、unlink、append、lock、getattr、setattr、relabelto、relabelfrom /tmp/pgbackrest 中專用的隔離臨時儲存空間和執行緒間通訊插座。
pgbackrest_t shadow_t / sysfs_t / sssd_var_lib_t file/dir dontaudit (已停用) 靜態捨棄並忽略無關的主機憑證探查,避免稽核記錄遭到汙染。

節點管理工具

來源網域 目標資源 / 類型 安全等級 授予的權限 安全理由和限制條件
init_t alloydbomni_nm_exec_t file getattr、open、read、execute 允許 systemd 啟動 Node Manager Daemon。
alloydbomni_nm_t self capability audit_write、chown、dac_override、dac_read_search、fowner、fsetid、setgid、setuid、net_admin 主機生命週期管理和磁碟區佈建作業需要嚴格受限的 Linux 功能。
alloydbomni_nm_t unreserved_port_t tcp_socket name_bind、name_connect 為叢集管理員提供 gRPC / HTTP API,並為 HAProxy 提供健康狀態檢查探測器。
alloydbomni_nm_t http_port_t tcp_socket name_connect 與雲端 API 或監控端點進行通訊。
alloydbomni_nm_t semanage_exec_t、setfiles_exec_t、setsebool_exec_t、load_policy_exec_t file execute、execute_no_trans、getattr、open、read、map 執行核心 SELinux 管理二進位檔,編譯及強制執行 CIL 政策。
alloydbomni_nm_t security_t security load_policy 將已編譯的 SELinux 政策模組直接載入 Linux 核心。
alloydbomni_nm_t semanage_store_t、selinux_config_t dir/file open,read,write,create,unlink,lock,getattr 維護 SELinux 持續性政策設定儲存空間。
alloydbomni_nm_t unlabeled_t (磁碟/掛接) filesystem / dir / file getattr、open、read、write、create、unlink、setattr、relabelto、relabelfrom 動態磁碟重新標記:探索新附加的原始磁碟,例如 /data1 或 /obs,並重新標記為 postgresql_db_t。
alloydbomni_nm_t rpm_exec_t file execute,execute_no_trans,getattr,open,read,ioctl,map 執行 RPM/DNF 套件管理員指令,自動安裝及更新軟體。
alloydbomni_nm_t rpm_var_cache_t、rpm_var_lib_t、rpm_log_t dir/file open,read,write,create,unlink,lock,getattr 在套件安裝期間管理 RPM 資料庫和快取檔案。
alloydbomni_nm_t systemd_unit_file_t、syslogd_unit_file_t、haproxy_unit_file_t、keepalived_unit_file_t service start、stop、status、reload、enable、disable 在所有代管資料庫和輔助元件中,協調 systemd 服務生命週期。
alloydbomni_nm_t system_dbusd_t、systemd_logind_t、systemd_hostnamed_t dbus/unix_stream_socket send_msg、connectto 透過系統 DBus 協調主機狀態、時間和系統記錄。

叢集管理員

來源網域 目標資源 / 類型 安全等級 授予的權限 安全理由和限制條件
init_t alloydbcontrol_exec_t file getattr、open、read、execute 允許 systemd 啟動 Cluster Manager 可執行檔。
alloydbcontrol_t alloydbcontrol_exec_t file entrypoint、execute、read、map、getattr、open 將控制層執行作業限制在授權的二進位檔。
alloydbcontrol_t unreserved_port_t tcp_socket name_bind、name_connect 繫結 API 端點,並連線至分散式共識儲存空間 (DCS / etcd) 和節點管理員。
alloydbcontrol_t node_t tcp_socket node_bind 將網路接聽程式繫結至網路介面。
alloydbcontrol_t alloydbcontrol_conf_t file/dir open、read、search、getattr /etc/alloydbomni/cluster_manager 的唯讀設定存取權。
alloydbcontrol_t net_conf_t、passwd_file_t、sssd_public_t、sssd_var_lib_t file/dir open、read、search、getattr 管理介面的主機解析和使用者驗證。
alloydbcontrol_t cgroup_t、sysctl_net_t、sysfs_t file/dir open、read、search、getattr Go 執行階段效能最佳化和遙測的唯讀存取權。
alloydbcontrol_t init_t unix_stream_socket dontaudit (ioctl) 抑制非重要的 systemd 檔案描述元 ioctl 警告。