launch-hadoop-slaves 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # Launch an EC2 Hadoop slaves.
  17. set -o errexit
  18. if [ -z $1 ]; then
  19. echo "Cluster name required!"
  20. exit -1
  21. fi
  22. if [ -z $2 ]; then
  23. echo "Must specify the number of slaves to start."
  24. exit -1
  25. fi
  26. CLUSTER=$1
  27. NO_INSTANCES=$2
  28. # Import variables
  29. bin=`dirname "$0"`
  30. bin=`cd "$bin"; pwd`
  31. . "$bin"/hadoop-ec2-env.sh
  32. if [ ! -f $MASTER_IP_PATH ]; then
  33. echo "Must start Cluster Master first!"
  34. exit -1
  35. fi
  36. # Finding Hadoop image
  37. AMI_IMAGE=`ec2-describe-images -a | grep $S3_BUCKET | grep $HADOOP_VERSION | grep $ARCH |grep available | awk '{print $2}'`
  38. # to use private master hostname, substitute below with:
  39. # MASTER_HOST=`cat $MASTER_PRIVATE_IP_PATH`
  40. MASTER_HOST=`cat $MASTER_IP_PATH`
  41. MASTER_ZONE=`cat $MASTER_ZONE_PATH`
  42. # Substituting master hostname
  43. sed -e "s|%MASTER_HOST%|$MASTER_HOST|" "$bin"/$USER_DATA_FILE > "$bin"/$USER_DATA_FILE.slave
  44. # Start slaves
  45. echo "Adding $1 node(s) to cluster group $CLUSTER with AMI $AMI_IMAGE"
  46. ec2-run-instances $AMI_IMAGE -n "$NO_INSTANCES" -g "$CLUSTER" -k "$KEY_NAME" -f "$bin"/$USER_DATA_FILE.slave -t "$INSTANCE_TYPE" -z "$MASTER_ZONE" $KERNEL_ARG | grep INSTANCE | awk '{print $2}'
  47. rm "$bin"/$USER_DATA_FILE.slave