啟用 Cassandra 驗證

根據預設,Cassandra 安裝但不啟用驗證功能。這代表任何人都可以存取 Cassandra。您可以在安裝 Edge 後啟用驗證功能,或在安裝過程中啟用驗證功能。

您可以使用 Cassandra CREATE/ALTER/DROP USER 陳述式新增、移除及修改使用者。詳情請參閱 Cassandra SQL 殼層指令

在安裝期間啟用 Cassandra 驗證

您可以在安裝時啟用 Cassandra 驗證。

如要在安裝時啟用 Cassandra 驗證,請在所有 Cassandra 節點的設定檔中加入 CASS_AUTH 屬性:

CASS_AUTH=y # The default value is n.

下列 Edge 元件可存取 Cassandra:

  • 管理伺服器
  • 訊息處理器
  • 路由器
  • Qpid 伺服器
  • Postgres 伺服器

安裝這些元件時,必須在設定檔中設定使用者名稱和密碼:

CASS_USERNAME=cassandra_username
CASS_PASSWORD=cassandra_password

您可以在安裝 Cassandra 後變更 Cassandra 憑證。不過,如果您已經安裝管理伺服器、訊息處理器、路由器、Qpid 伺服器或 Postgres 伺服器,您也必須更新這些元件來使用新憑證。

如何在安裝 Cassandra 後變更 Cassandra 憑證:

  1. 使用 cqlsh 工具和預設憑證登入任一 Cassandra 節點。您只需在一個節點上變更密碼,系統就會對環狀中的所有 Cassandra 節點廣播:
    /opt/apigee/apigee-cassandra/bin/cqlsh cassIP 9042 -u cassandra_username -p cassandra_password

    在此情況下:

    1. cassIP 是 Cassandra 節點的 IP 位址。
    2. 9042 是預設的 Cassandra 通訊埠。
  2. cqlsh> 提示中執行下列指令,以更新密碼:
    ALTER USER cassandra_username/var> WITH PASSWORD 'new_cassandra_password';
  3. 結束 cqlsh 工具,如以下範例所示:
    exit
  4. 如果您尚未安裝管理伺服器、訊息處理器、路由器、Qpid 伺服器或 Postgres 伺服器,請在設定檔中設定下列屬性,然後安裝這些元件:
    CASS_USERNAME=cassandra_username
    CASS_PASSWORD=new_cassandra_password
  5. 如果您已安裝管理伺服器、訊息處理器、路由器、Qpid 伺服器或 Postgres 伺服器,請參閱「重設邊緣密碼」一文,瞭解更新這些元件來使用新密碼的程序。

啟用安裝後的 Cassandra 驗證

如要在安裝後啟用驗證功能:

更新連線至 Cassandra 的 Edge 元件

請按照下列程序,更新與 Cassandra 通訊的所有 Edge 元件使用新憑證。請注意,在您實際更新 Cassandra 憑證之前,請先執行此步驟:

  1. 在 Management Server 節點中,執行下列指令:
    /opt/apigee/apigee-service/bin/apigee-service edge-management-server
      store_cassandra_credentials -u cassandra_username -p cassandra_password

    您也可以選擇將檔案傳送至包含新使用者名稱和密碼的指令:

    apigee-service edge-management-server store_cassandra_credentials  -f configFile

    其中 configFile 包含下列內容:

    CASS_USERNAME=cassandra_username # Default is cassandra
    CASS_PASSWORD='cassandra_password' # Default is cassandra; wrap in single quotes if it includes special chars

    這個指令會自動重新啟動管理伺服器。

  2. 針對下列各項服務重複步驟 1:
    • 所有訊息處理器
    • 所有路由器
    • 所有 Qpid 伺服器 (edge-qpid-server)
    • Postgres 伺服器 (edge-postgres-server)

    針對每項服務重複步驟 1 時,請將上述指令中的 edge-management-server 替換為適當的服務名稱。舉例來說,當您執行路由器服務的步驟時,請使用下列指令:

    /opt/apigee/apigee-service/bin/apigee-service edge-router
      store_cassandra_credentials -u cassandra -p cassandra

啟用驗證功能

請按照下列程序啟用 Cassandra 驗證,並設定使用者名稱和密碼:

  1. 使用以下內容建立無訊息設定檔:
    # Specify IP address or DNS name of cassandra node
    IP1=192.168.1.1
    IP2=192.168.1.2
    IP3=192.168.1.3
    # Must resolve to IP address or DNS name of host
    HOSTIP=$(hostname -i)
    # Set to ‘y’ to enable Cassandra authentication.
    CASS_AUTH=y # Possible values are ‘y/n’
    # Cassandra username. If it does not exist, this user would be created as a SUPERUSER
    CASS_USERNAME=cassandra_username # Default value is cassandra - don't use for production
    # Cassandra Password. If CASS_USERNAME does not exist, create SUPERUSER with this as password
    CASS_PASSWORD=cassandra_password # Default value is cassandra - don't use for production
    # Space-separated IP/DNS names of the Cassandra hosts
    CASS_HOSTS="$IP1:1,1 $IP2:1,1 $IP3:1,1"
    
    # Username of an existing C* user. Only needed if you have disabled or changed details of the default cassandra user(‘cassandra’)
    CASS_EXISTING_USERNAME=existing_cassandra_username
    # Password of an existing C* user. Only needed if you have disabled or change password of the default cassandra user(‘cassandra’)
    CASS_EXISTING_PASSWORD=existing_cassandra_password
    # Cassandra port
    CASS_PORT=9042 # The default port is 9042.
  2. 登入第一個 Cassandra 節點,然後執行下列指令:

    apigee-service apigee-cassandra enable_cassandra_authentication -f CONFIG

    您也可以選擇將屬性做為指令引數傳遞至指令碼,如以下範例所示:

    CASS_AUTH=y HOSTIP=$(hostname -i) CASS_PORT=9042 CASS_EXISTING_USERNAME=existing_cassandra_username CASS_EXISTING_PASSWORD=existing_cassandra_password CASS_USERNAME=cassandra_username CASS_PASSWORD=cassandra_password  CASS_HOSTS="192.168.1.1:1,1 192.168.1.2:1,1 192.168.1.3:1,1" apigee-service apigee-cassandra enable_cassandra_authentication

    附註:

    • 如為預設 Cassandra 憑證,上述指令會啟用 Cassandra 驗證並重新啟動 Cassandra。
    • 如為非預設憑證,這個指令也會變更複製因子、建立超級使用者,並在 system_auth keyspace 上執行修復。
  3. 對所有 Cassandra 節點重複步驟 1 和 2。