Edge for Private Cloud 4.17.01 版
您可以使用主動/主動設定,在多個資料中心安裝 API BaaS。本文說明如何將 BaaS 資料中心新增至現有的 BaaS 資料中心。
Cassandra 叢集與 Edge 共用時新增資料中心
所有資料中心的 Cassandra 節點數量必須相同。API BaaS 安裝作業可以使用自己的 Cassandra 叢集,也可以與 Edge 共用 Cassandra 叢集。
如果 BaaS 安裝作業與 Edge 共用 Cassandra 叢集,您必須更新原始資料中心內的管理伺服器,將其設定為辨識新資料中心內的 Cassandra 節點。
更新現有資料中心
如要新增 BaaS 資料中心 (資料中心 2),您必須執行安裝及設定新資料中心的步驟,但也必須更新原始 BaaS 資料中心 (資料中心 1)。這些修改是必要的,因為:
- 您要在新的資料中心新增 Cassandra 節點,且現有資料中心必須能存取這些節點。
- 您必須設定資料中心 1 中 BaaS Stack 節點使用的複製資訊,納入資料中心 2 的資訊。必須先安裝資料中心 2,才能執行這項設定。
如要在資料中心 1 執行這些更新,請更新用於安裝資料中心 1 的原始設定檔,然後在資料中心 1 的 Cassandra 節點上重新執行 apigee-setup。如果資料中心 1 的 Cassandra 叢集與 Edge 安裝共用,您也必須更新管理伺服器。
建立設定檔
如要安裝資料中心 1,請使用「API BaaS 安裝」中顯示的設定。安裝資料中心 1 時,設定檔不需要包含資料中心 2 的任何資訊。安裝資料中心 2 後,您可以在設定檔中新增資訊。
以下是資料中心 2 的設定檔。這個設定檔假設您要在 10 個節點上安裝 dc-2,如「安裝拓撲」所述。如果您要在 7 個節點上安裝,請據此修改這個檔案。
請注意,資料中心 2 (dc-2) 的設定檔包含資料中心 1 (dc-1) 的相關資訊:
# Specify IP address or DNS name of node for dc-2. IP1=192.168.1.1 # ElasticSearch IP2=192.168.1.2 # ElasticSearch IP3=192.168.1.3 # ElasticSearch IP4=192.168.1.4 # API BaaS Stack IP5=192.168.1.5 # API BaaS Stack IP6=192.168.1.6 # API BaaS Stack IP7=192.168.1.7 # API BaaS Portal IP8=192.168.1.8 # Cassandra dc-2 (shared with Edge or standalone) IP9=192.168.1.9 # Cassandra dc-2 (shared with Edge or standalone) IP10=192.168.1.10 # Cassandra dc-2 (shared with Edge or standalone) # Specify node information for dc-1 IP11=192.168.1.11 # Cassandra dc-1 (shared with Edge or standalone) IP12=192.168.1.12 # Cassandra dc-1 (shared with Edge or standalone) IP13=192.168.1.13 # Cassandra dc-1 (shared with Edge or standalone) IP14=192.168.1.14 # API BaaS Stack IP15=192.168.1.15 # API BaaS Stack # Must resolve to IP address or DNS name of host - not to 127.0.0.1 or localhost. HOSTIP=$(hostname -i) # Define the API BaaS administrator account. AS_ADMIN="superuser" # User name - default is "superuser". AS_ADMIN_EMAIL=stackAdmin@email.com AS_PASSWD=stackAdminPWord # Specify Cassandra data center and rack suffix. # List dc-2 nodes first, then dc-1. # Must use IP addresses for CASS_HOSTS, not DNS names. # CASS_HOSTS="$IP8:2,1 $IP9:2,1 $IP10:2,1 $IP11:1,1 $IP12:1,1 $IP13:1,1" # Specify the Cassandra region. REGION=dc-2 # Cassandra uname/pword. # Even if Cassandra authentication is disabled, # you must still pass values for these properties. CASS_USERNAME=cassandra # Default value CASS_PASSWORD=cassandra # Default value # Specify BaaS Cassandra connection information. # Specify the data center name as dc-2. BAAS_CASS_LOCALDC=dc-2 # Specify both data centers. BAAS_CASS_DC_LIST=dc-1,dc-2 # Replication is in the form "dataCenterName:#CassandraNodes". # Specify both data centers. BAAS_CASS_REPLICATION=dc-1:3,dc-2:3 # Defines the initial contact points for members of the BaaS cluster. # Specify the IP address of no more than two Stack nodes per data center. # Specify both data centers. BAAS_CLUSTER_SEEDS="dc-1:$IP14,dc-1:$IP15,dc-2:$IP4,dc-2:$IP5" # ElasticSearch IPs or DNS names, separated by spaces, for dc-2. ES_HOSTS="$IP1 $IP2 $IP3" # API BaaS Stack information. # Default cluster name is "apigee_baas" BAAS_USERGRID_CLUSTERNAME="apigee_baas" # URL and port of the load balancer for the API BaaS Stack nodes, # or IP/DNS and port 8080 of a single Stack node with no load balancer. BAAS_USERGRID_URL=http://myloadbalancer:8443 # API BaaS Portal information. # URL and port number of load balancer, if there is one in front of the Portal, # or the URL and port of the Portal node. BAAS_PORTAL_URL="http://$IP7:9000" # Portal port. Default value is 9000. BAAS_PORTAL_LISTEN_PORT=9000 # SMTP information. BaaS requires an SMTP server. SMTPHOST=smtp.gmail.com SMTPPORT=465 SMTPUSER=your@email.com SMTPPASSWORD=yourEmailPassword SMTPSSL=y
新增 BaaS 資料中心
- 按照「API BaaS 安裝」一文中的說明安裝第一個資料中心。該文件包含用於安裝資料中心 1 的設定檔。
- 按照上述步驟,為 dc-2 建立設定檔。
- 安裝 Cassandra,可以做為現有 Edge 安裝作業的一部分,也可以做為 BaaS 的獨立叢集:
- 使用網際網路或非網際網路程序,在 dc-2 的第一個 Cassandra 節點 (機器 8) 上安裝 Edge apigee-setup 公用程式。詳情請參閱「安裝 Edge apigee-setup 公用程式」。
- 在命令提示字元中,執行設定指令碼,在第一個節點上安裝 Cassandra:
> /opt/apigee/apigee-setup/bin/setup.sh -p c -f configFile
「-p c」選項指定安裝 Cassandra。
設定檔必須可供「apigee」使用者存取或讀取。 - 針對 dc-2 中其餘的 Cassandra 節點 (機器 9 和 10),重複步驟 3 和 4。
- 在 dc-1 的 Cassandra 節點上,編輯設定檔,根據 Cassandra 的安裝方式,新增資料中心 2 的 Cassandra 節點:
# List dc-1 nodes first, then dc-2,
# including Cassandra data center and rack suffix
CASS_HOSTS="$IP11:1,1 $IP12:1,1 $IP13:1,1 $IP8:2,1 $IP9:2,1 $IP10:2,1" - 在 dc-1 的第一個 Cassandra 節點上,使用包含 dc-2 Cassandra 節點的新 dc-1 設定檔執行 setup.sh:
> /opt/apigee/apigee-setup/bin/setup.sh -p c -f configFile - 針對 dc-1 中其餘的 Cassandra 節點,重複步驟 6 和 7。
- 如果您要連線至與 Edge 共用的 dc-1 Cassandra 叢集,請將 dc-2 Cassandra 節點新增至 dc-1 管理伺服器節點的設定檔,然後執行 setup.sh:
> /opt/apigee/apigee-setup/bin/setup.sh -p ms -f configFile - 使用兩個資料中心的正確複製係數,更新 Cassandra 鍵空間。您只需在任一資料中心的任何 Cassandra 伺服器上執行這個步驟一次:
注意:下列指令都會將複製係數設為「3」,表示叢集中有三個 Cassandra 節點。請視安裝需求修改這個值。- 啟動 Cassandra cqlsh 公用程式:
> /opt/apigee/apigee-cassandra/bin/cqlsh cassandraIP - 在「cqlsh>」提示執行下列 CQL 指令,設定 Cassandra 鍵空間的複製層級:
- cqlsh> ALTER KEYSPACE "Apigee_Baas_dc_1" WITH replication = { 'class': 'NetworkTopologyStrategy', 'dc-1': '3','dc-2': '3' };
- cqlsh> ALTER KEYSPACE "Apigee_Baas" WITH replication = { 'class': 'NetworkTopologyStrategy', 'dc-1': '3','dc-2': '3' };
- cqlsh> ALTER KEYSPACE "Apigee_Baas_Locks" WITH replication = { 'class': 'NetworkTopologyStrategy', 'dc-1': '3','dc-2': '3' };
- cqlsh> ALTER KEYSPACE "system_traces" WITH replication = { 'class': 'NetworkTopologyStrategy', 'dc-1': '3','dc-2': '3' };
- cqlsh> ALTER KEYSPACE "system_auth" WITH replication = { 'class': 'NetworkTopologyStrategy', 'dc-1': '3','dc-2': '3' };
- 使用下列指令查看 keyspace:
cqlsh> select * from system.schema_keyspaces; - 結束 cqlsh:
cqlsh> exit
- 啟動 Cassandra cqlsh 公用程式:
- 在 dc-2 的所有 Cassandra 節點上,執行 rebuild 指令,並指定 dc-1 的區域名稱:
> /opt/apigee/apigee-cassandra/bin/nodetool -h cassandraIP rebuild dc-1 - 在每個 Cassandra 節點上執行「nodetool status」,並確認所有 Cassandra 節點的「Owns」值均為「100%」:
> /opt/apigee/apigee-cassandra/bin/nodetool status - 在 dc-2 中安裝 BaaS:
- 編輯設定檔,僅列出 dc-2 資料中心中的 Cassandra 節點:
# List dc-2 Cassandra nodes,
# omitting Cassandra data center and rack suffix
CASS_HOSTS="$IP8 $IP9 $IP10" - 在 dc-2 的節點 4、5 和 6 上安裝 ElasticSearch:
> /opt/apigee/apigee-setup/bin/setup.sh -p e -f configFile - 在 dc-2 的節點 4、5 和 6 上安裝 BaaS 堆疊:
> /opt/apigee/apigee-setup/bin/setup.sh -p b -f configFile - 在機器 7 上安裝 BaaS 入口網站:
> /opt/apigee/apigee-setup/bin/setup.sh -p p -f configFile
- 編輯設定檔,僅列出 dc-2 資料中心中的 Cassandra 節點:
- 更新資料中心 1 中的 BaaS 堆疊節點:
- 在資料中心 1 的第一個 BaaS Stack 節點上,使用編輯器編輯 /opt/apigee/customer/application/usergrid.properties。如果檔案不存在,請建立檔案。
- 在 usergrid.properties 中新增下列屬性:
# Same value as BAAS_CLUSTER_SEEDS in the dc-2 設定檔,
# without double quotes.
usergrid-deployment_usergrid.cluster.seeds=dc-1:dc1StackIP1,dc-1:dc1StackIP2,dc-2:dc2StackIP1,dc-2:dc2StackIP2
# Same value as BAAS_CASS_DC_LIST in the dc-2 config file.
usergrid-deployment_usergrid.cluster.region.list=dc-1,dc-2 - 在其餘 BaaS Stack 節點上重複步驟 a 和 b。
- 重新啟動所有 BaaS Stack 節點。
注意:重新啟動 BaaS Stack 節點時,請按照 BAAS_CLUSTER_SEEDS 中列出的順序重新啟動。 BAAS_CLUSTER_SEEDS 最多會列出兩個 Stack 節點。依序重新啟動這兩個節點後,即可按照任何順序重新啟動其餘節點。
> /opt/apigee/apigee-service/bin/apigee-service baas-usergrid restart
- 更新 BaaS 鍵空間值。這些 keyspace 必須在安裝時設定為複製,但不必在執行階段設定。移除複製功能也能節省 Cassandra 記憶體。
您只需要在任一資料中心的任何 Cassandra 伺服器上執行這個步驟一次:- 啟動 Cassandra cqlsh 公用程式:
> /opt/apigee/apigee-cassandra/bin/cqlsh cassandraIP - 執行下列 CQL 指令,設定 Cassandra 鍵空間的複製層級:
- cqlsh> ALTER KEYSPACE "Apigee_Baas_dc_1" WITH replication = { 'class': 'NetworkTopologyStrategy', 'dc-1': '3' };
- cqlsh> ALTER KEYSPACE "Apigee_Baas_dc_2" WITH replication = { 'class': 'NetworkTopologyStrategy', 'dc-2': '3' };
- 使用下列指令查看鍵空間:
cqlsh> select * from system.schema_keyspaces; - 結束 cqlsh:
cqlsh> exit
- 啟動 Cassandra cqlsh 公用程式:
第二個資料中心現已安裝完成。
完成兩個資料中心的安裝和設定後,您可以按照下列程序驗證安裝:
- 在所有 BaaS Stack 節點上,檢查狀態:
> curl 0:8080/status - 檢查權杖 API 呼叫是否正常運作:
> curl -X POST "http://localhost:8080/management/token" -d '{"grant_type":"password", "username":"adminEmail","password":"pWord"}' - 嘗試登入 dc-2 的 BaaS 入口網站。確認所有資料都已複製到 dc-2,例如在 dc-1 建立的集合。