簡體   English   中英

在Powershell中使用Azure CLI創建CosmosDB

[英]Creating CosmosDB with Azure CLI in powershell

我正在嘗試創建新的cosmosdb,但是在執行以下代碼時卻收到以下錯誤。

az cosmosdb create --name TIC_Test
                    --resource-group "TIC" 
                    --default-consistency-level  Session  
                    --locations "Central US"=0 "Central US"=0 
                    --max-interval 5  --max-staleness-prefix 100  
                    --enable-automatic-failover false  
                    --enable-virtual-network false  
                    --kind GlobalDocumentDB

錯誤:

az : usage: az cosmosdb create [-h] [--verbose] [--debug]
At line:2 char:1
+ az cosmosdb create --name TIC_Test --resource-group "TIC"  --default- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (usage: az cosmo...bose] [--debug]:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

                          [--output {json,jsonc,table,tsv}] [--query JMESPATH]
                          --resource-group RESOURCE_GROUP_NAME --name
                          ACCOUNT_NAME [--locations LOCATIONS [LOCATIONS ...]]
                          [--tags [TAGS [TAGS ...]]]
                          [--kind {GlobalDocumentDB,MongoDB,Parse}]
                          [--default-consistency-level {Eventual,Session,BoundedStaleness,Strong,ConsistentPrefix}]
                          [--max-staleness-prefix MAX_STALENESS_PREFIX]
                          [--max-interval MAX_INTERVAL]
                          [--ip-range-filter IP_RANGE_FILTER [IP_RANGE_FILTER ...]]
                          [--enable-automatic-failover [{true,false}]]
                          [--capabilities CAPABILITIES [CAPABILITIES ...]]
                          [--enable-virtual-network [{true,false}]]
                          [--virtual-network-rules VIRTUAL_NETWORK_RULES [VIRTUAL_NETWORK_RULES ...]]
                          [--subscription _SUBSCRIPTION]
az cosmosdb create: error: list index out of range

知道可能是錯誤原因的原因嗎?

我懷疑這行,但不確定如何指定:

 --locations "Central US"=0 "Central US"=0 

是的,-- --locations似乎是問題所在。 根據文檔

以“ regionName = failoverPriority”格式分隔的位置。 例如eastus = 0 westus = 1。 對於寫入區域,故障轉移優先級值為0,對於讀取區域,故障轉移優先級值大於0。 故障轉移優先級值必須唯一且小於區域總數。 默認值:指定資源組所在位置的單個區域帳戶。

因此,例如,這適用於將CentralUS配置為讀/寫區域,並將EastUS配置為讀區域:

--locations "CentralUS=0" "EastUS=1"

--locations選項允許您指定故障轉移優先級。

在下面找到一個示例,該示例創建一個新的CosmosDB / SQL帳戶,其中East US是主要帳戶(讀寫)West US是次要帳戶(只讀)

az cosmosdb create --name "cosmosdb5555" --kind GlobalDocumentDB --resource-group "cosmosdbrg" --locations "eastus=0", "westus=1"

您正在觀察錯誤,因為指定的--locations由於區域和語法重復而無效。

如果在--locations中指定重復的區域,將引發以下錯誤:

Operation failed with status: 'BadRequest'. Details: Failover priorities must be unique and 0 <= priority < (number of failover policies)
ActivityId: 689752f6-8081-11e8-8a4b-9cb6d00f36f2, Microsoft.Azure.Documents.Common/2.0.0.0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM