start-dfs.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. # Start hadoop dfs daemons.
  17. # Optinally upgrade or rollback dfs state.
  18. # Run this on master node.
  19. usage="Usage: start-dfs.sh [-upgrade|-rollback]"
  20. bin=`dirname "${BASH_SOURCE-$0}"`
  21. bin=`cd "$bin"; pwd`
  22. DEFAULT_LIBEXEC_DIR="$bin"/../libexec
  23. HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
  24. . $HADOOP_LIBEXEC_DIR/hdfs-config.sh
  25. # get arguments
  26. if [ $# -ge 1 ]; then
  27. nameStartOpt="$1"
  28. shift
  29. case "$nameStartOpt" in
  30. (-upgrade)
  31. ;;
  32. (-rollback)
  33. dataStartOpt="$nameStartOpt"
  34. ;;
  35. (*)
  36. echo $usage
  37. exit 1
  38. ;;
  39. esac
  40. fi
  41. #---------------------------------------------------------
  42. # namenodes
  43. NAMENODES=$($HADOOP_PREFIX/bin/hdfs getconf -namenodes)
  44. echo "Starting namenodes on [$NAMENODES]"
  45. "$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
  46. --config "$HADOOP_CONF_DIR" \
  47. --hostnames "$NAMENODES" \
  48. --script "$bin/hdfs" start namenode $nameStartOpt
  49. #---------------------------------------------------------
  50. # datanodes (using default slaves file)
  51. if [ -n "$HADOOP_SECURE_DN_USER" ]; then
  52. echo \
  53. "Attempting to start secure cluster, skipping datanodes. " \
  54. "Run start-secure-dns.sh as root to complete startup."
  55. else
  56. "$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
  57. --config "$HADOOP_CONF_DIR" \
  58. --script "$bin/hdfs" start datanode $dataStartOpt
  59. fi
  60. #---------------------------------------------------------
  61. # secondary namenodes (if any)
  62. SECONDARY_NAMENODES=$($HADOOP_PREFIX/bin/hdfs getconf -secondarynamenodes 2>&-)
  63. echo "Starting secondary namenodes [$SECONDARY_NAMENODES]"
  64. "$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
  65. --config "$HADOOP_CONF_DIR" \
  66. --hostnames "$SECONDARY_NAMENODES" \
  67. --script "$bin/hdfs" start secondarynamenode
  68. # eof