start-hadoop 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/sh
  2. # Start Hadoop on a cluster.
  3. # Import variables
  4. bin=`dirname "$0"`
  5. bin=`cd "$bin"; pwd`
  6. . "$bin"/hadoop-ec2-env.sh
  7. echo "Asking master to say hello"
  8. if ! ssh $SSH_OPTS "root@$MASTER_HOST" echo "hello" ; then
  9. echo "SSH failed for root@$MASTER_HOST"
  10. exit 1
  11. fi
  12. # Datanodes that are started separately from the rest of the cluster will
  13. # still use the $MASTER_HOST address to access the master
  14. echo "Adjusting master hadoop-site.xml to minimize DNS lookups"
  15. ssh $SSH_OPTS "root@$MASTER_HOST" "sed -i -e \"s/$MASTER_HOST/\$(hostname)/g\" /usr/local/hadoop-$HADOOP_VERSION/conf/hadoop-site.xml"
  16. echo "Creating slaves file and copying to master"
  17. ec2-describe-instances | grep INSTANCE | grep running | awk '{if ($7 != 0 && $8 != 0) print $4}' > slaves
  18. scp $SSH_OPTS slaves "root@$MASTER_HOST:/usr/local/hadoop-$HADOOP_VERSION/conf/slaves"
  19. echo "Copying private key to master"
  20. scp $SSH_OPTS $PRIVATE_KEY_PATH "root@$MASTER_HOST:/root/.ssh/id_rsa"
  21. ssh $SSH_OPTS "root@$MASTER_HOST" "chmod 600 /root/.ssh/id_rsa"
  22. echo "Copying private key to slaves"
  23. for slave in `cat slaves`; do
  24. scp $SSH_OPTS $PRIVATE_KEY_PATH "root@$slave:/root/.ssh/id_rsa"
  25. ssh $SSH_OPTS "root@$slave" "chmod 600 /root/.ssh/id_rsa"
  26. sleep 1
  27. done
  28. echo "Formatting new cluster's filesystem"
  29. ssh $SSH_OPTS "root@$MASTER_HOST" "/usr/local/hadoop-$HADOOP_VERSION/bin/hadoop namenode -format"
  30. echo "Starting cluster"
  31. ssh $SSH_OPTS "root@$MASTER_HOST" "/usr/local/hadoop-$HADOOP_VERSION/bin/start-all.sh"
  32. echo "Finished - check progress at http://$MASTER_HOST:50030/"
  33. echo "Logging in to master $MASTER_HOST."
  34. ssh $SSH_OPTS "root@$MASTER_HOST"