(转)单机上配置hadoop
哈哈,几天连续收到百度两次电话,均是利好消息,于是乎不知不觉的自己的工作效率也提高了,几天折腾了好久终于在单机上配置好了hadoop,然后也成功的运行了一个用例,耶耶耶耶耶耶。
转自:http://www.michael-noll.com/tutorials/running-hadoop-on-ubuntu-linux-single-node-cluster/
Running Hadoop on Ubuntu Linux (Single-Node Cluster)
- Prerequisites
- Hadoop
- What’s next?
- Related Links
- Change Log
In this tutorial I will describe the required steps for setting up a pseudo-distributed, single-node Hadoop cluster backed by the Hadoop Distributed File System, running on Ubuntu Linux.
Hadoop is a framework written in Java for running applications on large clusters of commodity hardware and incorporates features similar to those of the Google File System (GFS) and of the MapReducecomputing paradigm. Hadoop’s HDFS is a highly fault-tolerant distributed file system and, like Hadoop in general, designed to be deployed on low-cost hardware. It provides high throughput access to application data and is suitable for applications that have large data sets.
The main goal of this tutorial is to get a simple Hadoop installation up and running so that you can play around with the software and learn more about it.
This tutorial has been tested with the following software versions:
- Ubuntu Linux 10.04 LTS (deprecated: 8.10 LTS, 8.04, 7.10, 7.04)
- Hadoop 1.0.3, released May 2012
Prerequisites
Sun Java 6
Hadoop requires a working Java 1.5+ (aka Java 5) installation. However, using Java 1.6 (aka Java 6) is recommended for running Hadoop. For the sake of this tutorial, I will therefore describe the installation of Java 1.6.
1 |
|
The full JDK which will be placed in /usr/lib/jvm/java-6-sun
(well, this directory is actually a symlink on Ubuntu).
After installation, make a quick check whether Sun’s JDK is correctly set up:
1 |
|
Adding a dedicated Hadoop system user
We will use a dedicated Hadoop user account for running Hadoop. While that’s not required it is recommended because it helps to separate the Hadoop installation from other software applications and user accounts running on the same machine (think: security, permissions, backups, etc).
1 |
|
This will add the user hduser
and the group hadoop
to your local machine.
Configuring SSH
Hadoop requires SSH access to manage its nodes, i.e. remote machines plus your local machine if you want to use Hadoop on it (which is what we want to do in this short tutorial). For our single-node setup of Hadoop, we therefore need to configure SSH access to localhost
for the hduser
user we created in the previous section.
I assume that you have SSH up and running on your machine and configured it to allow SSH public key authentication. If not, there are several online guides available.
First, we have to generate an SSH key for the hduser
user.
1 |
|
The second line will create an RSA key pair with an empty password. Generally, using an empty password is not recommended, but in this case it is needed to unlock the key without your interaction (you don’t want to enter the passphrase every time Hadoop interacts with its nodes).
Second, you have to enable SSH access to your local machine with this newly created key.
1 |
|
The final step is to test the SSH setup by connecting to your local machine with the hduser
user. The step is also needed to save your local machine’s host key fingerprint to the hduser
user’s known_hosts
file. If you have any special SSH configuration for your local machine like a non-standard SSH port, you can define host-specific SSH options in $HOME/.ssh/config
(see man ssh_config
for more information).
1 |
|
If the SSH connect should fail, these general tips might help:
- Enable debugging with
ssh -vvv localhost
and investigate the error in detail. - Check the SSH server configuration in
/etc/ssh/sshd_config
, in particular the optionsPubkeyAuthentication
(which should be set toyes
) andAllowUsers
(if this option is active, add thehduser
user to it). If you made any changes to the SSH server configuration file, you can force a configuration reload withsudo /etc/init.d/ssh reload
.
Disabling IPv6
One problem with IPv6 on Ubuntu is that using 0.0.0.0
for the various networking-related Hadoop configuration options will result in Hadoop binding to the IPv6 addresses of my Ubuntu box. In my case, I realized that there’s no practical point in enabling IPv6 on a box when you are not connected to any IPv6 network. Hence, I simply disabled IPv6 on my Ubuntu machine. Your mileage may vary.
To disable IPv6 on Ubuntu 10.04 LTS, open /etc/sysctl.conf
in the editor of your choice and add the following lines to the end of the file:
1 |
|
You have to reboot your machine in order to make the changes take effect.
You can check whether IPv6 is enabled on your machine with the following command:
1 |
|
A return value of 0 means IPv6 is enabled, a value of 1 means disabled (that’s what we want).
Alternative
You can also disable IPv6 only for Hadoop as documented in HADOOP-3437. You can do so by adding the following line to conf/hadoop-env.sh
:
1 |
|
Hadoop
Installation
Download Hadoop from the Apache Download Mirrors and extract the contents of the Hadoop package to a location of your choice. I picked /usr/local/hadoop
. Make sure to change the owner of all the files to the hduser
user and hadoop
group, for example:
1 |
|
(Just to give you the idea, YMMV – personally, I create a symlink from hadoop-1.0.3
to hadoop
.)
Update $HOME/.bashrc
Add the following lines to the end of the $HOME/.bashrc
file of user hduser
. If you use a shell other than bash, you should of course update its appropriate configuration files instead of .bashrc
.
1 |
|
You can repeat this exercise also for other users who want to use Hadoop.
Excursus: Hadoop Distributed File System (HDFS)
Before we continue let us briefly learn a bit more about Hadoop’s distributed file system.
The Hadoop Distributed File System (HDFS) is a distributed file system designed to run on commodity hardware. It has many similarities with existing distributed file systems. However, the differences from other distributed file systems are significant. HDFS is highly fault-tolerant and is designed to be deployed on low-cost hardware. HDFS provides high throughput access to application data and is suitable for applications that have large data sets. HDFS relaxes a few POSIX requirements to enable streaming access to file system data. HDFS was originally built as infrastructure for the Apache Nutch web search engine project. HDFS is part of the Apache Hadoop project, which is part of the Apache Lucene project.
The Hadoop Distributed File System: Architecture and Design hadoop.apache.org/hdfs/docs/…
The following picture gives an overview of the most important HDFS components.
Configuration
Our goal in this tutorial is a single-node setup of Hadoop. More information of what we do in this section is available on the Hadoop Wiki.
hadoop-env.sh
The only required environment variable we have to configure for Hadoop in this tutorial is JAVA_HOME
. Open conf/hadoop-env.sh
in the editor of your choice (if you used the installation path in this tutorial, the full path is /usr/local/hadoop/conf/hadoop-env.sh
) and set the JAVA_HOME
environment variable to the Sun JDK/JRE 6 directory.
Change
1 |
|
to
1 |
|
Note: If you are on a Mac with OS X 10.7 you can use the following line to set up JAVA_HOME
in conf/hadoop-env.sh
.
1 |
|
conf/*-site.xml
In this section, we will configure the directory where Hadoop will store its data files, the network ports it listens to, etc. Our setup will use Hadoop’s Distributed File System, HDFS, even though our little “cluster” only contains our single local machine.
You can leave the settings below “as is” with the exception of the hadoop.tmp.dir
parameter – this parameter you must change to a directory of your choice. We will use the directory /app/hadoop/tmp
in this tutorial. Hadoop’s default configurations use hadoop.tmp.dir
as the base temporary directory both for the local file system and HDFS, so don’t be surprised if you see Hadoop creating the specified directory automatically on HDFS at some later point.
Now we create the directory and set the required ownerships and permissions:
1 |
|
If you forget to set the required ownerships and permissions, you will see a java.io.IOException
when you try to format the name node in the next section).
Add the following snippets between the <configuration> ... </configuration>
tags in the respective configuration XML file.
In file conf/core-site.xml
:
1 |
|
In file conf/mapred-site.xml
:
1 |
|
In file conf/hdfs-site.xml
:
1 |
|
See Getting Started with Hadoop and the documentation in Hadoop’s API Overview if you have any questions about Hadoop’s configuration options.
Formatting the HDFS filesystem via the NameNode
The first step to starting up your Hadoop installation is formatting the Hadoop filesystem which is implemented on top of the local filesystem of your “cluster” (which includes only your local machine if you followed this tutorial). You need to do this the first time you set up a Hadoop cluster.
To format the filesystem (which simply initializes the directory specified by the dfs.name.dir
variable), run the command
1 |
|
The output will look like this:
1 |
|
Starting your single-node cluster
Run the command:
1 |
|
This will startup a Namenode, Datanode, Jobtracker and a Tasktracker on your machine.
The output will look like this:
1 |
|
A nifty tool for checking whether the expected Hadoop processes are running is jps
(part of Sun’s Java since v1.5.0). See also How to debug MapReduce programs.
1 |
|
You can also check with netstat
if Hadoop is listening on the configured ports.
1 |
|
If there are any errors, examine the log files in the /logs/
directory.
Stopping your single-node cluster
Run the command
1 |
|
to stop all the daemons running on your machine.
Example output:
1 |
|
Running a MapReduce job
We will now run your first Hadoop MapReduce job. We will use the WordCount example job which reads text files and counts how often words occur. The input is text files and the output is text files, each line of which contains a word and the count of how often it occurred, separated by a tab. More information of what happens behind the scenes is available at the Hadoop Wiki.
Download example input data
We will use three ebooks from Project Gutenberg for this example:
- The Outline of Science, Vol. 1 (of 4) by J. Arthur Thomson
- The Notebooks of Leonardo Da Vinci
- Ulysses by James Joyce
Download each ebook as text files in Plain Text UTF-8
encoding and store the files in a local temporary directory of choice, for example /tmp/gutenberg
.
1 |
|
Restart the Hadoop cluster
Restart your Hadoop cluster if it’s not running already.
1 |
|
Copy local example data to HDFS
Before we run the actual MapReduce job, we first have to copy the files from our local file system to Hadoop’s HDFS.
1 |
|
Run the MapReduce job
Now, we actually run the WordCount example job.
1 |
|
This command will read all the files in the HDFS directory /user/hduser/gutenberg
, process it, and store the result in the HDFS directory /user/hduser/gutenberg-output
.
Exception in thread "main" java.io.IOException: Error opening job jar: hadoop*examples*.jar
at org.apache.hadoop.util.RunJar.main (RunJar.java: 90)
Caused by: java.util.zip.ZipException: error in opening zip file
In this case, re-run the command with the full name of the Hadoop Examples JAR file, for example:
hduser@ubuntu:/usr/local/hadoop$ bin/hadoop jar hadoop-examples-1.0.3.jar wordcount /user/hduser/gutenberg /user/hduser/gutenberg-output
Example output of the previous command in the console:
1 |
|
Check if the result is successfully stored in HDFS directory /user/hduser/gutenberg-output
:
1 |
|
If you want to modify some Hadoop settings on the fly like increasing the number of Reduce tasks, you can use the "-D"
option:
1 |
|
An important note about mapred.map.tasks: Hadoop does not honor mapred.map.tasks beyond considering it a hint. But it accepts the user specified mapred.reduce.tasks and doesn’t manipulate that. You cannot force mapred.map.tasks but you can specify mapred.reduce.tasks.
Retrieve the job result from HDFS
To inspect the file, you can copy it from HDFS to the local file system. Alternatively, you can use the command
1 |
|
to read the file directly from HDFS without copying it to the local file system. In this tutorial, we will copy the results to the local file system though.
1 |
|
Note that in this specific output the quote signs (“) enclosing the words in the head
output above have not been inserted by Hadoop. They are the result of the word tokenizer used in the WordCount example, and in this case they matched the beginning of a quote in the ebook texts. Just inspect the part-00000
file further to see it for yourself.
The command fs -getmerge will simply concatenate any files it finds in the directory you specify. This means that the merged file might (and most likely will) not be sorted.
Hadoop Web Interfaces
Hadoop comes with several web interfaces which are by default (see conf/hadoop-default.xml
) available at these locations:
- http://localhost:50070/ – web UI of the NameNode daemon
- http://localhost:50030/ – web UI of the JobTracker daemon
- http://localhost:50060/ – web UI of the TaskTracker daemon
These web interfaces provide concise information about what’s happening in your Hadoop cluster. You might want to give them a try.
NameNode Web Interface (HDFS layer)
The name node web UI shows you a cluster summary including information about total/remaining capacity, live and dead nodes. Additionally, it allows you to browse the HDFS namespace and view the contents of its files in the web browser. It also gives access to the local machine’s Hadoop log files.
By default, it’s available at http://localhost:50070/.
JobTracker Web Interface (MapReduce layer)
The JobTracker web UI provides information about general job statistics of the Hadoop cluster, running/completed/failed jobs and a job history log file. It also gives access to the ‘‘local machine’s’’ Hadoop log files (the machine on which the web UI is running on).
By default, it’s available at http://localhost:50030/.
TaskTracker Web Interface (MapReduce layer)
The task tracker web UI shows you running and non-running tasks. It also gives access to the ‘‘local machine’s’’ Hadoop log files.
By default, it’s available at http://localhost:50060/.
What’s next?
If you’re feeling comfortable, you can continue your Hadoop experience with my follow-up tutorial Running Hadoop On Ubuntu Linux (Multi-Node Cluster) where I describe how to build a Hadoop ‘‘multi-node’’ cluster with two Ubuntu boxes (this will increase your current cluster size by 100%, heh).
In addition, I wrote a tutorial on how to code a simple MapReduce job in the Python programming language which can serve as the basis for writing your own MapReduce programs.
Related Links
From yours truly:
From other people:
- How to debug MapReduce programs
- Hadoop API Overview (for Hadoop 2.x)
Change Log
Only important changes to this article are listed here:
- 2011-07-17: Renamed the Hadoop user from
hadoop
tohduser
based on readers’ feedback. This should make the distinction between the local Hadoop user (nowhduser
), the local Hadoop group (hadoop
), and the Hadoop CLI tool (hadoop
) more clear.
(转)单机上配置hadoop的更多相关文章
- 在MacOs上配置Hadoop和Spark环境
在MacOs上配置hadoop和spark环境 Setting up Hadoop with Spark on MacOs Instructions 准备环境 如果没有brew,先google怎样安装 ...
- mac上eclipse上配置hadoop
在mac上安装了eclipse之后,配置hadoop其实跟在linux上配置差不多,只是mac上得eclipse和界面和linux上得有点不同. 一:安装eclipse eclipse得安装比较简单, ...
- Hadoop完全分布式环境搭建(四)——基于Ubuntu16.04安装和配置Hadoop大数据环境
[系统环境] [安装配置概要] 1.上传hadoop安装文件到主节点机器 2.给文件夹设置权限 3.解压 4.拷贝到目标文件夹 放在/opt文件夹下,目录结构:/opt/hadoop/hadoop-2 ...
- Hadoop单机模式安装-(3)安装和配置Hadoop
网络上关于如何单机模式安装Hadoop的文章很多,按照其步骤走下来多数都失败,按照其操作弯路走过了不少但终究还是把问题都解决了,所以顺便自己详细记录下完整的安装过程. 此篇主要介绍在Ubuntu安装完 ...
- Ubuntu 14.04 (32位)上搭建Hadoop 2.5.1单机和伪分布式环境
引言 一直用的Ubuntu 32位系统(准备下次用Fedora,Ubuntu越来越不适合学习了),今天准备学习一下Hadoop,结果下载Apache官网上发布的最新的封装好的2.5.1版,配置完了根本 ...
- Ubuntu上搭建Hadoop环境(单机模式+伪分布模式)
首先要了解一下Hadoop的运行模式: 单机模式(standalone) 单机模式是Hadoop的默认模式.当首次解压Hadoop的源码包时,Hadoop无法了解硬件安装环境,便保守地选 ...
- 沉淀,再出发——在Ubuntu Kylin15.04中配置Hadoop单机/伪分布式系统经验分享
在Ubuntu Kylin15.04中配置Hadoop单机/伪分布式系统经验分享 一.工作准备 首先,明确工作的重心,在Ubuntu Kylin15.04中配置Hadoop集群,这里我是用的双系统中的 ...
- Ubuntu上搭建Hadoop环境(单机模式+伪分布模式) (转载)
Hadoop在处理海量数据分析方面具有独天优势.今天花了在自己的Linux上搭建了伪分布模式,期间经历很多曲折,现在将经验总结如下. 首先,了解Hadoop的三种安装模式: 1. 单机模式. 单机模式 ...
- Ubuntu上搭建Hadoop环境(单机模式+伪分布模式)【转】
[转自:]http://blog.csdn.net/hitwengqi/article/details/8008203 最近一直在自学Hadoop,今天花点时间搭建一个开发环境,并整理成文. 首先要了 ...
随机推荐
- Python判断是否是数字(无法判断浮点数)(已解决)
s为字符串s.isalnum() 所有字符都是数字或者字母s.isalpha() 所有字符都是字母s.isdigit() 所有字符都是数字s.islower() 所有字符都是小写s.isupper() ...
- Linux ls -l内容详解
ls -l是列出当前目录下所有文件信息 以下是实例: 具体的文字描述如下: 第1字段: 文件属性字段文件属性字段总共有10个字母组成,第一个字母表示文件类型,如果这个字母是一个减号”-”,则说明该文 ...
- window7部署solr 4.7
环境:win7 + tomcat 7.0.50 + solr 4.7 备注:C:\solr-4.7.0为solr.zip解压后的目录 C:\apache-tomcat-7.0.50为tomcat目录 ...
- 6月24日AppCan移动开发者大会礼品清单遭泄露
6月24日,第一届AppCan移动开发者大会将在北京国际会议中心举办,大会以”平台之上,应用无限”为主题,全景展现移动应用发展趋势.AppCan 移动技术蓝图及80万开发者的技术实践成果. 大会现场礼 ...
- iOS学习之基础控件
一.UILabel 1.UILabel(标签):是显示文本的空间.在App中UILabel是出现频率最高的控件. 2.UILabel是UIView的子类,作为子类一般是为了扩充父类 ...
- Swift弹窗
在一个ViewController中使用以下代码: let alertController = UIAlertController(title: "Game Set", messa ...
- Entity Framework 学习第一天 续
改写第一天的增删改查方法,观察增删改查的本质 using System; using System.Collections.Generic; using System.Data.Entity.Infr ...
- Sharepoint 2010 RBS 的安装和配置
基本上按照微软官方的配置方法配置就行了. 给下地址:微软官方 涂大神 找RBS的安装文件也是个问题,微软的链接好像失效了.我使用的是RBS下载.这里也有. 我的环境是数据库两台故障群集转移,微 ...
- UITableView swift
// // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...
- activemq整合spring