SingleCluster.md.vm 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <!---
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License. See accompanying LICENSE file.
  11. -->
  12. #set ( $H3 = '###' )
  13. #set ( $H4 = '####' )
  14. #set ( $H5 = '#####' )
  15. Hadoop: Setting up a Single Node Cluster.
  16. =========================================
  17. <!-- MACRO{toc|fromDepth=0|toDepth=3} -->
  18. Purpose
  19. -------
  20. This document describes how to set up and configure a single-node Hadoop installation so that you can quickly perform simple operations using Hadoop MapReduce and the Hadoop Distributed File System (HDFS).
  21. Prerequisites
  22. -------------
  23. $H3 Supported Platforms
  24. * GNU/Linux is supported as a development and production platform. Hadoop has been demonstrated on GNU/Linux clusters with 2000 nodes.
  25. * Windows is also a supported platform but the followings steps are for Linux only. To set up Hadoop on Windows, see [wiki page](http://wiki.apache.org/hadoop/Hadoop2OnWindows).
  26. $H3 Required Software
  27. Required software for Linux include:
  28. 1. Java™ must be installed. Recommended Java versions are described at [HadoopJavaVersions](http://wiki.apache.org/hadoop/HadoopJavaVersions).
  29. 2. ssh must be installed and sshd must be running to use the Hadoop scripts that manage remote Hadoop daemons if the optional start and stop scripts are to be used. Additionally, it is recommmended that pdsh also be installed for better ssh resource management.
  30. $H3 Installing Software
  31. If your cluster doesn't have the requisite software you will need to install it.
  32. For example on Ubuntu Linux:
  33. $ sudo apt-get install ssh
  34. $ sudo apt-get install pdsh
  35. Download
  36. --------
  37. To get a Hadoop distribution, download a recent stable release from one of the [Apache Download Mirrors](http://www.apache.org/dyn/closer.cgi/hadoop/common/).
  38. Prepare to Start the Hadoop Cluster
  39. -----------------------------------
  40. Unpack the downloaded Hadoop distribution. In the distribution, edit the file `etc/hadoop/hadoop-env.sh` to define some parameters as follows:
  41. # set to the root of your Java installation
  42. export JAVA_HOME=/usr/java/latest
  43. Try the following command:
  44. $ bin/hadoop
  45. This will display the usage documentation for the hadoop script.
  46. Now you are ready to start your Hadoop cluster in one of the three supported modes:
  47. * [Local (Standalone) Mode](#Standalone_Operation)
  48. * [Pseudo-Distributed Mode](#Pseudo-Distributed_Operation)
  49. * [Fully-Distributed Mode](#Fully-Distributed_Operation)
  50. Standalone Operation
  51. --------------------
  52. By default, Hadoop is configured to run in a non-distributed mode, as a single Java process. This is useful for debugging.
  53. The following example copies the unpacked conf directory to use as input and then finds and displays every match of the given regular expression. Output is written to the given output directory.
  54. $ mkdir input
  55. $ cp etc/hadoop/*.xml input
  56. $ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-${project.version}.jar grep input output 'dfs[a-z.]+'
  57. $ cat output/*
  58. Pseudo-Distributed Operation
  59. ----------------------------
  60. Hadoop can also be run on a single-node in a pseudo-distributed mode where each Hadoop daemon runs in a separate Java process.
  61. $H3 Configuration
  62. Use the following:
  63. etc/hadoop/core-site.xml:
  64. <configuration>
  65. <property>
  66. <name>fs.defaultFS</name>
  67. <value>hdfs://localhost:9000</value>
  68. </property>
  69. </configuration>
  70. etc/hadoop/hdfs-site.xml:
  71. <configuration>
  72. <property>
  73. <name>dfs.replication</name>
  74. <value>1</value>
  75. </property>
  76. </configuration>
  77. $H3 Setup passphraseless ssh
  78. Now check that you can ssh to the localhost without a passphrase:
  79. $ ssh localhost
  80. If you cannot ssh to localhost without a passphrase, execute the following commands:
  81. $ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
  82. $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  83. $ chmod 0600 ~/.ssh/authorized_keys
  84. $H3 Execution
  85. The following instructions are to run a MapReduce job locally. If you want to execute a job on YARN, see [YARN on Single Node](#YARN_on_Single_Node).
  86. 1. Format the filesystem:
  87. $ bin/hdfs namenode -format
  88. 2. Start NameNode daemon and DataNode daemon:
  89. $ sbin/start-dfs.sh
  90. The hadoop daemon log output is written to the `$HADOOP_LOG_DIR` directory (defaults to `$HADOOP_HOME/logs`).
  91. 3. Browse the web interface for the NameNode; by default it is available at:
  92. * NameNode - `http://localhost:9870/`
  93. 4. Make the HDFS directories required to execute MapReduce jobs:
  94. $ bin/hdfs dfs -mkdir /user
  95. $ bin/hdfs dfs -mkdir /user/<username>
  96. 5. Copy the input files into the distributed filesystem:
  97. $ bin/hdfs dfs -mkdir input
  98. $ bin/hdfs dfs -put etc/hadoop/*.xml input
  99. 6. Run some of the examples provided:
  100. $ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-${project.version}.jar grep input output 'dfs[a-z.]+'
  101. 7. Examine the output files: Copy the output files from the distributed filesystem to the local filesystem and examine them:
  102. $ bin/hdfs dfs -get output output
  103. $ cat output/*
  104. or
  105. View the output files on the distributed filesystem:
  106. $ bin/hdfs dfs -cat output/*
  107. 8. When you're done, stop the daemons with:
  108. $ sbin/stop-dfs.sh
  109. $H3 YARN on a Single Node
  110. You can run a MapReduce job on YARN in a pseudo-distributed mode by setting a few parameters and running ResourceManager daemon and NodeManager daemon in addition.
  111. The following instructions assume that 1. ~ 4. steps of [the above instructions](#Execution) are already executed.
  112. 1. Configure parameters as follows:
  113. `etc/hadoop/mapred-site.xml`:
  114. <configuration>
  115. <property>
  116. <name>mapreduce.framework.name</name>
  117. <value>yarn</value>
  118. </property>
  119. <property>
  120. <name>mapreduce.application.classpath</name>
  121. <value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*:$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*</value>
  122. </property>
  123. </configuration>
  124. `etc/hadoop/yarn-site.xml`:
  125. <configuration>
  126. <property>
  127. <name>yarn.nodemanager.aux-services</name>
  128. <value>mapreduce_shuffle</value>
  129. </property>
  130. <property>
  131. <name>yarn.nodemanager.env-whitelist</name>
  132. <value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>
  133. </property>
  134. </configuration>
  135. 2. Start ResourceManager daemon and NodeManager daemon:
  136. $ sbin/start-yarn.sh
  137. 3. Browse the web interface for the ResourceManager; by default it is available at:
  138. * ResourceManager - `http://localhost:8088/`
  139. 4. Run a MapReduce job.
  140. 5. When you're done, stop the daemons with:
  141. $ sbin/stop-yarn.sh
  142. Fully-Distributed Operation
  143. ---------------------------
  144. For information on setting up fully-distributed, non-trivial clusters see [Cluster Setup](./ClusterSetup.html).