ubuntu 11配置hadoop

   最近没事,研究下ubuntu 配置hadoop!

   ubuntu版本:64 bit   11.04

   hadoop版本: hadoop1.2.1

一、在Ubuntu下创建hadoop用户组和用户;

1. 创建hadoop用户组;

sudo addgroup hadoop

2. 创建hadoop用户;

sudo adduser -ingroup hadoop hadoop

3. 给hadoop用户添加权限,打开/etc/sudoers文件;

sudo gedit /etc/sudoers

按回车键后就会打开/etc/sudoers文件了,给hadoop用户赋予root用户同样的权限。

在root   ALL=(ALL:ALL)   ALL下添加

hadoop   ALL=(ALL:ALL)  ALL


二、在Ubuntu下安装JDK

下载适合自己系统的jdk并配置JAVA环境变量,

http://blog.csdn.net/wei_ge163/article/details/8060534


三、安装ssh服务 

sudo apt-get install ssh openssh-server

四、建立ssh无密码登录本机
1.换成hadoop用户
su - hadoop

2.创建ssh-key
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys  //将id_rsa.pub追加到authorized_keys授权文件
chmod 777 ~/.ssh/authorized_keys    
scp ~/.ssh/id_rsa.pub hadoop@localhost:~/

3.登录localhost;
ssh localhost
( 注:当ssh远程登录到其它机器后,现在你控制的是远程的机器,需要执行退出命令才能重新控制本地主机。)

4.执行退出命令;
exit

五、安装hadoop

我们采用的hadoop版本是:hadoop-1.2.1(http://www.apache.org/dyn/closer.cgi/hadoop/common/
1.假设hadoop-1.2.1.tar.gz在/work,将它复制到安装目录 /usr/local/下;    
sudo cp hadoop-1.2.1.tar.gz /usr/local/
2.解压hadoop-0.20.203.tar.gz;
cd /usr/local
sudo tar -zxf hadoop-1.2.1.tar.gz
3. 将解压出的文件夹改名为hadoop;
sudo mv hadoop-1.2.1 hadoop
4.将该hadoop文件夹的属主用户设为hadoop,
sudo chown -R hadoop:hadoop hadoop
5.打开hadoop/conf/hadoop-env.sh文件;    
sudo gedit hadoop/conf/hadoop-env.sh

6.配置conf/hadoop-env.sh(找到#export JAVA_HOME=...,去掉#,然后加上本机jdk的路径);
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk

7.打开conf/core-site.xml文件;
sudo gedit hadoop/conf/core-site.xml
编辑如下:property后面需要手工敲    
<?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>

8. 打开conf/mapred-site.xml文件;
sudo gedit hadoop/conf/mapred-site.xml
编辑如下property后面需要手工敲:    
<?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>

9. 打开conf/hdfs-site.xml文件;    

sudo gedit hadoop/conf/hdfs-site.xml
编辑如下:    
<configuration>
  <property>
    <name>dfs.name.dir</name>
    <value>/usr/local/hadoop/datalog1,/usr/local/hadoop/datalog2</value>
  </property>

  <property>
    <name>dfs.data.dir</name>
    <value>/usr/local/hadoop/data1,/usr/local/hadoop/data2</value>
  </property>

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

10.打开conf/masters文件,添加作为secondarynamenode的主机名,作为单机版环境,这里只需填写 localhost
sudo gedit hadoop/conf/masters

11.打开conf/slaves文件,添加作为slave的主机名,一行一个。作为单机版,这里也只需填写 localhost
sudo gedit hadoop/conf/slaves
 
六、在单机上运行hadoop
1.进入hadoop目录下,格式化hdfs文件系统,初次运行hadoop时一定要有该操作,    
cd /usr/local/hadoop/
bin/hadoop namenode -format
注:可以在/etc/profile中导入如下:
$ export HADOOP_INSTALL=/usr/local/hadoop
$ export PATH=$PATH:$HADOOP_INSTALL/bin

2.启动bin/start-all.sh    
bin/start-all.sh

3.检测hadoop是否启动成功
jps
如果有Namenode,SecondaryNameNode,TaskTracker,DataNode,JobTracker五个进程,就说明你的hadoop单机版环境配置好了,然后可以通过firefox浏览器查看,使用http://localhost:50030/

注意:Hadoop的各组件都可以用xml文件进行配置。
一般配置的话,主要是三个配置文件(全在$HADOOP_INSTALL的conf目录):
    core-site.xml:用于配置Common组件的属。
    hdfs-site.xml:用于配置HDFS的属性,
    HDFS顾名思义Hadoop Distributed File System,Hadoop分布式文件系统。
    mapred-site.xml:用于配置MapReduce属性。

在Hadoop的早期版本中,只有一个配置文件来配置这三项,叫hadoop_site.xml的配置文件,后期开始分为三个,一一对应个组件。属性内容不变,仅仅是分开。
另外,在docs目录中还有对应的三个html文件,分别保存着各组件的默认设置。

Hadoop的三种运行模式:
第一:独立模式(standalone)或者本地模式(local model)
此模式无需守护进程,所有的程序都在单个的虚拟机上运行。
由于在本地模式下测试和调试MapReduce程序很方便,所以一般来说比较适用于开发阶段。
第二:伪分布模式(pseudo-distributed model)
顾名思义,一个模拟的小规模的集群,Hadoop守护进程运行在本地环境中。一般用作测试环境
第三:全分布模式(fully distributed model)
这才是真实的,Hadoop守护进程运行在真正的集群环境。一般作为产品环境。

注:在无论哪个模式下去运行Hadoop都需要关注两个重要因素:
1.是否启动Hadoop守护进程,2.是否已经正确配置各属性。

下面这个表里简单列举了三种模式下的所需的最小属性配置集合:

组件名称

属性名称

独立模式

伪分布模式

全分布模式

Common

fs.default.name

file:///

(默认)

hdfs://localhost/

hdfs://namenode/

HDFS

dfs.replication

N/A

1

3

(默认)

MapReduce

mapred.job.tracker

local

(默认)

localhost:8021

jobtracker:8021

 

三种模式下的配置:

本机模式:

一般Hadoop安装后默认属性就是本地模式(独立模式),所以一般来说,不用进行更多的配置。

三个配置文件内容如下:

-----core-site.xml-----

<?xml version="1.0"?>

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

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

   <configuration>

   </configuration>

<?xml version="1.0"?>

-----mapred-site.xml-----

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

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

<configuration>

</configuration>

-----mapred-site.xml-----

<?xml version="1.0"?>

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

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

<configuration>

</configuration>


伪分布模式:

三个配置配置文件内容如下:

-----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/</value>

   </property>

</configuration>

<?xml version="1.0"?>

-----mapred-site.xml-----

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

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

<configuration>

   <property>

     <name>dfs.replication</name>

     <value>1</value>

   </property>

</configuration>

-----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:8021</value>

   </property>

</configuration>


全分布模式:

三个配置配置文件内容如下:

-----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://namenode/</value>

   </property>

</configuration>

<?xml version="1.0"?>

-----mapred-site.xml-----

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

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

<configuration>

   <property>

     <name>dfs.replication</name>

     <value>3</value>

   </property>

</configuration>

-----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>jobtracker:8021 </value>

   </property>

</configuration>

参考:http://www.cnblogs.com/tippoint/archive/2012/10/23/2735532.html

http://www.cnblogs.com/shannyn/archive/2013/08/28/3287443.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值