---
title: "hadoop 1.2.1 安装步骤 伪分布式"
author: "xiamizy"
date: "2014-07-28T01:51:37Z"
tags: ["Hadoop", "Java"]
categories: ["企业架构"]
slug: "hadoop-1-2-1"
draft: false
lastmod: "2014-07-28T01:51:37Z"
id: 2097084
url: "https://mitchz.iteye.com/blog/2097084"
---

最近在系统的学习hadoop

课程第一步是安装hadoop1.x，具体安装步骤如下：

一、系统安装

本文使用centos6.5安装，具体安装步骤省略

二、jdk安装

下载jdk1.7.0\_51解压，在环境中

设置环境变量：

vi /etc/profile,添加如下行：

export JAVA\_HOME=/usr/local/jdk1.7.0\_51  
export CLASSPATH=.:$JAVA\_HOME/jre/lib/rt.jar:$JAVA\_HOME/lib/dt.jar:$JAVA\_HOME/lib/tools.jar  
export PATH=$PATH:$JAVA\_HOME/bin

由于在centos下安装，选择需要设置jdk版本

update-alternatives --install /usr/bin/java java /export/home/es/jdk1.7.0\_51/bin/java 60

update-alternatives --config java

![](http://dl2.iteye.com/upload/attachment/0099/5862/bbfd2e2c-8873-3364-a4a0-3adedf38642c.png)  
 

三、linux基本参数设置

设置防火墙：

vi /etc/selinux/config

![](http://dl2.iteye.com/upload/attachment/0099/5864/0e8e69cd-39cb-3e8a-854c-96587b7cb3b9.png)  
 将红框标示部分，设置为disabled

![](http://dl2.iteye.com/upload/attachment/0099/5868/c2693d1f-5e39-35a1-9c67-84fcbba252a9.png)  
 查看防火墙情况，并关闭

```
service iptables status
service ip6tables status
service iptables stop
service ip6tables stop
chkconfig iptables off
chkconfig ip6tables off
```

四，免密码登陆

设置使用免密码登陆方式

![](http://dl2.iteye.com/upload/attachment/0099/5870/107c75e6-1414-32b7-a0d6-d8732f6df4c2.png)  
 

```
vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
```

 将这三个部分的注释去掉，使用RSA验证方式

![](http://dl2.iteye.com/upload/attachment/0099/5872/b4acb7cd-6b70-3247-b3b1-70b40a84d80b.png)  
 生成公钥

```
[hadoop@vm .ssh]$ pwd
/export/home/hadoop/.ssh
[hadoop@vm .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
......
[hadoop@vm .ssh]$ cp id_rsa.pub authorized_keys
[hadoop@vm .ssh]$ ls
authorized_keys  id_rsa  id_rsa.pub
```

 修改hosts文件：

```
[hadoop@vm conf]$ more /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.201 vm.master
192.168.2.202 vm.slave1
192.168.2.203 vm.slave2
```

 修改hostname  
![](http://dl2.iteye.com/upload/attachment/0099/5880/f5a524b0-0070-3812-aa78-7981b0fa4ef3.png)

```
[hadoop@vm etc]$ vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=vm.master
```

 四，修改hadoop配置文件

\[hadoop@vm conf]$ pwd

/export/home/hadoop/hadoop-1.2.1/conf

修改core-site.xml 

![](http://dl2.iteye.com/upload/attachment/0099/5882/e2117910-e5cc-3103-9d8f-c905806620a7.png)  
 

```
[hadoop@vm conf]$ vi core-site.xml 

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

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

 修改hdfs-site.xml

![](http://dl2.iteye.com/upload/attachment/0099/5884/f52476d6-16d0-3105-8b80-a6ff15ec7563.png)  
 

```
[hadoop@vm conf]$ vi hdfs-site.xml 

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
<name>dfs.replications</name>
<value>1</value>
</property>
</configuration>
```

 修改mapred-site.xml  
![](http://dl2.iteye.com/upload/attachment/0099/5886/12f35dd0-add4-3cf5-83c6-aaeb461e71a6.png)  
 

```
[hadoop@vm conf]$ vi mapred-site.xml 

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
</configuration>
```

 设置JAVA\_HOME

![](http://dl2.iteye.com/upload/attachment/0099/5888/2360ab5f-c5d6-3470-84f3-686302138c37.png)

五，尝试启动

format namenode 

![](http://dl2.iteye.com/upload/attachment/0099/5890/78515d25-88d8-3719-bda7-d2c0bdfe54ed.png)  
 

 尝试启动  
   
![](http://dl2.iteye.com/upload/attachment/0099/5892/a74728cb-8446-3b7c-a4e8-e50f28ca28e1.png)  
 搭建完毕