建立機構、環境和虛擬主機

您可以在指令列中,使用單一指令建立組織、環境和虛擬主機,也可以分別建立。此外,您也可以使用 Management API 執行許多這類動作。

影片: 觀看短片,概略瞭解 Apigee 組織的設定。

同時建立組織、環境和虛擬主機

在 Apigee Edge 建立 API Proxy 之前,您必須先建立至少一個組織,並在每個組織中建立一或多個環境和虛擬主機。

通常,組織和環境會一起建立。如要簡化程序,請使用 apigee-provision 公用程式。在 Edge 管理伺服器上,透過指令列叫用:

/opt/apigee/apigee-service/bin/apigee-service apigee-provision setup-org -f configFile

其中 configFile 是設定檔的路徑,類似下列內容:

# Set Edge sys admin credentials.
ADMIN_EMAIL=your@email.com
APIGEE_ADMINPW=admin_password  # If omitted, you are prompted for it.
NEW_USER="y"
USER_NAME=orgAdmin@myCo.com
FIRST_NAME=foo
LAST_NAME=bar
USER_PWD="userPword"
ORG_NAME=example  # lowercase only, no spaces, underscores, or periods.
ENV_NAME=prod  # lowercase only
VHOST_PORT=9001
VHOST_NAME=default
VHOST_ALIAS="$IP1:9001"
# Optionally configure TLS/SSL for virtual host.
# VHOST_SSL=y     # Set to "y" to enable TLS/SSL on the virtual host.
# KEYSTORE_JAR=   # JAR file containing the cert and private key.
# KEYSTORE_NAME=  # Name of the keystore.
# KEYSTORE_ALIAS= # The key alias.
# KEY_PASSWORD=   # The key password, if it has one.
# Optionally set the base URL displayed by the Edge UI for an
# API proxy deployed to the virtual host.
# VHOST_BASEURL="http://myCo.com"
# AXGROUP=axgroup-001 # Default value is axgroup-001

設定組織時,setup-org 指令碼會執行下列操作:

  • 建立組織。
  • 將組織與「閘道」Pod 建立關聯。這項設定無法變更。
  • 將指定使用者新增為組織管理員。如果使用者不存在,您可以建立一個。
  • 建立一或多個環境。
  • 為每個環境建立一或多個虛擬主機。
  • 將環境與所有訊息處理器建立關聯。
  • 啟用數據分析。

根據預設,使用 apigee-provision 公用程式時,組織名稱和環境名稱的長度上限為 20 個字元。如果您直接使用 Edge API 建立組織或環境,則不適用這項限制。組織名稱和環境名稱都必須使用小寫。

建立機構

使用 create-org 指令建立組織,如下例所示:

/opt/apigee/apigee-service/bin/apigee-service apigee-provision create-org -f configFile

這個指令碼會建立組織,但不會新增或設定組織處理 API 呼叫所需的環境和虛擬主機。

設定檔包含組織名稱和組織管理員的電子郵件地址。name 屬性中可使用的字元僅限 a-z0-9\-$%。名稱中請勿使用空格、句號或大寫字母:

APIGEE_ADMINPW=admin_password    # If omitted, you are prompted for it.
ORG_NAME=example  # lowercase only, no spaces, underscores, or periods.
ORG_ADMIN=orgAdmin@myCo.com

create-org 指令碼:

  • 建立組織。
  • 將組織與「閘道」Pod 建立關聯。
  • 將指定使用者新增為組織管理員。使用者必須已存在,否則指令碼會發生錯誤。

使用 API 呼叫建立組織

您可以使用下列 API 呼叫建立組織。第一個呼叫會建立組織:

curl -H "Content-Type:application/xml" -u sysAdminEmail:adminPasswd \
  -X POST http://management_server_IP:8080/v1/organizations \
  -d '<Organization name="org_name" type="paid"/>'

下一個呼叫會將組織與 Pod 建立關聯:

curl -H "Content-Type:application/x-www-form-urlencoded" \
  -u sysAdminEmail:adminPasswd -X POST \
  http://management_server_IP:8080/v1/organizations/org_name/pods \
  -d "region=default&pod=gateway"

最後一個呼叫會將現有使用者新增為機構組織管理員:

curl -H "Content-Type:application/xml" -u sysAdminEmail:adminPasswd \
  -X POST http://<ms-ip>:8080/v1/organizations/org_name/users/user_email/userroles/ \
  -d '<Roles><Role name="orgadmin"/></Roles>'

如果使用者不存在,您可以使用下列呼叫建立使用者,如「新增使用者」一節所述。

建立環境

使用 add-env 指令碼在現有組織中建立環境:

/opt/apigee/apigee-service/bin/apigee-service apigee-provision add-env -f configFile

這個設定檔包含建立環境和虛擬主機所需的資訊:

APIGEE_ADMINPW=admin_password  # If omitted, you are prompted for it.
ORG_NAME=example  # lowercase only, no spaces, underscores, or periods.
ENV_NAME=prod  # lowercase only
VHOST_PORT=9001
VHOST_NAME=default
VHOST_ALIAS="$IP1:9001"
# Optionally configure TLS/SSL for virtual host.
# VHOST_SSL=y     # Set to "y" to enable TLS/SSL on the virtual host.
# KEYSTORE_JAR=   # JAR file containing the cert and private key.
# KEYSTORE_NAME=  # Name of the keystore. 
# KEYSTORE_ALIAS= # The key alias.
# KEY_PASSWORD=   # The key password, if it has one. 
# Optionally set the base URL displayed by the Edge UI for an
# API proxy deployed to the virtual host.
# VHOST_BASEURL="http://myCo.com"
# AXGROUP=axgroup-001 # Default value is axgroup-001

add-env 指令:

  • 建立環境。
  • 為環境建立單一虛擬主機。
  • 將環境與 Pod 中的所有訊息處理器建立關聯,Pod 則與包含環境的組織相關聯。
  • 啟用數據分析

使用 API 呼叫建立環境

或者,您也可以使用下列 API 呼叫建立環境。第一次呼叫會建立環境:

curl -H "Content-Type:application/xml" -u sysAdminEmail:adminPasswd \
  -X POST http://management_server_IP:8080/v1/organizations/org_name/environments \
  -d '<Environment name="env_name"/>'

下一個呼叫會將環境與訊息處理器建立關聯。請為要與環境建立關聯的每個訊息處理器發出這項呼叫:

curl -H "Content-Type:application/x-www-form-urlencoded" \
  -u sysAdminEmail:adminPasswd -X POST \
  http://management_server_IP:8080/v1/organizations/org_name/environments/env_name/servers \
  -d "action=add&uuid=uuid"

其中 uuid 是訊息處理器的 UUID。您可以使用下列指令取得 UUID:

curl http://Message_Processor_IP:8082/v1/servers/self

其中 Message_Processor_IP 是訊息處理器的 IP 位址。

下一個 API 呼叫會為指定環境啟用 Analytics。這項指令會驗證所有資料中心 POD 中是否存在 Qpid 和 Postgres 伺服器。然後,它會為指定的組織和環境啟動 Analytics 新手上路。

這個設定檔包含:

ORG_NAME=orgName  # lowercase only, no spaces, underscores, or periods.
ENV_NAME=envName  # lowercase only

其中 sample.json 包含下列內容:

{
  "properties" : {
    "samplingAlgo" : "reservoir_sampler",
    "samplingTables" : "10=ten;1=one;",
    "aggregationinterval" : "300000",
    "samplingInterval" : "300000",
    "useSampling" : "100",
    "samplingThreshold" : "100000"
  },
  "servers" : {
    "postgres-server" : [ "1acff3a5-8a6a-4097-8d26-d0886853239c", "f93367f7-edc8-4d55-92c1-2fba61ccc4ab" ],  
    "qpid-server" : [ "d3c5acf0-f88a-478e-948d-6f3094f12e3b", "74f67bf2-86b2-44b7-a3d9-41ff117475dd"] 
  }
}

postgres-servers 屬性包含以半形逗號分隔的 Postgres UUID 清單,qpid-server 屬性則包含 Qpid UUID。如需取得這些 UUID,請使用下列指令。

如果是 Qpid,請執行下列指令:

curl -u sysAdminEmail:password http://management_server_IP/v1/servers?pod=central

這個指令的輸出內容是 JSON 物件。每個 Qpid 伺服器都會顯示以下格式的輸出內容:

"type" : [ "qpid-server" ],
"uUID" : "d3c5acf0-f88a-478e-948d-6f3094f12e3b"

如果是 Postgres,請執行下列指令:

curl -u sysAdminEmail:admin_password http://management_server_IP/v1/servers?pod=analytics

每個 Postgres 伺服器都會顯示以下格式的輸出內容:

"type" : [ "postgres-server" ],
"uUID" : "d3c5acf0-f88a-478e-948d-6f3094f12e3b"

建立虛擬主機

您可以在組織的現有環境中建立虛擬主機。一個環境通常支援多個虛擬主機。舉例來說,某個虛擬主機可能支援 HTTP 通訊協定,而同一環境中的另一個虛擬主機則支援加密的 HTTPS 通訊協定。

使用下列 API 呼叫建立其他虛擬主機,或為沒有虛擬主機的環境建立虛擬主機:

curl -H "Content-Type:application/xml" -u sysAdminEmail:adminPasswd \
  -X POST http://management_server_IP:8080/v1/organizations/org_name/environments/env_name/virtualhosts \
  -d '<VirtualHost name="default"> \
    <HostAliases> \
      <HostAlias>myorg-test.apigee.net</HostAlias> \
    </HostAliases> \
    <Interfaces/> \
    <Port>443</Port> \
  </VirtualHost>'

如需建立虛擬主機的完整說明,包括建立透過 HTTPS 使用 TLS/SSL 的安全虛擬主機,請參閱「為私有雲設定 API 的 TLS 存取權」。