Any command to get active namenode for nameservice in hadoop?

后端 未结 10 1443
情歌与酒
情歌与酒 2020-12-13 22:08

The command:

hdfs haadmin -getServiceState machine-98

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

h         


        
10条回答
  •  半阙折子戏
    2020-12-13 22:45

    You can do it in bash with hdfs cli calls, too. With the noted caveat that this takes a bit more time since it's a few calls to the API in succession, but this may be preferable to using a python script for some.

    This was tested with Hadoop 2.6.0

    get_active_nn(){
       ha_name=$1 #Needs the NameServiceID
       ha_ns_nodes=$(hdfs getconf -confKey dfs.ha.namenodes.${ha_name})
       active=""
       for node in $(echo ${ha_ns_nodes//,/ }); do
         state=$(hdfs haadmin -getServiceState $node)
         if [ "$state" == "active" ]; then
           active=$(hdfs getconf -confKey dfs.namenode.rpc-address.${ha_name}.${node})
           break
         fi
       done
       if [ -z "$active" ]; then
         >&2 echo "ERROR: no active namenode found for ${ha_name}"
         exit 1
       else
         echo $active
       fi
    }
    

提交回复
热议问题