0

Hello Hadoop One

:夜深人静读书时……

版本:Hadoop 0.21

内容:配置Hadoop,运行一个MapReduce 示例程序。

参考:点我!

Step 1: 下载

稳定版:点我!

Step 2: 安装

  1. 解压缩你下载Hadoop
  2. 修改conf/hadoop-env.sh 中的JAVA_HOME,必须设置正确

运行
$ bin/hadoop 会看到帮助信息。

Step 3: 单机模式

单机模式对开发和调试非常有用!

以单机模式运行自带的示例程序:

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

Step 4: 伪集群模式

实际上就是运行一个单节点的集群。

修改配置文件

conf/core-site.xml:
<configuration>
     <property>
         <name>fs.default.name</name>
         <value>hdfs://localhost:9000</value>
     </property>
</configuration>

conf/hdfs-site.xml:
<configuration>
     <property>
         <name>dfs.replication</name>
         <value>1</value>
     </property>
</configuration>

conf/mapred-site.xml:
<configuration>
     <property>
         <name>mapred.job.tracker</name>
         <value>localhost:9001</value>
     </property>
</configuration>

免密码SSH 登录

本地需要启动sshd,具体方法略。
使用公钥模式免密码登录:

$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

$ ssh localhost

格式化分布式文件系统

$ bin/hadoop namenode -format

启动Hadoop 守护进程

$ bin/start-dfs.sh
$ bin/start-mapred.sh

Web 监控接口:

  • NameNode – http://localhost:50070/
  • JobTracker – http://localhost:50030/

运行自带示例程序

执行map reduce

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

将结果下载到本地查看

$ bin/hadoop fs -get output output
$ cat output/*

直接在分布式文件系统上查看

$ bin/hadoop fs -cat output/*

关闭节点

$ bin/stop-dfs.sh
$ bin/stop-mapred.sh

- 相关文章:

login with sina weibo