任何命令获得hadoop中nameservice的活动namenode? [英] Any command to get active namenode for nameservice in hadoop?

查看:2258
本文介绍了任何命令获得hadoop中nameservice的活动namenode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令:

  hdfs haadmin -getServiceState machine-98 

只有在知道机器名称的情况下才有效。是否有任何命令:

  hdfs haadmin -getServiceState< nameservice> 

可以告诉你活动 namenode的IP /主机名?

解决方案

使用以下命令可以打印出名称节点:

  hdfs getconf -namenodes 

打印辅助名称节点:

  hdfs getconf -secondaryNameNodes 

打印备份名称节点:

  hdfs getconf -backupNodes 



注意:这些命令已使用Hadoop 2.4.0进行了测试。



更新 10-31-2014:

以下是一个python脚本,它将从配置文件中读取Hadoop HA中涉及的NameNode,并确定它们中的哪些被活动使用hdfs haadmin命令。由于我没有配置高可用性,因此该脚本未完全测试。只使用基于Hadoop HA文档的示例文件来测试解析。随意使用和修改。

b $ b#编码:UTF-8
将xml.etree.ElementTree作为ET
导入子过程作为SP
if __name__ ==__main__:
hdfsSiteConfigFile =/ etc /hadoop/conf/hdfs-site.xml

tree = ET.parse(hdfsSiteConfigFile)$ b $ root root = tree.getroot()
hasHadoopHAElement = False
activeNameNode = None
为根中的属性:
如果property.find(name)中的dfs.ha.namenodes。text:
hasHadoopHAElement = True
nameserviceId = property。 find(name)。text [len(dfs.ha.namenodes)+ 1:]
nameNodes = property.find(value)。text.split(,)
对于nameNodes中的节点:$ b​​ $ b#获取namenode机器地址,然后检查它是否为活动节点
for root in:
prefix =dfs.namenode.rpc-address。 + nameserviceId +。
elementText = n.find(name)。text
if 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)

为p.stdout.readlines()中的行:
如果在line.lower()中为active:
printActive NameNode:+ node
break;
for p.stderr.readlines()中的错误:
print执行Hadoop HA命令时出错:,err
break
如果不是hasHadoopHAElement:
printHadoop找不到高可用性配置!


The command:

hdfs haadmin -getServiceState machine-98

Works only if you know the machine name. Is there any command like:

hdfs haadmin -getServiceState <nameservice>

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

To print out the backup namenodes:

hdfs getconf -backupNodes

Note: These commands were tested using Hadoop 2.4.0.

Update 10-31-2014:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆