【大数据系列】hadoop单节点安装官方文档翻译

Hadoop: Setting up a Single Node Cluster.

HADOOP:建立单节点集群

目的

前置条件

    支持的平台

    需要的软件

   安装软件

下载

准备开始建立hadoop集群

单机操作

伪分布式操作

   配置

  设置ssh免密登陆

  扩展

  单节点中YARN

完全分布式

Purpose

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).

目的

该文档描述了如何安装和配置一个单节点的Hadoop,以便于你可以快速的使用MapReduce和HDFS执行简单的操作。

Prerequisites

前置条件

Supported Platforms

  • GNU/Linux is supported as a development and production platform. Hadoop has been demonstrated on GNU/Linux clusters with 2000 nodes.

  • Windows is also a supported platform but the followings steps are for Linux only. To set up Hadoop on Windows, see wiki page.

支持的平台

     开发和生产环境支持GUN/linux环境。Hadoop在GUN/LINUX平台下证实可以创建2000个节点。

     windows平台也是支持的,但是如下的操作只是针对linux平台的,在windows上安装hadoop,请参考 wiki page.

Required Software

Required software for Linux include:

  1. Java™ must be installed. Recommended Java versions are described at HadoopJavaVersions.

  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.

需要的软件

    Java是必须的,需求的Java版本请查看HadoopJavaVersions.

   ssh是必须的,sshd必须使用hadoop脚本运行,如果使用开启或关闭脚本来管理远程机器上的hadoop进程。此外,为了更好的管理ssh资源pdsh也是需要安装的。

Installing Software

If your cluster doesn’t have the requisite software you will need to install it.

For example on Ubuntu Linux:

  $ sudo apt-get install ssh
  $ sudo apt-get install pdsh

安装软件

如果你的集群没有必要的软件,你需要去安装它。

例如在Ubuntu linux系统上:

   sudo apt-get install ssh

  sudo apt-get install pdsh

Download

To get a Hadoop distribution, download a recent stable release from one of the Apache Download Mirrors.

下载:

为了获取hadoop发行版,从Apache Download Mirrors.下载一个最近的稳定的发行版

Prepare to Start the Hadoop Cluster

Unpack the downloaded Hadoop distribution. In the distribution, edit the file etc/hadoop/hadoop-env.sh to define some parameters as follows:

  # set to the root of your Java installation
  export JAVA_HOME=/usr/java/latest

Try the following command:

  $ bin/hadoop

This will display the usage documentation for the hadoop script.

Now you are ready to start your Hadoop cluster in one of the three supported modes:

准备去启动hadoop集群

解压下载的hadoop发行版,在解压文件中,编辑etc/hadoop/hadoop-env.sh去设置如下的参数:

# set to the root of your Java installation
  export JAVA_HOME=/usr/java/latest
执行如下命令
$bin/hadoop
这将会展现使用hadoop脚本的文档现在你可以准备去启动你的hadoop集群从以下3种模式之一
本地模式
伪分布式
完全分布式

Standalone Operation

By default, Hadoop is configured to run in a non-distributed mode, as a single Java process. This is useful for debugging.

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.

  $ mkdir input
  $ cp etc/hadoop/*.xml input
  $ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.0-alpha4.jar grep input output 'dfs[a-z.]+'
  $ cat output/*

单机操作模式
默认情况下,hadoop是设置为非分布式模式,作为一个单独的Java进程。这对于调试是有用的。以下的例子复制解压的配置文件并且符合给定的表达式的文件作为输入。输出是被写到给定的输出文件夹。
$ mkdir input
  $ cp etc/hadoop/*.xml input
  $ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.0-alpha4.jar grep input output 'dfs[a-z.]+'
  $ cat output/*

Pseudo-Distributed Operation

Hadoop can also be run on a single-node in a pseudo-distributed mode where each Hadoop daemon runs in a separate Java process.

伪分布式

hadoop同样可以运行为单节点的伪分布式模式,在这种情况下每一个hadoop进程作为一个单独的Java进程单独运行。

Configuration

Use the following:

etc/hadoop/core-site.xml:

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://localhost:9000</value>
    </property>
</configuration>

etc/hadoop/hdfs-site.xml:

<configuration>
    <property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>
</configuration>
配置如下

etc/hadoop/core-site.xml:

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://localhost:9000</value>
    </property>
</configuration>

etc/hadoop/hdfs-site.xml:

<configuration>
    <property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>
</configuration>

Setup passphraseless ssh

Now check that you can ssh to the localhost without a passphrase:

  $ ssh localhost

If you cannot ssh to localhost without a passphrase, execute the following commands:

  $ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
  $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  $ chmod 0600 ~/.ssh/authorized_keys

设置免密登陆

现在检查你可以不使用密码ssh到本地

   $ ssh localhost 

如果你不可以没有密码ssh到本地,执行如下命令:

  $ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

  $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

 $ chmod 0600 ~/.ssh/authorized_keys

Execution

The following instructions are to run a MapReduce job locally. If you want to execute a job on YARN, see YARN on Single Node.

  1. Format the filesystem:

      $ bin/hdfs namenode -format
    
  2. Start NameNode daemon and DataNode daemon:

      $ sbin/start-dfs.sh
    

    The hadoop daemon log output is written to the $HADOOP_LOG_DIR directory (defaults to $HADOOP_HOME/logs).

  3. Browse the web interface for the NameNode; by default it is available at:

    • NameNode - http://localhost:9870/
  4. Make the HDFS directories required to execute MapReduce jobs:

      $ bin/hdfs dfs -mkdir /user
      $ bin/hdfs dfs -mkdir /user/<username>
    
  5. Copy the input files into the distributed filesystem:

      $ bin/hdfs dfs -mkdir input
      $ bin/hdfs dfs -put etc/hadoop/*.xml input
    
  6. Run some of the examples provided:

      $ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.0-alpha4.jar grep input output 'dfs[a-z.]+'
    
  7. Examine the output files: Copy the output files from the distributed filesystem to the local filesystem and examine them:

      $ bin/hdfs dfs -get output output
      $ cat output/*
    

    or

    View the output files on the distributed filesystem:

      $ bin/hdfs dfs -cat output/*
    
  8. When you’re done, stop the daemons with:

      $ sbin/stop-dfs.sh
    

执行

以下的指导描述了如何在本地运行一个MapReduce任务,如果你希望在YARN上执行MapReduce任务请参考后面

1、格式化文件系统

bin/hdfs  namenode -format

2、启动NameNode和DataNode

sbin/start-dfs.sh

hadoop进程日志的输出文件夹由HADOOP_LOG_DIR设置

3、浏览NameNode的web页面,默认是

NameNode http://localhost:9870

4、创建执行MapReduce任务的目录

$ bin/hdfs dfs -mkdir /user
$ bin/hdfs dfs -mkdir /user/<username>

5、拷贝输入文件到文件系统

$ bin/hdfs dfs -mkdir input
$ bin/hdfs dfs -put etc/hadoop/*.xml input

6、运行提供的一些例子

  $ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.0-alpha4.jar grep input output 'dfs[a-z.]+'

7、检查输出文件:从分布式文件系统中拷贝输出文件到本地并且检查他们

$ bin/hdfs dfs -get output output
$ cat output/*
或者

在分布式系统中查看输出文件:

$ bin/hdfs dfs -cat output/*

8、做完之后,关闭hadoop进程

$ sbin/stop-dfs.sh

YARN on a Single Node

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.

The following instructions assume that 1. ~ 4. steps of the above instructions are already executed.

  1. Configure parameters as follows:

    etc/hadoop/mapred-site.xml:

    <configuration>
        <property>
            <name>mapreduce.framework.name</name>
            <value>yarn</value>
        </property>
    </configuration>
    

    etc/hadoop/yarn-site.xml:

    <configuration>
        <property>
            <name>yarn.nodemanager.aux-services</name>
            <value>mapreduce_shuffle</value>
        </property>
        <property>
            <name>yarn.nodemanager.env-whitelist</name>
            <value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>
        </property>
    </configuration>
    
  2. Start ResourceManager daemon and NodeManager daemon:

      $ sbin/start-yarn.sh
    
  3. Browse the web interface for the ResourceManager; by default it is available at:

    • ResourceManager - http://localhost:8088/
  4. Run a MapReduce job.

  5. When you’re done, stop the daemons with:

      $ sbin/stop-yarn.sh
YARN上运行单节点
你可以通过在伪分布式系统中配置一些参数在YARN上运行一个MapReduce job,除此之外还可以运行ResourceManager和NodeManager
如下的操作假设1~4步已经执行执行

配置参数如下:

etc/hadoop/mapred-site.xml:

<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
etc/hadoop/yarn-site.xml:

<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.env-whitelist</name>
<value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>
</property>
</configuration>

启动ResourceManager进程和NodeManager进程:

$ sbin/start-yarn.sh

浏览ResourceManager的web界面,默认认识http://localhost:8088/
ResourceManager - http://localhost:8088/

运行一个MapReduce job

完成之后,停止进程

$ sbin/stop-yarn.sh

 

posted @ 2017-08-07 11:52  霓裳梦竹  阅读(854)  评论(0编辑  收藏  举报