Skip to content

Instantly share code, notes, and snippets.

@Raboo
Created October 12, 2016 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raboo/1e63a126ce73144dc7ac4f426ee3cb52 to your computer and use it in GitHub Desktop.
Save Raboo/1e63a126ce73144dc7ac4f426ee3cb52 to your computer and use it in GitHub Desktop.
#!/bin/bash
AMBARI_USER='admin'
AMBARI_PASSWORD='PWPWPW'
AMBARI_HOST='ambari.local'
CLUSTER_NAME='hdp'
MOVE_FROM='node1.local'
MOVE_TO='node2.local'
SSH_USER=john.doe
# Tell to ambari we want to install this component on new_host
curl -u $AMBARI_USER:$AMBARI_PASSWORD -H "X-Requested-By:ambari" -i -X POST http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/hosts/$MOVE_TO/host_components/HISTORYSERVER
# Trigger installation
curl -u $AMBARI_USER:$AMBARI_PASSWORD -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo": {"context": "Install History Server","query":"HostRoles/component_name.in('HISTORYSERVER')"}, "Body":{"HostRoles": {"state": "INSTALLED"}}}' http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/hosts/$MOVE_TO/host_components
# Stop HISTORYSERVER on old host
curl -u $AMBARI_USER:$AMBARI_PASSWORD -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo": {"context": "Stop History Server","query":"HostRoles/component_name.in('HISTORYSERVER')"}, "Body":{"HostRoles": {"state": "INSTALLED"}}}' http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/hosts/$MOVE_FROM/host_components/HISTORYSERVER
# copy journal from old node to new node.
mkdir /hadoop/mapreduce
rsync -av -e "ssh" --rsync-path="sudo rsync" $SSH_USER@$MOVE_FROM:/hadoop/mapreduce/jhs/ /hadoop/mapreduce/jhs
# update the configuration property below within in the Ambari UI within the MapReduce2 section.
# <mapreduce.jobhistory.address>
# <mapreduce.jobhistory.webapp.address>
# update the configuration property below within in the Ambari UI within the YARN section.
# <yarn.log.server.url>
# Start HISTORYSERVER on new host
curl -u $AMBARI_USER:$AMBARI_PASSWORD -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo": {"context": "Start History Server","query":"HostRoles/component_name.in('HISTORYSERVER')"}, "Body":{"HostRoles": {"state": "STARTED"}}}' http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/hosts/$MOVE_TO/host_components/HISTORYSERVER
# Remove the old component
curl -u $AMBARI_USER:$AMBARI_PASSWORD -H "X-Requested-By:ambari" -i -X DELETE http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/hosts/$MOVE_FROM/host_components/HISTORYSERVER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment