我可以访问Cloudera manager rest API。
curl -u username:password http://cmhost:port/api/v10/clusters/clusterName
如何找到活动的 namenode 和资源mangarer主机名?
我无法从API文档中找到任何相关信息。
http://cloudera.github.io/cm_api/apidocs/v10/index.html
注意:群集配置了高可用性
答案 0 :(得分:2)
您需要使用此端点:
然后执行以下操作:
For each Name Node:
$ curl -u username:password \
http://cmhost:port/api/v10/clusters/CLNAME/services/HDFS/roles/NN_NAME
更换:
clusterName
serviceName
name
这将返回apiRole对象,该对象具有名为haStatus
的字段。显示" ACTIVE"是活动的NameNode。
对于资源管理器,执行类似的步骤:
For each Resource Manager:
$ curl -u username:password \
http://cmhost:port/api/v10/clusters/CLNAME/services/YARN/roles/RM_NAME
其中:
serviceName
name
获得正确的NameNode和资源管理器后,请使用:
http://cloudera.github.io/cm_api/apidocs/v10/path__hosts_-hostId-.html
将hostId
映射到主机名。
答案 1 :(得分:0)
通过使用REST API,您可以获得有关主机的大量与HDFS相关的信息:
$ python build.py username:password cmhost:port
$ cat build.py
import sys
import json
import requests
args = sys.argv
if len(args) != 3:
print "Usage: python %s login:password host:port" % args[0]
exit(1)
LP = args[1]
CM = args[2]
host = {}
hosts = requests.get('http://'+LP+'@'+CM+'/api/v10/hosts').json()
for h in hosts['items']:
host[h['hostId']] = h['hostname']
nameservices = requests.get('http://'+LP+'@'+CM+'/api/v10/clusters/cluster/services/hdfs/nameservices').json()
for ns in nameservices['items']:
print('hdfs.NS:' + ns['name'])
services = requests.get('http://'+LP+'@'+CM+'/api/v10/clusters/cluster/services').json()
for s in services['items']:
if (s['name'] == 'hdfs'):
roles = requests.get('http://'+LP+'@'+CM+'/api/v10/clusters/cluster/services/' + s['name'] + '/roles').json()
srv = {}
for r in roles['items']:
suff = '.' + r.get('haStatus') if r.get('haStatus') else ''
key = s['name'] + '.' + r['type'] + suff
srv[key] = srv.get(key) + ',' + host[r['hostRef']['hostId']] if srv.get(key) else host[r['hostRef']['hostId']]
for s in srv:
print(s + ":" + ','.join(sorted(srv[s].split(','))))
然后您将得到类似的内容,只需为hdfs.NAMENODE.ACTIVE
使用grep(或稍微更改python脚本)即可:
hdfs.NS:H1
hdfs.NAMENODE.ACTIVE:h6
hdfs.NAMENODE.STANDBY:h1
hdfs.FAILOVERCONTROLLER:h1,h2,h3
hdfs.DATANODE:h1
hdfs.HTTPFS:h1,h2,h3
hdfs.GATEWAY:h1,h2,h3
hdfs.JOURNALNODE:h4,h5
hdfs.BALANCER:h7