Эта команда помогает вам добавить хост в кластер hdp через API REST ambari, добавляет службу менеджера узлов 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