hdfs 11 KB

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