Hadoop之最佳实践

关键字:Hadoop之最佳实践

如今Apache Hadoop已成为大数据行业发展背后的驱动力。Hive和Pig等技术也经常被提到,但是他们都有什么功能,为什么会需要奇怪的名字(如Oozie,ZooKeeper、Flume)。
Hadoop带来了廉价的处理大数据(大数据的数据容量通常是10-100GB或更多,同时数据种类多种多样,包括结构化、非结构化等)的能力。但这与之前有什么不同?
现今企业数据仓库和关系型数据库擅长处理结构化数据,并且可以存储大量的数据。但成本上有些昂贵。这种对数据的要求限制了可处理的数据种类,同时这种惯性所带的缺点还影响到数据仓库在面对海量异构数据时对于敏捷的探索。这通常意味着有价值的数据源在组织内从未被挖掘。这就是Hadoop与传统数据处理方式最大的不同。
本文就重点探讨了Hadoop系统安装配置和简单使用部分!

Hadoop安装之前的准备工作:
1.JAVA1.6.x (sun兼容性更好),1.5.x也OK
2.ssh
安装ssh

$ sudo apt-get install ssh
$ sudo apt-get install rsync


下载Hadoop
从http://hadoop.apache.org/core/releases.html 下载最近发布的版本

最好为hadoop创建一个用户:
比如创建一个group为hadoop user为hadoop的用户以及组

$ sudo addgroup hadoop
$ sudo adduser --ingroup hadoop hadoop

解压下载的hadoop文件,放到/home/hadoop目录下 名字为hadoop
配置JAVA_HOME:

gedit ~/hadoop/conf/hadoop-env.sh



Java代码
# The java implementation to use.  Required.
# export JAVA_HOME=/usr/lib/j2sdk1.5-sun

修改成java的安装目录:(我的是:/usr/lib/jvm/java-6-sun-1.6.0.15)

# The java implementation to use. Required.
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.15


现在可以使用单节点的方式运行:

$ cd hadoop
$ mkdir input
$ cp conf/*.xml input
$ bin/hadoop jar hadoop-*-examples.jar grep input output 'dfs[a-z.]+'
$ cat output/*

Pseudo-distributed方式跑:

配置ssh

$ su - hadoop
$ ssh-keygen -t rsa -P ""
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa):
Created directory '/home/hadoop/.ssh'.
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
9d:47:ab:d7:22:54:f0:f9:b9:3b:64:93:12:75:81:27 hadoop@ubuntu


让其不输入密码就能登录:

hadoop@ubuntu:~$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

  使用:

$ ssh localhost

看看是不是直接ok了。


hadoop配置文件:
conf/core-site.xml

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

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

<configuration>
   <property>
    <name>hadoop.tmp.dir</name>
        <value>/home/hadoop/hadoop-datastore/hadoop-${user.name}</value>
   </property>
   <property>
    <name>fs.default.name</name>
    <value>hdfs://localhost:9000</value>
   </property>
</configuration>

hadoop.tmp.dir配置为你想要的路径,${user.name}会自动扩展为运行hadoop的用户名

conf/hdfs-site.xml

Xml代码
<configuration>
  <property>
    <name>dfs.replication</name>
    <value>1</value>
  </property>
</configuration>

dfs.replication为默认block复制数量
conf/mapred-site.xml

Xml代码
<configuration>
  <property>
    <name>mapred.job.tracker</name>
    <value>localhost:9001</value>
  </property>
</configuration>

执行

格式化分布式文件系统:

$ bin/hadoop namenode -format

启动hadoop:

Java代码
$ bin/start-all.sh

可以从

NameNode - http://localhost:50070/
JobTracker - http://localhost:50030/

查看NameNode和JobTracker

运行例子:


$ bin/hadoop fs -put conf input
$ bin/hadoop jar hadoop-*-examples.jar grep input output 'dfs[a-z.]+'

look at the run result:
$ bin/hadoop fs -get output output
$ cat output/*


大家可参考: 1、http://hadoop.apache.org/common/docs/current/quickstart.html
2、http://www.michael-noll.com/wiki/Running_Hadoop_On_Ubuntu_Linux_%28Single-Node_Cluster%29


欢迎一起交流学习,谢谢大家.......

猜你喜欢

转载自zhaoshijie.iteye.com/blog/1934911