查找群集节点的主机名Find the Host names of Cluster Nodes

HDInsight 群集是通过公共 DNS clustername.azurehdinsight.cn 创建的。HDInsight cluster is created with public DNS clustername.azurehdinsight.cn. 在同一自定义虚拟网络中通过 SSH 连接到单个节点或与群集节点建立连接时,需要使用主机名或群集节点的完全限定域名 (FQDN)。When you SSH to individual nodes or set connection to cluster nodes with in the same custom virtual network, you need to use host name, or fully qualified domain names (FQDN) of cluster nodes.

本文介绍如何获取群集节点的主机名。In this article, you learn how to get the host names of cluster nodes. 可以通过 Ambari Web UI 手动获取,也可以通过 Ambari REST API 自动获取。You can get it manually through Ambari Web UI or automatically through Ambari REST API.

警告

请使用以下建议方法获取群集节点的主机名。Please use the following recommended approaches to fetch host names of cluster nodes. 主机名中的数字不能保证按顺序排列,且 HDInsight 可能会更改主机名格式,以与具有版本刷新的 VM 保持一致。The numbers in the host name is not guaranteed in sequence and HDInsight may change the host name format to align with VMs with release refresh. 不要依赖于目前存在的任何特定命名约定。Don’t take the dependency on any certain naming convention that exists today.

可以通过 Ambari UI 或 Ambari REST API 获取主机名。You can get the host names through Ambari UI or Ambari REST API.

通过 Ambari Web UI 获取主机名Get the host names from Ambari Web UI

通过 SSH 连接到节点时,可以使用 Ambari Web UI 获取主机名。You can use Ambari Web UI to get the host names when you SSH to the node. 可在 HDInsight 群集上从 https://CLUSTERNAME.azurehdinsight.cn/#/main/hosts 获取 Ambari Web UI 主机视图,其中 CLUSTERNAME 是你的群集名称。The Ambari Web UI hosts view is available on your HDInsight cluster at https://CLUSTERNAME.azurehdinsight.cn/#/main/hosts, where CLUSTERNAME is the name of your cluster.

Get-Host-Names-In-Ambari-UI

通过 Ambari REST API 获取主机名Get the host names from Ambari REST API

生成自动化脚本时,可以使用 Ambari REST API 在与主机建立连接之前获取主机名。When building automation scripts, you can use the Ambari REST API to get the host names before you make connections to hosts. 主机名中的数字不能保证按顺序排列,且 HDInsight 可能会更改主机名格式,以与具有版本刷新的 VM 保持一致。The numbers in the host name are not guaranteed in sequence and HDInsight may change the host name format to align with VMs with release refresh. 不要依赖于目前存在的任何特定命名约定。Don’t take the dependency on any certain naming convention that exists today.

以下是有关如何检索群集中节点的 FQDN 的一些示例。Here are some examples of how to retrieve the FQDN for the nodes in the cluster. 有关 Ambari REST API 的详细信息,请参阅使用 Apache Ambari REST API 管理 HDInsight 群集For more information about Ambari REST API, see Manage HDInsight clusters by using the Apache Ambari REST API

以下示例使用 jqConvertFrom-Json 来分析 JSON 响应文档并仅显示主机名。The following example uses jq or ConvertFrom-Json to parse the JSON response document and display only the host names.

export password=''
export clusterName=''
curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/hosts" \
| jq -r '.items[].Hosts.host_name'
$clusterName=''
$creds = Get-Credential -UserName "admin" -Message "Enter the HDInsight login"
$resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/hosts" `
    -Credential $creds -UseBasicParsing
$respObj = ConvertFrom-Json $resp.Content
$respObj.items.Hosts.host_name