hadoop-setup-hdfs.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. bin=`dirname "$0"`
  17. bin=`cd "$bin"; pwd`
  18. if [ "$HADOOP_HOME" != "" ]; then
  19. echo "Warning: \$HADOOP_HOME is deprecated."
  20. echo
  21. fi
  22. . "$bin"/../libexec/hadoop-config.sh
  23. echo "Setup Hadoop Distributed File System"
  24. echo
  25. echo "Formatting namenode"
  26. echo
  27. su -c '${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} namenode -format' hdfs
  28. echo
  29. echo "Starting namenode process"
  30. echo
  31. /etc/init.d/hadoop-namenode start
  32. echo
  33. echo "Initialize HDFS file system: "
  34. echo
  35. su -c '${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} dfs -mkdir /user/mapred' hdfs
  36. su -c '${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} dfs -chown mapred:mapred /user/mapred' hdfs
  37. su -c '${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} dfs -mkdir /tmp' hdfs
  38. su -c '${HADOOP_PREFIX}/bin/hadoop --config ${HADOOP_CONF_DIR} dfs -chmod 777 /tmp' hdfs
  39. if [ $? -eq 0 ]; then
  40. echo "Completed."
  41. else
  42. echo "Unknown error occurred, check hadoop logs for details."
  43. fi
  44. echo
  45. echo "Please startup datanode processes: /etc/init.d/hadoop-datanode start"