||
1 现准备好环境 (虽然也能在windows上运行,但官方建议用linux,我的系统是Mac OS X)
设置好JAVA_HOME 看了下我的set
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
是1.6的jdk
2 下载hadoop
现在hadoop分裂成好多个子项目了。叫 common(核心core),HBase,HDFS,Hive,Pig,MapRdeuce等。本次我下载的hadoop common的
http://labs.renren.com/apache-mirror/hadoop/core/
3解压 tar jxvf hadoop-0.20.2.tar.gz
cd hadoop-0.20.2
然后执行bin/hadoop 有输出,就说明是OK的了。
Hadoop 有三种支持模式:
Now you are ready to start your Hadoop cluster in one of the three supported modes:
默认情况下,Hadoop 是配置成没有分布式模式,作为单个Java进程运行的。对开发调式比较有用。
下面的例子是拷贝了conf目录的xml文件到input目录。来查找并显示符合表达式的内容
$ mkdir input
$ cp conf/*.xml input
$ bin/hadoop jar hadoop-*-examples.jar grep input output 'dfs[a-z.]+'
$ cat output/*
Hadoop 还能够运行在一个单节点的模拟分布式模式下,运行在分开的Java进程下。
配置修改下面的配置文件,加上:
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> |
检查你的localhost 登录,要能看到不用密码登录。
$ ssh localhost
发现的我的Mac OS X 还没有装ssh 服务,呵呵,这个安装在Mac下很容易:
$sudo port install openssh #使用MacPort 安装这些开源软件,自动解决包依赖,编译源码,安装。
下面的方法是配置不需要密钥登录:
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
格式化一个新的分布式文件系统:
$ bin/hadoop namenode -format
启动 hadoop 后台进程:
$ bin/start-all.sh
hadoop 后台进程日志会写到 ${HADOOP_LOG_DIR} 目录 (默认是${HADOOP_HOME}/logs).
可以通过浏览器访问 NameNode 和 JobTracker;
拷贝 input 文件到分布式文件系统:
$ bin/hadoop fs -put conf input
运行上面的例子:
$ bin/hadoop jar hadoop-*-examples.jar grep input output 'dfs[a-z.]+'
检查下输出文件:
从分布式文件系统从拷贝output 文件到本地的文件系统,并检查:
$ bin/hadoop fs -get output output
$ cat output/*
或
在分布式文件系统上查看output 文件:
$ bin/hadoop fs -cat output/*
关闭后台进程:
$ bin/stop-all.sh
C真正-分布式模式第三种真正的分布式环境,需要配置多台linux服务器,或用虚拟机来代替,等下次再来整理。