五 伪分布式模式操作使用
在单台机子上Hadoop通过运行多个java后台进程来实现伪分布式。
1 依次编辑配置文件,并按照下面的内容进行设置:
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>
2 配置SSH客户端不需要输入密码登陆
如果你执行以下命令:
$sshlocalhost
成果,则不需要配置,否则需要配置,配置命令如下:
$ssh-keygen -t dsa -P''-f ~/.ssh/id_dsa
$cat~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
3 执行命令
格式化hadoop文件系统:
$ bin/hadoopnamenode -format
启动hadoop后台实例:
$ bin/start-all.sh
hadoop实例日志在${HADOOP_LOG_DIR}目录中(默认为${HADOOP_HOME}/logs)
通过浏览器来查看hadoop的命名节点(NameNode)和作业追踪器(JobTracker),默认的地址为:
NameNode - http://localhost:50070/
JobTracker - http://localhost:50030/
将输入文件拷贝到hadoop分布式文件系统上:
$ bin/hadoopfs -put conf input
执行命令:
$ bin/hadoopjar hadoop-examples-*.jargrepinput output'dfs[a-z.]+'
将输出文件拷贝到本地文件系统并查看输出内容:
$ bin/hadoopfs -get output output
$catoutput/*
或者,你可以直接在分布式文件系统上查看输出文件内容:
$ bin/hadoopfs -catoutput/*
测试完成以后,停止hadoop集群命令:
$ bin/stop-all.sh
更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13
