hdfs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. # Environment Variables
  17. #
  18. # JSVC_HOME home directory of jsvc binary. Required for starting secure
  19. # datanode.
  20. #
  21. # JSVC_OUTFILE path to jsvc output file. Defaults to
  22. # $HADOOP_LOG_DIR/jsvc.out.
  23. #
  24. # JSVC_ERRFILE path to jsvc error file. Defaults to $HADOOP_LOG_DIR/jsvc.err.
  25. bin=`which $0`
  26. bin=`dirname ${bin}`
  27. bin=`cd "$bin" > /dev/null; pwd`
  28. DEFAULT_LIBEXEC_DIR="$bin"/../libexec
  29. if [ -n "$HADOOP_HOME" ]; then
  30. DEFAULT_LIBEXEC_DIR="$HADOOP_HOME"/libexec
  31. fi
  32. HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
  33. . $HADOOP_LIBEXEC_DIR/hdfs-config.sh
  34. function print_usage(){
  35. echo "Usage: hdfs [--config confdir] COMMAND"
  36. echo " where COMMAND is one of:"
  37. echo " dfs run a filesystem command on the file systems supported in Hadoop."
  38. echo " namenode -format format the DFS filesystem"
  39. echo " secondarynamenode run the DFS secondary namenode"
  40. echo " namenode run the DFS namenode"
  41. echo " journalnode run the DFS journalnode"
  42. echo " zkfc run the ZK Failover Controller daemon"
  43. echo " datanode run a DFS datanode"
  44. echo " dfsadmin run a DFS admin client"
  45. echo " haadmin run a DFS HA admin client"
  46. echo " fsck run a DFS filesystem checking utility"
  47. echo " balancer run a cluster balancing utility"
  48. echo " jmxget get JMX exported values from NameNode or DataNode."
  49. echo " mover run a utility to move block replicas across"
  50. echo " storage types"
  51. echo " oiv apply the offline fsimage viewer to an fsimage"
  52. echo " oiv_legacy apply the offline fsimage viewer to an legacy fsimage"
  53. echo " oev apply the offline edits viewer to an edits file"
  54. echo " fetchdt fetch a delegation token from the NameNode"
  55. echo " getconf get config values from configuration"
  56. echo " groups get the groups which users belong to"
  57. echo " snapshotDiff diff two snapshots of a directory or diff the"
  58. echo " current directory contents with a snapshot"
  59. echo " lsSnapshottableDir list all snapshottable dirs owned by the current user"
  60. echo " Use -help to see options"
  61. echo " portmap run a portmap service"
  62. echo " nfs3 run an NFS version 3 gateway"
  63. echo " cacheadmin configure the HDFS cache"
  64. echo " crypto configure HDFS encryption zones"
  65. echo " storagepolicies get all the existing block storage policies"
  66. echo " version print the version"
  67. echo ""
  68. echo "Most commands print help when invoked w/o parameters."
  69. }
  70. if [ $# = 0 ]; then
  71. print_usage
  72. exit
  73. fi
  74. COMMAND=$1
  75. shift
  76. case $COMMAND in
  77. # usage flags
  78. --help|-help|-h)
  79. print_usage
  80. exit
  81. ;;
  82. esac
  83. # Determine if we're starting a secure datanode, and if so, redefine appropriate variables
  84. if [ "$COMMAND" == "datanode" ] && [ "$EUID" -eq 0 ] && [ -n "$HADOOP_SECURE_DN_USER" ]; then
  85. if [ -n "$JSVC_HOME" ]; then
  86. if [ -n "$HADOOP_SECURE_DN_PID_DIR" ]; then
  87. HADOOP_PID_DIR=$HADOOP_SECURE_DN_PID_DIR
  88. fi
  89. if [ -n "$HADOOP_SECURE_DN_LOG_DIR" ]; then
  90. HADOOP_LOG_DIR=$HADOOP_SECURE_DN_LOG_DIR
  91. HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR"
  92. fi
  93. HADOOP_IDENT_STRING=$HADOOP_SECURE_DN_USER
  94. HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING"
  95. starting_secure_dn="true"
  96. else
  97. echo "It looks like you're trying to start a secure DN, but \$JSVC_HOME"\
  98. "isn't set. Falling back to starting insecure DN."
  99. fi
  100. fi
  101. # Determine if we're starting a privileged NFS daemon, and if so, redefine appropriate variables
  102. if [ "$COMMAND" == "nfs3" ] && [ "$EUID" -eq 0 ] && [ -n "$HADOOP_PRIVILEGED_NFS_USER" ]; then
  103. if [ -n "$JSVC_HOME" ]; then
  104. if [ -n "$HADOOP_PRIVILEGED_NFS_PID_DIR" ]; then
  105. HADOOP_PID_DIR=$HADOOP_PRIVILEGED_NFS_PID_DIR
  106. fi
  107. if [ -n "$HADOOP_PRIVILEGED_NFS_LOG_DIR" ]; then
  108. HADOOP_LOG_DIR=$HADOOP_PRIVILEGED_NFS_LOG_DIR
  109. HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.log.dir=$HADOOP_LOG_DIR"
  110. fi
  111. HADOOP_IDENT_STRING=$HADOOP_PRIVILEGED_NFS_USER
  112. HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.id.str=$HADOOP_IDENT_STRING"
  113. starting_privileged_nfs="true"
  114. else
  115. echo "It looks like you're trying to start a privileged NFS server, but"\
  116. "\$JSVC_HOME isn't set. Falling back to starting unprivileged NFS server."
  117. fi
  118. fi
  119. if [ "$COMMAND" = "namenode" ] ; then
  120. CLASS='org.apache.hadoop.hdfs.server.namenode.NameNode'
  121. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NAMENODE_OPTS"
  122. elif [ "$COMMAND" = "zkfc" ] ; then
  123. CLASS='org.apache.hadoop.hdfs.tools.DFSZKFailoverController'
  124. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_ZKFC_OPTS"
  125. elif [ "$COMMAND" = "secondarynamenode" ] ; then
  126. CLASS='org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode'
  127. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_SECONDARYNAMENODE_OPTS"
  128. elif [ "$COMMAND" = "datanode" ] ; then
  129. CLASS='org.apache.hadoop.hdfs.server.datanode.DataNode'
  130. if [ "$starting_secure_dn" = "true" ]; then
  131. HADOOP_OPTS="$HADOOP_OPTS -jvm server $HADOOP_DATANODE_OPTS"
  132. else
  133. HADOOP_OPTS="$HADOOP_OPTS -server $HADOOP_DATANODE_OPTS"
  134. fi
  135. elif [ "$COMMAND" = "journalnode" ] ; then
  136. CLASS='org.apache.hadoop.hdfs.qjournal.server.JournalNode'
  137. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_JOURNALNODE_OPTS"
  138. elif [ "$COMMAND" = "dfs" ] ; then
  139. CLASS=org.apache.hadoop.fs.FsShell
  140. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  141. elif [ "$COMMAND" = "dfsadmin" ] ; then
  142. CLASS=org.apache.hadoop.hdfs.tools.DFSAdmin
  143. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  144. elif [ "$COMMAND" = "haadmin" ] ; then
  145. CLASS=org.apache.hadoop.hdfs.tools.DFSHAAdmin
  146. CLASSPATH=${CLASSPATH}:${TOOL_PATH}
  147. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  148. elif [ "$COMMAND" = "fsck" ] ; then
  149. CLASS=org.apache.hadoop.hdfs.tools.DFSck
  150. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  151. elif [ "$COMMAND" = "balancer" ] ; then
  152. CLASS=org.apache.hadoop.hdfs.server.balancer.Balancer
  153. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_BALANCER_OPTS"
  154. elif [ "$COMMAND" = "mover" ] ; then
  155. CLASS=org.apache.hadoop.hdfs.server.mover.Mover
  156. HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_MOVER_OPTS}"
  157. elif [ "$COMMAND" = "storagepolicies" ] ; then
  158. CLASS=org.apache.hadoop.hdfs.tools.GetStoragePolicies
  159. elif [ "$COMMAND" = "jmxget" ] ; then
  160. CLASS=org.apache.hadoop.hdfs.tools.JMXGet
  161. elif [ "$COMMAND" = "oiv" ] ; then
  162. CLASS=org.apache.hadoop.hdfs.tools.offlineImageViewer.OfflineImageViewerPB
  163. elif [ "$COMMAND" = "oiv_legacy" ] ; then
  164. CLASS=org.apache.hadoop.hdfs.tools.offlineImageViewer.OfflineImageViewer
  165. elif [ "$COMMAND" = "oev" ] ; then
  166. CLASS=org.apache.hadoop.hdfs.tools.offlineEditsViewer.OfflineEditsViewer
  167. elif [ "$COMMAND" = "fetchdt" ] ; then
  168. CLASS=org.apache.hadoop.hdfs.tools.DelegationTokenFetcher
  169. elif [ "$COMMAND" = "getconf" ] ; then
  170. CLASS=org.apache.hadoop.hdfs.tools.GetConf
  171. elif [ "$COMMAND" = "groups" ] ; then
  172. CLASS=org.apache.hadoop.hdfs.tools.GetGroups
  173. elif [ "$COMMAND" = "snapshotDiff" ] ; then
  174. CLASS=org.apache.hadoop.hdfs.tools.snapshot.SnapshotDiff
  175. elif [ "$COMMAND" = "lsSnapshottableDir" ] ; then
  176. CLASS=org.apache.hadoop.hdfs.tools.snapshot.LsSnapshottableDir
  177. elif [ "$COMMAND" = "portmap" ] ; then
  178. CLASS=org.apache.hadoop.portmap.Portmap
  179. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_PORTMAP_OPTS"
  180. elif [ "$COMMAND" = "nfs3" ] ; then
  181. CLASS=org.apache.hadoop.hdfs.nfs.nfs3.Nfs3
  182. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_NFS3_OPTS"
  183. elif [ "$COMMAND" = "cacheadmin" ] ; then
  184. CLASS=org.apache.hadoop.hdfs.tools.CacheAdmin
  185. elif [ "$COMMAND" = "crypto" ] ; then
  186. CLASS=org.apache.hadoop.hdfs.tools.CryptoAdmin
  187. elif [ "$COMMAND" = "version" ] ; then
  188. CLASS=org.apache.hadoop.util.VersionInfo
  189. else
  190. CLASS="$COMMAND"
  191. fi
  192. export CLASSPATH=$CLASSPATH
  193. HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,NullAppender}"
  194. # Check to see if we should start a secure datanode
  195. if [ "$starting_secure_dn" = "true" ]; then
  196. if [ "$HADOOP_PID_DIR" = "" ]; then
  197. HADOOP_SECURE_DN_PID="/tmp/hadoop_secure_dn.pid"
  198. else
  199. HADOOP_SECURE_DN_PID="$HADOOP_PID_DIR/hadoop_secure_dn.pid"
  200. fi
  201. JSVC=$JSVC_HOME/jsvc
  202. if [ ! -f $JSVC ]; then
  203. echo "JSVC_HOME is not set correctly so jsvc cannot be found. jsvc is required to run secure datanodes. "
  204. echo "Please download and install jsvc from http://archive.apache.org/dist/commons/daemon/binaries/ "\
  205. "and set JSVC_HOME to the directory containing the jsvc binary."
  206. exit
  207. fi
  208. if [[ ! $JSVC_OUTFILE ]]; then
  209. JSVC_OUTFILE="$HADOOP_LOG_DIR/jsvc.out"
  210. fi
  211. if [[ ! $JSVC_ERRFILE ]]; then
  212. JSVC_ERRFILE="$HADOOP_LOG_DIR/jsvc.err"
  213. fi
  214. exec "$JSVC" \
  215. -Dproc_$COMMAND -outfile "$JSVC_OUTFILE" \
  216. -errfile "$JSVC_ERRFILE" \
  217. -pidfile "$HADOOP_SECURE_DN_PID" \
  218. -nodetach \
  219. -user "$HADOOP_SECURE_DN_USER" \
  220. -cp "$CLASSPATH" \
  221. $JAVA_HEAP_MAX $HADOOP_OPTS \
  222. org.apache.hadoop.hdfs.server.datanode.SecureDataNodeStarter "$@"
  223. elif [ "$starting_privileged_nfs" = "true" ] ; then
  224. if [ "$HADOOP_PID_DIR" = "" ]; then
  225. HADOOP_PRIVILEGED_NFS_PID="/tmp/hadoop_privileged_nfs3.pid"
  226. else
  227. HADOOP_PRIVILEGED_NFS_PID="$HADOOP_PID_DIR/hadoop_privileged_nfs3.pid"
  228. fi
  229. JSVC=$JSVC_HOME/jsvc
  230. if [ ! -f $JSVC ]; then
  231. echo "JSVC_HOME is not set correctly so jsvc cannot be found. jsvc is required to run privileged NFS gateways. "
  232. echo "Please download and install jsvc from http://archive.apache.org/dist/commons/daemon/binaries/ "\
  233. "and set JSVC_HOME to the directory containing the jsvc binary."
  234. exit
  235. fi
  236. if [[ ! $JSVC_OUTFILE ]]; then
  237. JSVC_OUTFILE="$HADOOP_LOG_DIR/nfs3_jsvc.out"
  238. fi
  239. if [[ ! $JSVC_ERRFILE ]]; then
  240. JSVC_ERRFILE="$HADOOP_LOG_DIR/nfs3_jsvc.err"
  241. fi
  242. exec "$JSVC" \
  243. -Dproc_$COMMAND -outfile "$JSVC_OUTFILE" \
  244. -errfile "$JSVC_ERRFILE" \
  245. -pidfile "$HADOOP_PRIVILEGED_NFS_PID" \
  246. -nodetach \
  247. -user "$HADOOP_PRIVILEGED_NFS_USER" \
  248. -cp "$CLASSPATH" \
  249. $JAVA_HEAP_MAX $HADOOP_OPTS \
  250. org.apache.hadoop.hdfs.nfs.nfs3.PrivilegedNfsGatewayStarter "$@"
  251. else
  252. # run it
  253. exec "$JAVA" -Dproc_$COMMAND $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"
  254. fi