hdfs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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=`which $0`
  17. bin=`dirname ${bin}`
  18. bin=`cd "$bin"; pwd`
  19. DEFAULT_LIBEXEC_DIR="$bin"/../libexec
  20. HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
  21. . $HADOOP_LIBEXEC_DIR/hdfs-config.sh
  22. function print_usage(){
  23. echo "Usage: hdfs [--config confdir] COMMAND"
  24. echo " where COMMAND is one of:"
  25. echo " dfs run a filesystem command on the file systems supported in Hadoop."
  26. echo " namenode -format format the DFS filesystem"
  27. echo " secondarynamenode run the DFS secondary namenode"
  28. echo " namenode run the DFS namenode"
  29. echo " datanode run a DFS datanode"
  30. echo " dfsadmin run a DFS admin client"
  31. echo " haadmin run a DFS HA admin client"
  32. echo " fsck run a DFS filesystem checking utility"
  33. echo " balancer run a cluster balancing utility"
  34. echo " jmxget get JMX exported values from NameNode or DataNode."
  35. echo " oiv apply the offline fsimage viewer to an fsimage"
  36. echo " oev apply the offline edits viewer to an edits file"
  37. echo " fetchdt fetch a delegation token from the NameNode"
  38. echo " getconf get config values from configuration"
  39. echo " groups get the groups which users belong to"
  40. echo " Use -help to see options"
  41. echo ""
  42. echo "Most commands print help when invoked w/o parameters."
  43. }
  44. if [ $# = 0 ]; then
  45. print_usage
  46. exit
  47. fi
  48. COMMAND=$1
  49. shift
  50. # Determine if we're starting a secure datanode, and if so, redefine appropriate variables
  51. if [ "$COMMAND" == "datanode" ] && [ "$EUID" -eq 0 ] && [ -n "$HADOOP_SECURE_DN_USER" ]; then
  52. if [ -n "$HADOOP_SECURE_DN_PID_DIR" ]; then
  53. HADOOP_PID_DIR=$HADOOP_SECURE_DN_PID_DIR
  54. fi
  55. if [ -n "$HADOOP_SECURE_DN_LOG_DIR" ]; then
  56. HADOOP_LOG_DIR=$HADOOP_SECURE_DN_LOG_DIR
  57. fi
  58. HADOOP_IDENT_STRING=$HADOOP_SECURE_DN_USER
  59. starting_secure_dn="true"
  60. fi
  61. if [ "$COMMAND" = "namenode" ] ; then
  62. CLASS='org.apache.hadoop.hdfs.server.namenode.NameNode'
  63. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NAMENODE_OPTS"
  64. elif [ "$COMMAND" = "secondarynamenode" ] ; then
  65. CLASS='org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode'
  66. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_SECONDARYNAMENODE_OPTS"
  67. elif [ "$COMMAND" = "datanode" ] ; then
  68. CLASS='org.apache.hadoop.hdfs.server.datanode.DataNode'
  69. if [ "$starting_secure_dn" = "true" ]; then
  70. HADOOP_OPTS="$HADOOP_OPTS -jvm server $HADOOP_DATANODE_OPTS"
  71. else
  72. HADOOP_OPTS="$HADOOP_OPTS -server $HADOOP_DATANODE_OPTS"
  73. fi
  74. elif [ "$COMMAND" = "dfs" ] ; then
  75. CLASS=org.apache.hadoop.fs.FsShell
  76. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  77. elif [ "$COMMAND" = "dfsadmin" ] ; then
  78. CLASS=org.apache.hadoop.hdfs.tools.DFSAdmin
  79. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  80. elif [ "$COMMAND" = "haadmin" ] ; then
  81. CLASS=org.apache.hadoop.hdfs.tools.DFSHAAdmin
  82. CLASSPATH=${CLASSPATH}:${TOOL_PATH}
  83. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  84. elif [ "$COMMAND" = "fsck" ] ; then
  85. CLASS=org.apache.hadoop.hdfs.tools.DFSck
  86. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  87. elif [ "$COMMAND" = "balancer" ] ; then
  88. CLASS=org.apache.hadoop.hdfs.server.balancer.Balancer
  89. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_BALANCER_OPTS"
  90. elif [ "$COMMAND" = "jmxget" ] ; then
  91. CLASS=org.apache.hadoop.hdfs.tools.JMXGet
  92. elif [ "$COMMAND" = "oiv" ] ; then
  93. CLASS=org.apache.hadoop.hdfs.tools.offlineImageViewer.OfflineImageViewer
  94. elif [ "$COMMAND" = "oev" ] ; then
  95. CLASS=org.apache.hadoop.hdfs.tools.offlineEditsViewer.OfflineEditsViewer
  96. elif [ "$COMMAND" = "fetchdt" ] ; then
  97. CLASS=org.apache.hadoop.hdfs.tools.DelegationTokenFetcher
  98. elif [ "$COMMAND" = "getconf" ] ; then
  99. CLASS=org.apache.hadoop.hdfs.tools.GetConf
  100. elif [ "$COMMAND" = "groups" ] ; then
  101. CLASS=org.apache.hadoop.hdfs.tools.GetGroups
  102. else
  103. CLASS="$COMMAND"
  104. fi
  105. if $cygwin; then
  106. CLASSPATH=`cygpath -p -w "$CLASSPATH"`
  107. fi
  108. export CLASSPATH=$CLASSPATH
  109. #turn security logger on the namenode
  110. if [ $COMMAND = "namenode" ]; then
  111. HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS}"
  112. else
  113. HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,NullAppender}"
  114. fi
  115. # Check to see if we should start a secure datanode
  116. if [ "$starting_secure_dn" = "true" ]; then
  117. if [ "$HADOOP_PID_DIR" = "" ]; then
  118. HADOOP_SECURE_DN_PID="/tmp/hadoop_secure_dn.pid"
  119. else
  120. HADOOP_SECURE_DN_PID="$HADOOP_PID_DIR/hadoop_secure_dn.pid"
  121. fi
  122. JSVC=$JSVC_HOME/jsvc
  123. if [ ! -f $JSVC ]; then
  124. echo "JSVC_HOME is not set correctly so jsvc can not be found. Jsvc is required to run secure datanodes. "
  125. echo "Please download and install jsvc from http://archive.apache.org/dist/commons/daemon/binaries/ "\
  126. "and set JSVC_HOME to the directory containing the jsvc binary."
  127. exit
  128. fi
  129. exec "$JSVC" \
  130. -Dproc_$COMMAND -outfile "$HADOOP_LOG_DIR/jsvc.out" \
  131. -errfile "$HADOOP_LOG_DIR/jsvc.err" \
  132. -pidfile "$HADOOP_SECURE_DN_PID" \
  133. -nodetach \
  134. -user "$HADOOP_SECURE_DN_USER" \
  135. -cp "$CLASSPATH" \
  136. $JAVA_HEAP_MAX $HADOOP_OPTS \
  137. org.apache.hadoop.hdfs.server.datanode.SecureDataNodeStarter "$@"
  138. else
  139. # run it
  140. exec "$JAVA" -Dproc_$COMMAND $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"
  141. fi