在hadoop中为nameservice获取活动namenode的任何命令? [英] Any command to get active namenode for nameservice in hadoop?
问题描述
命令:
hdfs haadmin -getServiceState machine-98
仅当您知道机器名称时才有效.有没有类似的命令:
Works only if you know the machine name. Is there any command like:
hdfs haadmin -getServiceState <nameservice>
哪个可以告诉您活动名称节点的 IP/主机名?
which can tell you the IP/hostname of the active namenode?
推荐答案
要打印出名称节点,请使用以下命令:
To print out the namenodes use this command:
hdfs getconf -namenodes
要打印出辅助名称节点:
To print out the secondary namenodes:
hdfs getconf -secondaryNameNodes
打印备份名称节点:
hdfs getconf -backupNodes
注意:这些命令是使用 Hadoop 2.4.0 测试的.
Note: These commands were tested using Hadoop 2.4.0.
更新 10-31-2014:
Update 10-31-2014:
这是一个 python 脚本,它将从配置文件中读取 Hadoop HA 中涉及的 NameNode,并使用 hdfs haadmin 命令确定其中哪些是活动的.由于我没有配置 HA,所以这个脚本没有经过全面测试.仅使用基于 Hadoop HA 文档的示例文件测试了解析.随意使用和根据需要修改.
Here is a python script that will read the NameNodes involved in Hadoop HA from the config file and determine which of them is active by using the hdfs haadmin command. This script is not fully tested as I do not have HA configured. Only tested the parsing using a sample file based on the Hadoop HA Documentation. Feel free to use and modify as needed.
#!/usr/bin/env python
# coding: UTF-8
import xml.etree.ElementTree as ET
import subprocess as SP
if __name__ == "__main__":
hdfsSiteConfigFile = "/etc/hadoop/conf/hdfs-site.xml"
tree = ET.parse(hdfsSiteConfigFile)
root = tree.getroot()
hasHadoopHAElement = False
activeNameNode = None
for property in root:
if "dfs.ha.namenodes" in property.find("name").text:
hasHadoopHAElement = True
nameserviceId = property.find("name").text[len("dfs.ha.namenodes")+1:]
nameNodes = property.find("value").text.split(",")
for node in nameNodes:
#get the namenode machine address then check if it is active node
for n in root:
prefix = "dfs.namenode.rpc-address." + nameserviceId + "."
elementText = n.find("name").text
if prefix in elementText:
nodeAddress = n.find("value").text.split(":")[0]
args = ["hdfs haadmin -getServiceState " + node]
p = SP.Popen(args, shell=True, stdout=SP.PIPE, stderr=SP.PIPE)
for line in p.stdout.readlines():
if "active" in line.lower():
print "Active NameNode: " + node
break;
for err in p.stderr.readlines():
print "Error executing Hadoop HA command: ",err
break
if not hasHadoopHAElement:
print "Hadoop High-Availability configuration not found!"
这篇关于在hadoop中为nameservice获取活动namenode的任何命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!