如何将主机添加到ambari服务器群集中?

时间:2018-10-29 18:30:51

标签: curl hdfs hortonworks-data-platform ambari

我正在尝试使用以下curl命令添加主机。

curl --user admin:passwd -i -H "X-Requested-By: ambari" -X POST http://182.29.6.3:8080/api/v1/clusters/prod/hosts/ip-182-29-6-3.us-east-2.ec2.internal

但是,我陷入了糟糕的困境

  

HTTP / 1.1 400 Bad Request X-Frame-Options:DENY X-XSS-Protection:1;   模式=块Set-Cookie:   AMBARISESSIONID = d52ibb6a8b6q1tmqm2l21q85e; Path = /; HttpOnly过期:   星期四,1970年1月1日00:00:00 GMT用户:admin内容类型:文本/纯文本   内容长度:179服务器:码头(8.1.19.v20160209)

     

{“ status”:400,“ message”:“试图将未知主机添加到   簇。这些主机尚未在服务器上注册:   ip-182-29-6-3.us-east-2.ec2.internal”

1 个答案:

答案 0 :(得分:0)

此命令可帮助您通过ambari REST API将主机添加到hdp群集,添加YARN节点管理器服务,在节点上部署配置并启动服务。

#!/bin/bash
# variables
HOSTNAME=$(curl http://169.254.169.254/latest/meta-data/hostname)
hostname $HOSTNAME
USERNAME='username'
PASSWORD='password'
CLUSTER_NAME='mycluster'
AMBARI_HOST='ip-172-166-11-52.ap-south-1.compute.internal'
AMBARI_PORT='8080'

#start ambari agent if its not running on the host to be registered and wait for 30 seconds for the agent to become up and running
/etc/init.d/ambari-agent start
sleep 30

# add a host to the cluster
curl --user $USERNAME:$PASSWORD -i -H 'X-Requested-By: ambari' -X POST http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$CLUSTER_NAME/hosts/$HOSTNAME
sleep 30

#add node manager service to the node
curl --user $USERNAME:$PASSWORD -i -H 'X-Requested-By: ambari' -X POST http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$CLUSTER_NAME/hosts/$HOSTNAME/host_components/NODEMANAGER
sleep 30

#install node manager packages and deploy configs it is not already present in the node
curl -u $USERNAME:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"Install"},"Body":{"HostRoles":{"state":"INSTALLED"}}}' http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$CLUSTER_NAME/hosts/$HOSTNAME/host_components/NODEMANAGER
sleep 30

# start node manager service
curl -u $USERNAME:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"HostRoles": {"state": "STARTED"}}' http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$CLUSTER_NAME/hosts/$HOSTNAME/host_components/NODEMANAGER