你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

适用于 Azure Managed Instance for Apache Cassandra 的 DBA 命令

Azure Managed Instance for Apache Cassandra 是针对纯开源 Apache Cassandra 群集的完全托管服务。 该服务还允许重写配置,具体取决于每个工作负载的特定需求。 此功能可根据需要实现最大的灵活性和控制。 本文介绍了如何在需要时手动运行 DBA 命令。

重要

Nodetoolsstable 命令处于公共预览阶段。

此功能没有提供服务级别协议。 不建议对生产工作负荷使用此功能。 有关详细信息,请参阅 Microsoft Azure 预览版补充使用条款

DBA 命令支持

Azure 托管实例适用于 Apache Cassandra,允许使用 Azure CLI 运行 nodetoolsstable 命令,以进行例行的 DBA 管理工作。 并非所有命令都受支持,存在一些限制。 有关受支持的命令,请参阅以下部分。

警告

其中一些命令可能会破坏 Cassandra 群集的稳定性。 只有在非生产环境中进行测试后,才应仔细使用这些命令。 如果可能,请先部署选项 --dry-run 。 Microsoft 不对运行更改默认数据库配置和/或表的命令的问题提供任何服务水平协议 (SLA) 或支持。

如何运行 nodetool 命令

Azure Managed Instance for Apache Cassandra 提供以下 Azure CLI 命令来运行 DBA 命令:

az managed-cassandra cluster invoke-command --resource-group <rg> \
  --cluster-name <cluster> --host <ip of data node> --command-name nodetool \
  --arguments "<nodetool-subcommand>"="" "paramerter1"="" 

子命令需要位于 --arguments 节中,并且该节的值应为空。 不带值的 Nodetool 标记的格式为:"<flag>"=""。 如果标志具有值,则其格式为: "<flag>"="value"

下面的示例演示如何运行不带标记的 nodetool 命令,在本例中为 nodetool status 命令:

az managed-cassandra cluster invoke-command --resource-group <rg> --cluster-name <cluster> \
  --host <ip of data node> --command-name nodetool --arguments "status"="" 

下面的示例演示如何运行带标记的 nodetool 命令,在本例中为 nodetool compact 命令:

az managed-cassandra cluster invoke-command --resource-group <rg> --cluster-name <cluster> \
  --host <ip of data node> --command-name nodetool --arguments "compact"="" "-st"="65678794" 

两者都返回以下格式的 json:

{
    "commandErrorOutput": "",
    "commandOutput": "<result>",
    "exitCode": 0
}

在大多数情况下,只需使用 commandOutputexitCode. 下面是一个仅获取 commandOutput 的示例:

az managed-cassandra cluster invoke-command --query "commandOutput" --resource-group $resourceGroupName \
  --cluster-name $clusterName --host $host --command-name nodetool --arguments getstreamthroughput=""

如何运行 sstable 命令

sstable 令需要对 Cassandra 数据目录和要停止的 Cassandra 数据库进行读/写访问。 若要满足此要求,请指定以下两个参数: --cassandra-stop-start true--readwrite true

az managed-cassandra cluster invoke-command --resource-group <test-rg> \
  --cluster-name <test-cluster> --host <ip> --cassandra-stop-start true --readwrite true \
  --command-name sstableutil --arguments "system"="peers"
{
"commandErrorOutput": "",
"commandOutput": "Listing files...\n/var/lib/cassandra/data/system/peers-37f71aca7dc2383ba70672528af04d4f/me-1-big-CompressionInfo.db\n/var/lib/cassandra/data/system/peers-37f71aca7dc2383ba70672528af04d4f/me-1-big-Data.db\n/var/lib/cassandra/data/system/peers-37f71aca7dc2383ba70672528af04d4f/me-1-big-Digest.crc32\n/var/lib/cassandra/data/system/peers-37f71aca7dc2383ba70672528af04d4f/me-1-big-Filter.db\n/var/lib/cassandra/data/system/peers-37f71aca7dc2383ba70672528af04d4f/me-1-big-Index.db\n/var/lib/cassandra/data/system/peers-37f71aca7dc2383ba70672528af04d4f/me-1-big-Statistics.db\n/var/lib/cassandra/data/system/peers-37f71aca7dc2383ba70672528af04d4f/me-1-big-Summary.db\n/var/lib/cassandra/data/system/peers-37f71aca7dc2383ba70672528af04d4f/me-1-big-TOC.txt\n",
"exitCode": 0
}

如何运行其他命令

cassandra-reset-password 命令允许用户更改 Cassandra 用户的密码。

az managed-cassandra cluster invoke-command --resource-group <rg> --cluster-name <cluster> \
  --host <ip of data node> --command-name cassandra-reset-password --arguments password="<password>"

重要

密码在此命令中为 URL 编码(UTF-8),这意味着以下规则适用:

  • The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
  • The special characters ".", "-", "*", and "_" remain the same.
  • The space character " " is converted into a plus sign "+".
  • All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte.

cassandra-reset-auth-replication 命令允许用户更改 Cassandra 用户的架构。 按空间分隔数据中心名称。

az managed-cassandra cluster invoke-command --resource-group <rg> --cluster-name <cluster> \
  --host <ip of data node> --command-name cassandra-reset-auth-replication \
  --arguments password="<datacenters>"

重要

数据中心在传递到此命令时采用 URL 编码(UTF-8),这意味着以下规则适用:

  • The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same.
  • The special characters ".", "-", "*", and "_" remain the same.
  • The space character " " is converted into a plus sign "+".
  • All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. Then each byte is represented by the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the byte.

sstable-tree 命令允许用户查看其 sstable。

az managed-cassandra cluster invoke-command --resource-group <rg> --cluster-name <cluster> \
  --host <ip of data node> --command-name sstable-tree

sstable-delete 命令允许用户删除在特定时间之前制作的 sstables。

az managed-cassandra cluster invoke-command --resource-group <rg> --cluster-name <cluster> \
  --host <ip of data node> --command-name sstable-delete --arguments datetime="<YYYY-MM-DD hh:mm:ss>"

datetime参数的格式必须如示例中所示。 还可以添加 --dry-run="" 为参数以查看命令删除的文件。

支持的 sstable 命令的列表

有关每个命令的详细信息,请参阅 SSTable 工具

  • sstableverify
  • sstablescrub
  • sstablemetadata
  • sstablelevelreset
  • sstableutil
  • sstablesplit
  • sstablerepairedset
  • sstableofflinerelevel
  • sstableexpiredblockers

支持的 nodetool 命令的列表

有关每个命令的详细信息,请参阅 Use Nodetool

  • status
  • cleanup
  • clearsnapshot
  • compact
  • compactionhistory
  • compactionstats
  • describecluster
  • describering
  • disableautocompaction
  • disablehandoff
  • disablehintsfordc
  • drain
  • enableautocompaction
  • enablehandoff
  • enablehintsfordc
  • failuredetector
  • flush
  • garbagecollect
  • gcstats
  • getcompactionthreshold
  • getcompactionthroughput
  • getconcurrentcompactors
  • getendpoints
  • getinterdcstreamthroughput
  • getlogginglevels
  • getsstables
  • getstreamthroughput
  • gettimeout
  • gettraceprobability
  • gossipinfo
  • info
  • invalidatecountercache
  • invalidatekeycache
  • invalidaterowcache
  • listsnapshots
  • netstats
  • pausehandoff
  • proxyhistograms
  • rangekeysample
  • rebuild
  • rebuild_index - 针对参数使用 "keyspace"="table indexname..."
  • refresh
  • refreshsizeestimates
  • reloadlocalschema
  • replaybatchlog
  • resetlocalschema
  • resumehandoff
  • ring
  • scrub
  • setcachecapacity - 针对参数使用 "key-cache-capacity" = "<row-cache-capacity> <counter-cache-capacity>"
  • setcachekeystosave - 针对参数使用 "key-cache-keys-to-save":"<row-cache-keys-to-save> <counter-cache-keys-to-save>"
  • setcompactionthreshold - 针对参数使用 "<keyspace>"="<table> <minthreshold> <maxthreshold>
  • setcompactionthroughput
  • setconcurrentcompactors
  • sethintedhandoffthrottlekb
  • setinterdcstreamthroughput
  • setstreamthroughput
  • settimeout
  • settraceprobability
  • statusbackup
  • statusbinary
  • statusgossip
  • statushandoff
  • stop
  • tablehistograms
  • tablestats
  • toppartitions
  • tpstats
  • truncatehints
  • verify
  • version
  • viewbuildstatus

后续步骤