Azure CLI를 사용하여 자동 크기 조정이 있는 API for Cassandra 계정, 키스페이스 및 테이블 만들기

적용 대상: Cassandra

이 문서의 스크립트는 자동 크기 조정을 사용하여 Apache Cassandra 계정, 키스페이스 및 테이블용 Azure Cosmos DB를 만듭니다.

필수 조건

  • Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

  • 이 스크립트에는 Azure CLI 버전 2.12.1 이상이 필요합니다.

    • Azure Cloud Shell의 Bash 환경에서 스크립트를 실행할 수 있습니다. Cloud Shell이 열리면 셸 창의 왼쪽 상단에 있는 환경 필드에서 Bash를 선택해야 합니다. Cloud Shell에는 최신 버전의 Azure CLI가 있습니다.

    • 원하는 경우 Azure CLI를 설치하여 스크립트를 로컬에서 실행할 수 있습니다. az version을 실행하여 Azure CLI 버전을 찾고 업그레이드가 필요한 경우 az upgrade를 실행합니다. az login을 실행하여 Azure에 로그인합니다.

샘플 스크립트

이 스크립트는 다음 명령을 사용합니다.

  • az group create는 모든 리소스를 저장할 리소스 그룹을 만듭니다.
  • --capabilities EnableCassandra 매개 변수가 있는 az cosmosdb create는 API for Cassandra 지원 Azure Cosmos DB 계정을 만듭니다.
  • az cosmosdb cassandra keyspace create는 Azure Cosmos DB Cassandra 키스페이스를 만듭니다.
  • 최소 4000으로 설정된 --max-throughput 매개 변수를 사용하여 az cosmosdb cassandra table create는 자동 크기 조정이 있는 Azure Cosmos DB Cassandra 테이블을 만듭니다.
# Create a Cassandra keyspace and table with autoscale

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="autoscale-casandra-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
keySpace="keyspace1-$randomIdentifier"
table="table1-$randomIdentifier"
maxThroughput=1000 #minimum = 1000

# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag

# Create a Cosmos account for Cassandra API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableCassandra --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False 

# Create a Cassandra Keyspace
echo "Create $keySpace"
az cosmosdb cassandra keyspace create --account-name $account --resource-group $resourceGroup --name $keySpace

# Define the schema for the table
schema=$(cat << EOF 
{
    "columns": [
        {"name": "columna","type": "uuid"},
        {"name": "columnb","type": "int"},
        {"name": "columnc","type": "text"}
    ],
    "partitionKeys": [
        {"name": "columna"}
    ],
    "clusterKeys": [
        { "name": "columnb", "orderBy": "asc" }
    ]
}
EOF
)
# Persist schema to json file
echo "$schema" > "schema-$randomIdentifier.json"

# Create the Cassandra table
echo "Creating $table"
az cosmosdb cassandra table create --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --max-throughput $maxThroughput --schema @schema-$randomIdentifier.json

# Clean up temporary schema file
rm -f "schema-$randomIdentifier.json"

리소스 삭제

만든 리소스가 필요하지 않은 경우 az group delete 명령을 사용하여 Azure Cosmos DB 계정 및 키스페이스를 포함하여 리소스 그룹과 여기에 포함된 모든 리소스를 삭제합니다.

az group delete --name $resourceGroup

다음 단계

Azure Cosmos DB CLI 설명서