Hadoop学起来分布式Hadoop的搭建(Ubuntu 17.04)

Posted 工科狗和生物喵

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hadoop学起来分布式Hadoop的搭建(Ubuntu 17.04)相关的知识,希望对你有一定的参考价值。

正文之前

作为一个以后肯定要做大数据的人,至今还没玩过Java 和 Hadoop 会不会被老师打死?所以就想着,在我的国外的云主机上搭建个Hadoop ,以后在 dell 电脑的ubuntu系统下也搭建一个,然后还有一台老戴尔可以搭一个,mac也可以搭一个,勉强算是一个分布式集群了?不管了。反正今天先把Hadoop在Ubuntu 17.04 下搭建好吧!

正文

国内的资料都太老了。我就用Google搜了一波,果然好用啊!!

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

之后选择了一个教程: http://www.admintome.com/blog/installing-hadoop-on-ubuntu-17-10/ 下面进入安装环节:

1、 Install required software

 
   
   
 
  1. # apt update && apt upgrade -y

  2. # reboot

  3. # apt install -y openjdk-8-jdk

  4. # apt install ssh pdsh -y

2、 Download Hadoop

 
   
   
 
  1. # wget http://apache.cs.utah.edu/hadoop/common/stable/hadoop-2.8.2.tar.gz

  2. # tar -xzvf hadoop-2.8.2.tar.gz

  3. # cd hadoop-2.8.2/

上面的网址现在好像废了。我找了一些新的,你们自己看条件选择:

http://apache.claz.org/hadoop/common/hadoop-2.8.2/hadoop-2.8.2.tar.gz

http://apache.claz.org/hadoop/common/

下面是下载安装和安装完毕之后的样子:

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

下面进入配置环节:

We need to make some additions to our configuration, so edit the next couple of files with the appropriate contents:

etc/hadoop/hadoop-env.sh

 
   
   
 
  1. export JAVA_HOME=/usr

etc/hadoop/core-site.xml

 
   
   
 
  1. <configuration>

  2.    <property>

  3.        <name>fs.defaultFS</name>

  4.        <value>hdfs://localhost:9000</value>

  5.    </property>

  6. </configuration>

etc/hadoop/hdfs-site.xml

 
   
   
 
  1. <configuration>

  2.    <property>

  3.        <name>dfs.replication</name>

  4.        <value>1</value>

  5.    </property>

  6. </configuration>

Now in order to make the scripts work, we need to setup passwordless SSH to localhost:

 
   
   
 
  1.  $ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

  2.  $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

  3.  $ chmod 0600 ~/.ssh/authorized_keys

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

Format the HDFS filesystem.

 
   
   
 
  1. # bin/hdfs namenode -format

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

And finally, start up HDFS.

 
   
   
 
  1. # sbin/start-dfs.sh

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

After it starts up you can access the web interface for the NameNode at this URL: http://{server-ip}50070 .

因为我的是云主机,所以直接用类似网站的方式也可以进入:

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

Configure YARN

Create the directories we will need for YARN.

 
   
   
 
  1. # bin/hdfs dfs -mkdir /user

  2. # bin/hdfs dfs -mkdir /user/root

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

Edit  etc/hadoop/mapred-site.xml and add the following contents:

 
   
   
 
  1. <configuration>

  2.    <property>

  3.        <name>mapreduce.framework.name</name>

  4.        <value>yarn</value>

  5.    </property>

  6. </configuration>

And edit

etc/hadoop/yarn-site.xml:

 
   
   
 
  1. <property>

  2.        <name>yarn.nodemanager.aux-services</name>

  3.        <value>mapreduce_shuffle</value>

  4.    </property>

  5.    <property>

  6.        <name>yarn.nodemanager.vmem-check-enabled</name>

  7.        <value>false</value>

  8.    </property>

Start YARN:

 
   
   
 
  1. # sbin/start-yarn.sh

如果无法启动,报错如下:

 
   
   
 
  1. root@HustWolfzzb:/home/hustwolf/Hadoop/hadoop-2.8.2# sbin/start-yarn.sh

  2. starting yarn daemons

  3. resourcemanager running as process 16803. Stop it first.

  4. localhost: starting nodemanager, logging to /home/hustwolf/Hadoop/hadoop-2.8.2/logs/yarn-root-nodemanager-HustWolfzzb.out

  5. root@HustWolfzzb:/home/hustwolf/Hadoop/hadoop-2.8.2# kill -9 16803

  6. root@HustWolfzzb:/home/hustwolf/Hadoop/hadoop-2.8.2# sbin/start-yarn.sh

  7. starting yarn daemons

  8. starting resourcemanager, logging to /home/hustwolf/Hadoop/hadoop-2.8.2/logs/yarn-root-resourcemanager-HustWolfzzb.out

  9. localhost: nodemanager running as process 17374. Stop it first.

  10. root@HustWolfzzb:/home/hustwolf/Hadoop/hadoop-2.8.2# ls

那么,先把所有的先关了。方法是到sbin下采用stop脚本,可以直接stop-all.sh 也可以试试stop-dfs.sh stop-yarn.sh 两个搭配。然后再开启一次就ok.

You can now view the web interface at

http://{server-ip}:8088 .

【Hadoop学起来】分布式Hadoop的搭建(Ubuntu 17.04)

Testing our installation

In order to test that everything is working we can run a MapReduce job using YARN:

 
   
   
 
  1. # bin/yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.8.2.jar pi 16 1000

This is going to calculate PI to 16 decimal places for us using the quasiMonteCarlo method. After a minute or two you should get your response:

 
   
   
 
  1. Job Finished in 96.095 seconds

  2. Estimated value of Pi is 3.14250000000000000000

我在这儿遇到了一个很苦恼的问题就是:

 
   
   
 
  1. Number of Maps  = 16

  2. Samples per Map = 1000

  3. 17/11/24 07:49:52 WARN ipc.Client: Failed to connect to server: localhost/127.0.0.1:9000: try once and fail.

  4. java.net.ConnectException: Connection refused

  5.    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

  6.    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)

  7.    at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)

  8.    at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:531)

  9.    at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:495)

  10.    at org.apache.hadoop.ipc.Client$Connection.setupConnection(Client.java:682)

  11.    at org.apache.hadoop.ipc.Client$Connection.setupiostreams(Client.java:778)

  12.    at org.apache.hadoop.ipc.Client$Connection.access$3500(Client.java:410)

  13.    at org.apache.hadoop.ipc.Client.getConnection(Client.java:1544)

  14.    at org.apache.hadoop.ipc.Client.call(Client.java:1375)

  15.    at org.apache.hadoop.ipc.Client.call(Client.java:1339)

  16.    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:227)

  17.    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:116)

  18.    at com.sun.proxy.$Proxy10.getFileInfo(Unknown Source)

  19.    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.getFileInfo(ClientNamenodeProtocolTranslatorPB.java:792)

  20.    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  21.    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

  22.    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  23.    at java.lang.reflect.Method.invoke(Method.java:498)

  24.    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:409)

  25.    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeMethod(RetryInvocationHandler.java:163)

  26.    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invoke(RetryInvocationHandler.java:155)

  27.    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeOnce(RetryInvocationHandler.java:95)

  28.    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:346)

  29.    at com.sun.proxy.$Proxy11.getFileInfo(Unknown Source)

  30.    at org.apache.hadoop.hdfs.DFSClient.getFileInfo(DFSClient.java:1704)

  31.    at org.apache.hadoop.hdfs.DistributedFileSystem$27.doCall(DistributedFileSystem.java:1436)

  32.    at org.apache.hadoop.hdfs.DistributedFileSystem$27.doCall(DistributedFileSystem.java:1433)

  33.    at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)

  34.    at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1433)

  35.    at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:1437)

  36.    at org.apache.hadoop.examples.QuasiMonteCarlo.estimatePi(QuasiMonteCarlo.java:278)

  37.    at org.apache.hadoop.examples.QuasiMonteCarlo.run(QuasiMonteCarlo.java:358)

  38.    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:76)

  39.    at org.apache.hadoop.examples.QuasiMonteCarlo.main(QuasiMonteCarlo.java:367)

  40.    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  41.    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

  42.    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  43.    at java.lang.reflect.Method.invoke(Method.java:498)

  44.    at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:71)

  45.    at org.apache.hadoop.util.ProgramDriver.run(ProgramDriver.java:144)

  46.    at org.apache.hadoop.examples.ExampleDriver.main(ExampleDriver.java:74)

  47.    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  48.    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

  49.    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  50.    at java.lang.reflect.Method.invoke(Method.java:498)

  51.    at org.apache.hadoop.util.RunJar.run(RunJar.java:234)

  52.    at org.apache.hadoop.util.RunJar.main(RunJar.java:148)

  53. java.net.ConnectException: Call From HustWolfzzb/127.0.1.1 to localhost:9000 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused

  54.    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

  55.    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

  56.    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

  57.    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

  58.    at org.apache.hadoop.net.NetUtils.wrapWithMessage(NetUtils.java:801)

  59.    at org.apache.hadoop.net.NetUtils.wrapException(NetUtils.java:732)

  60.    at org.apache.hadoop.ipc.Client.getRpcResponse(Client.java:1487)

  61.    at org.apache.hadoop.ipc.Client.call(Client.java:1429)

  62.    at org.apache.hadoop.ipc.Client.call(Client.java:1339)

  63.    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:227)

  64.    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:116)

  65.    at com.sun.proxy.$Proxy10.getFileInfo(Unknown Source)

  66.    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.getFileInfo(ClientNamenodeProtocolTranslatorPB.java:792)

  67.    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  68.    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

  69.    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  70.    at java.lang.reflect.Method.invoke(Method.java:498)

  71.    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:409)

  72.    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeMethod(RetryInvocationHandler.java:163)

  73.    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invoke(RetryInvocationHandler.java:155)

  74.    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeOnce(RetryInvocationHandler.java:95)

  75.    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:346)

  76.    at com.sun.proxy.$Proxy11.getFileInfo(Unknown Source)

  77.    at org.apache.hadoop.hdfs.DFSClient.getFileInfo(DFSClient.java:1704)

  78.    at org.apache.hadoop.hdfs.DistributedFileSystem$27.doCall(DistributedFileSystem.java:1436)

  79.    at org.apache.hadoop.hdfs.DistributedFileSystem$27.doCall(DistributedFileSystem.java:1433)

  80.    at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)

  81.    at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1433)

  82.    at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:1437)

  83.    at org.apache.hadoop.examples.QuasiMonteCarlo.estimatePi(QuasiMonteCarlo.java:278)

  84.    at org.apache.hadoop.examples.QuasiMonteCarlo.run(QuasiMonteCarlo.java:358)

  85.    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:76)

  86.    at org.apache.hadoop.examples.QuasiMonteCarlo.main(QuasiMonteCarlo.java:367)

  87.    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  88.    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

  89.    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  90.    at java.lang.reflect.Method.invoke(Method.java:498)

  91.    at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:71)

  92.    at org.apache.hadoop.util.ProgramDriver.run(ProgramDriver.java:144)

  93.    at org.apache.hadoop.examples.ExampleDriver.main(ExampleDriver.java:74)

  94.    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  95.    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

  96.    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  97.    at java.lang.reflect.Method.invoke(Method.java:498)

  98.    at org.apache.hadoop.util.RunJar.run(RunJar.java:234)

  99.    at org.apache.hadoop.util.RunJar.main(RunJar.java:148)

  100. Caused by: java.net.ConnectException: Connection refused

  101.    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

  102.    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)

  103.    at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)

  104.    at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:531)

  105.    at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:495)

  106.    at org.apache.hadoop.ipc.Client$Connection.setupConnection(Client.java:682)

  107.    at org.apache.hadoop.ipc.Client$Connection.setupIOstreams(Client.java:778)

  108.    at org.apache.hadoop.ipc.Client$Connection.access$3500(Client.java:410)

  109.    at org.apache.hadoop.ipc.Client.getConnection(Client.java:1544)

  110.    at org.apache.hadoop.ipc.Client.call(Client.java:1375)

  111.    ... 38 more

至今还没解决,不过文章实在没啥好改的了。后续如果有了解决之道,我就在评论区贴出来,或者直接修改文章吧!拜了个拜~ 健身去~~!!

This should be enough to get you started on your Hadoop journey. Subscribe to my newsletter below to get notifications of more Hadoop articles.

I hope you enjoyed this post. If it was helpful or if it was way off then please comment and let me know.

好像成功了???我好像是漏了建立hdfs用户的那一关?然后还有就是重启了一次,以及对于一些东西的缺漏。 不过就在我期待值最高的时候,事实给了我狠狠的一击。好吧,GG。不过还是发现了不少了的有用的教程!!

Hadoop环境安装设置 hadoop 2.7.1安装和配置

正文之后

人家老外英文写的挺好的,我就不多改了。想必就算看不大懂也可以摸索着在百度翻译的帮助下get 到点,实在不行可以发评论问我嘛 而且,命令都给你整好了,难道还不会?不存在的!!


以上是关于Hadoop学起来分布式Hadoop的搭建(Ubuntu 17.04)的主要内容,如果未能解决你的问题,请参考以下文章

Hadoop技术之Apache Hadoop集群搭建

Hadoop学习之八MapReduce开发

Docker搭建Hadoop环境

Hadoop YARN架构组件及其交互流程

Hadoop技术之HDFS分布式文件系统基础

Hadoop MapReduce介绍官方示例及执行流程