0
点赞
收藏
分享

微信扫一扫

跟我一起hadoop(1)-hadoop2.6安装与使用

左小米z 2022-03-30 阅读 77


伪分布式

hadoop的三种安装方式:

  • ​​Local (Standalone) Mode​​
  • ​​Pseudo-Distributed Mode​​
  • ​​Fully-Distributed Mode​​

安装之前需要

$ sudo apt-get install ssh

     $ sudo apt-get install rsync

详见:​​http://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/SingleCluster.html​​

伪分布式配置

Configuration

修改下边:

etc/hadoop/core-site.xml:

<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>

etc/hadoop/hdfs-site.xml:

<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
配置ssh
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
如果想运行在yarn上
需要执行下边的步骤:
  1. Configure parameters as follows:
  2. etc/hadoop/mapred-site.xml:

    <configuration>
    <property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
    </property>
    </configuration>

    etc/hadoop/yarn-site.xml:

    <configuration>
    <property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
    </property>
    </configuration>
  3. Start ResourceManager daemon and NodeManager daemon:
  4. $ sbin/start-yarn.sh
  5. Browse the web interface for the ResourceManager; by default it is available at:
  • ResourceManager - http://localhost:8088/
  1. Run a MapReduce job.
  2. When you're done, stop the daemons with:
  3. $ sbin/stop-yarn.sh

输入:

​​http://localhost:8088/​​

可以看到

跟我一起hadoop(1)-hadoop2.6安装与使用_hadoop​​

启动yarn后

  1. Format the filesystem:
  2. $ bin/hdfs namenode -format
  3. Start NameNode daemon and DataNode daemon:
  4. $ sbin/start-dfs.sh

    The hadoop daemon log output is written to the $HADOOP_LOG_DIR directory (defaults to $HADOOP_HOME/logs).

  5. Browse the web interface for the NameNode; by default it is available at:
  • NameNode -​​http://localhost:50070/​​

输入后得到:

跟我一起hadoop(1)-hadoop2.6安装与使用_hadoop_02​​

然后执行测试

  1. Make the HDFS directories required to execute MapReduce jobs:
  2. $ bin/hdfs dfs -mkdir /user
    $ bin/hdfs dfs -mkdir /user/<username>
  3. Copy the input files into the distributed filesystem:
  4. $ bin/hdfs dfs -put etc/hadoop input
  5. Run some of the examples provided:
  6. $ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0.jar grep input output 'dfs[a-z.]+'
  7. Examine the output files:
  8. Copy the output files from the distributed filesystem to the local filesystem and examine them:

    $ bin/hdfs dfs -get output output
    $ cat output/*

    or

    View the output files on the distributed filesystem:

    $ bin/hdfs dfs -cat output/*

看运行的情况:

跟我一起hadoop(1)-hadoop2.6安装与使用_hadoop_03​​

查看结果

跟我一起hadoop(1)-hadoop2.6安装与使用_apache_04​​

测试执行成功,可以编写本地代码了。

eclipse hadoop2.6插件使用

下载源码:

git clone https://github.com/winghc/hadoop2x-eclipse-plugin.git


下载过程:

跟我一起hadoop(1)-hadoop2.6安装与使用_java_05​​

编译插件:

cd src/contrib/eclipse-plugin
ant jar -Dversion=2.6.0 -Declipse.home=/usr/local/eclipse -Dhadoop.home=/usr/local/hadoop-2.6.0  //路径根据自己的配置​跟我一起hadoop(1)-hadoop2.6安装与使用_hadoop_06​​

  • 复制编译好的jar到eclipse插件目录,重启eclipse
  • 配置 hadoop 安装目录

遇到异常


Exception in thread "main" org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory hdfs://localhost:9000/output already exists
at org.apache.hadoop.mapred.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:132)
at org.apache.hadoop.mapreduce.JobSubmitter.checkSpecs(JobSubmitter.java:564)
at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:432)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1296)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1293)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:1293)
at org.apache.hadoop.mapred.JobClient$1.run(JobClient.java:562)
at org.apache.hadoop.mapred.JobClient$1.run(JobClient.java:557)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:557)
at org.apache.hadoop.mapred.JobClient.submitJob(JobClient.java:548)
at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:833)
at com.zongtui.WordCount.main(WordCount.java:83)


1、改变输出路径。

2、删除重新建。

运行完成后看结果:

跟我一起hadoop(1)-hadoop2.6安装与使用_apache_09​​


作者:​​张锋​​

本文版权归作者,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。

更多精彩文章可以观注

微信公众号 跟我一起hadoop(1)-hadoop2.6安装与使用_众推_10

举报

相关推荐

0 条评论