准备工作:

1.一台Linux机器【windows也支持,参考:https://cwiki.apache.org/confluence/display/HADOOP2/Hadoop2OnWindows】

2.安装JDK

3.安装Hadoop

4.ssh免密码登陆配置

本地运行模式操作过程:【参考:https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/SingleCluster.html#Standalone_Operation】

本地运行模式使用场景:

By default, Hadoop is configured to run in a non-distributed mode, as a single Java process. This is useful for debugging.

本地无配置运行grep程序:

bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.1.jar grep input output 'dfs[a-z.]+'
报错:
[atguigu@hadoop104 hadoop-2.7.2]$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar grep input ouput 'dfs[a-z.]+'
20/08/31 23:29:27 INFO client.RMProxy: Connecting to ResourceManager at hadoop102/192.168.59.102:8032
java.net.NoRouteToHostException: No Route to Host from  hadoop104/192.168.59.104 to hadoop101:9000 failed on socket timeout exception: java.net.NoRouteToHostException: No route to host; For more details see:  http://wiki.apache.org/hadoop/NoRouteToHostat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:423)at org.apache.hadoop.net.NetUtils.wrapWithMessage(NetUtils.java:792)at org.apache.hadoop.net.NetUtils.wrapException(NetUtils.java:758)at org.apache.hadoop.ipc.Client.call(Client.java:1479)at org.apache.hadoop.ipc.Client.call(Client.java:1412)at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:229)at com.sun.proxy.$Proxy9.delete(Unknown Source)at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.delete(ClientNamenodeProtocolTranslatorPB.java:540)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:191)at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)at com.sun.proxy.$Proxy10.delete(Unknown Source)at org.apache.hadoop.hdfs.DFSClient.delete(DFSClient.java:2044)at org.apache.hadoop.hdfs.DistributedFileSystem$14.doCall(DistributedFileSystem.java:707)at org.apache.hadoop.hdfs.DistributedFileSystem$14.doCall(DistributedFileSystem.java:703)at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)at org.apache.hadoop.hdfs.DistributedFileSystem.delete(DistributedFileSystem.java:703)at org.apache.hadoop.examples.Grep.run(Grep.java:97)at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)at org.apache.hadoop.examples.Grep.main(Grep.java:103)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:71)at org.apache.hadoop.util.ProgramDriver.run(ProgramDriver.java:144)at org.apache.hadoop.examples.ExampleDriver.main(ExampleDriver.java:74)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.hadoop.util.RunJar.run(RunJar.java:221)at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.net.NoRouteToHostException: No route to hostat sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:531)at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:495)at org.apache.hadoop.ipc.Client$Connection.setupConnection(Client.java:614)at org.apache.hadoop.ipc.Client$Connection.setupIOstreams(Client.java:712)at org.apache.hadoop.ipc.Client$Connection.access$2900(Client.java:375)at org.apache.hadoop.ipc.Client.getConnection(Client.java:1528)at org.apache.hadoop.ipc.Client.call(Client.java:1451)... 32 more
修改core-site.xml中的配置<property>
<name>fs.defaultFS</name><value>hdfs://hadoop104:9000</value>
</property>
还报错:
java.net.ConnectException: Call From hadoop104/192.168.59.104 to hadoop104:9000 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefusedat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.lang.reflect.Constructor.newInstance(Constructor.java:423)at org.apache.hadoop.net.NetUtils.wrapWithMessage(NetUtils.java:792)at org.apache.hadoop.net.NetUtils.wrapException(NetUtils.java:732)at org.apache.hadoop.ipc.Client.call(Client.java:1479)at org.apache.hadoop.ipc.Client.call(Client.java:1412)at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:229)at com.sun.proxy.$Proxy9.delete(Unknown Source)at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.delete(ClientNamenodeProtocolTranslatorPB.java:540)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:191)at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)at com.sun.proxy.$Proxy10.delete(Unknown Source)at org.apache.hadoop.hdfs.DFSClient.delete(DFSClient.java:2044)at org.apache.hadoop.hdfs.DistributedFileSystem$14.doCall(DistributedFileSystem.java:707)at org.apache.hadoop.hdfs.DistributedFileSystem$14.doCall(DistributedFileSystem.java:703)at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)at org.apache.hadoop.hdfs.DistributedFileSystem.delete(DistributedFileSystem.java:703)at org.apache.hadoop.examples.Grep.run(Grep.java:97)at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)at org.apache.hadoop.examples.Grep.main(Grep.java:103)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:71)at org.apache.hadoop.util.ProgramDriver.run(ProgramDriver.java:144)at org.apache.hadoop.examples.ExampleDriver.main(ExampleDriver.java:74)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.apache.hadoop.util.RunJar.run(RunJar.java:221)at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.net.ConnectException: Connection refusedat sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:531)at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:495)at org.apache.hadoop.ipc.Client$Connection.setupConnection(Client.java:614)at org.apache.hadoop.ipc.Client$Connection.setupIOstreams(Client.java:712)at org.apache.hadoop.ipc.Client$Connection.access$2900(Client.java:375)at org.apache.hadoop.ipc.Client.getConnection(Client.java:1528)at org.apache.hadoop.ipc.Client.call(Client.java:1451)... 32 more
直接删除掉原来的hadoop,新解压一个【原来有额外的yarn,mapreduce配置】
rm -rf hadoop-2.7.2
tar -zxvf hadoop-2.7.2.tar.gz -C /opt/module/【可以多次执行,会覆盖掉】
echo $JAVA_HOME
运行grep后,输入jps有如下进程:
jps
RunJar(程序执行完就没了)

伪分布式运行模式:

修改配置文件:

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 localhost
报错:
ssh: Could not resolve hostname localhost: Name or service not known
在/etc/hosts中添加:
localhost 127.0.0.1
然后source /etc/profile--免密码操作
$ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 0600 ~/.ssh/authorized_keys【这一步很关键,否则还得要密码】

Hadoop常见命令:

1.Run a MapReduce job locally
1)格式化hdfs
$ bin/hdfs namenode -format【直接输入bin/hdfs回车会提示后面所有的命令参数】
2)启动hdfs
$ sbin/start-dfs.sh
执行jps,有如下进程:
3585 Jps
3465 DataNode
3357 NameNode
3534 GetConf(启动过程中有,启动完成就没了)
SecondaryNameNode
3)访问namnode:http://localhost:9870/【无法访问】
2.x是访问50070,
3.x访问的是9870。【看的文档是最新的,是3.x版的】
linux确认是否可以访问:curl 'localhost:50070'
windows访问:localhost得换为linux ip【如果用linux主机名,需要在windows hosts文件中添加映射】
4)dfs常用命令
$ bin/hdfs dfs -mkdir /user
$ bin/hdfs dfs -mkdir /user/<username>
$ bin/hdfs dfs -mkdir input
$ bin/hdfs dfs -put etc/hadoop/*.xml input
$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.1.jar grep input output 'dfs[a-z.]+'【修改完配置文件,启动namenode,默认运行的是hdfs目录文件】
执行grep命令警告:
20/09/01 00:24:31 WARN io.ReadaheadPool: Failed readahead on ifile
EBADF: Bad file descriptorat org.apache.hadoop.io.nativeio.NativeIO$POSIX.posix_fadvise(Native Method)at org.apache.hadoop.io.nativeio.NativeIO$POSIX.posixFadviseIfPossible(NativeIO.java:267)at org.apache.hadoop.io.nativeio.NativeIO$POSIX$CacheManipulator.posixFadviseIfPossible(NativeIO.java:146)at org.apache.hadoop.io.ReadaheadPool$ReadaheadRequestImpl.run(ReadaheadPool.java:206)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
应该与grep运行参数中的路径写法有关:
hadoop jar /opt/module/hadoop-2.7.2/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar grep /input /output 'dfs[a-z.]+'

备注:

1.Hadoop官方文档写的是真的好【推荐操作直接按照官方文档来,会少走很多弯路】

2.SecureCRT楷体中文平躺

切换为宋体即可

3.hdfs文件系统命令行操作的时候,比如我现在在/,再输入input,其实全路径是/input,也有相对路径和绝对路径之分

20200903-03-Hadoop运行模式之本地运行模式伪分布式运行模式相关推荐

  1. Hadoop运行模式 之 伪分布式运行模式

    什么是伪分布式模式?它与本地运行模式以及完全分布式模式有什么区别? 伪分布式的配置信息,完全是按照完全分布式的模式去搭建的,但是它只有一台服务器,可以用于学习和测试,真正的开发中不可以使用. 目录 一 ...

  2. Hadoop安装教4程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.0

    Hadoop安装教4程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.0 当开始着手实践 Hadoop 时,安装 Hadoop 往往会成为新手的一道门槛.尽管安装其实很简单,书上有写到 ...

  3. HADOOP实战——蔬菜价格统计(win10伪分布式环境)

    一.环境搭建与配置 采用Hadoop-3.2.2+伪分布式环境,在win10操作系统下利用idea进行代码的编写,其中使用maven进行环境配置. 1.配置pom.xml <?xml versi ...

  4. 《Hadoop系列》脚本开发自动化配置伪分布式Hadoop

    shell脚本配置伪分布式Hadoop 一 hadoop安装 install_hadoop.sh ## !/bin/bash## 安装jdk ./install_java.sh ##安装前的路径 IN ...

  5. Hadoop伪分布式运行案例

    写在前面: 我的博客已迁移至自建服务器:博客传送门,CSDN博客暂时停止,如有机器学习方面的兴趣,欢迎来看一看. 此外目前我在gitHub上准备一些李航的<统计学习方法>的实现算法,目标将 ...

  6. day70-大数据之Hadoop部署1(单机部署与伪分布式部署)

    大数据基础平台实施及运维 一.大数据介绍 学习目标 能够了解为什么使用大数据技术 能够了解大数据指的是什么 1. 为什么使用大数据技术? 数据量越来越大 数据分析的实时性越来越强 数据结果的应用越来越 ...

  7. Hadoop 的三种运行模式_本地模式_伪分布式模式

    演示的版本是:2.7.2 官方文档 Hadoop运行模式 Hadoop运行模式包括:本地模式.伪分布式模式以及完全分布式模式. Hadoop官方网站:http://hadoop.apache.org/ ...

  8. Nutch 分布式运行模式 (v1.14)

    Nutch 1.x 是成熟的产品级 web 爬虫,这个分支通过精细的优化配制,充分利用了具有非常强大的批处理能力的Apache Hadoop数据结构.目前该分支最新版本是 2017 年12月23日发布 ...

  9. Hadoop系列之九:Hadoop集群伪分布式模式的实现详解

    1.Hadoop依赖软件 Hadoop基于Java语言开发,因此其运行严重依赖于JDK(Java Development Kit),并且Hadoop的许多功能依赖于Java 6及以后的版本才提供的特性 ...

最新文章

  1. 关于char(M)和varchar(N)的区别
  2. php扩展xdebug基本使用
  3. ubuntu su进入root权限
  4. linux php-fpm优化 php-fpm.conf 重要参数详解
  5. Winform中使用FileStream读取文件后,继续操作提示:it is being used by anothor process
  6. Android studio中git密码记住的问题
  7. wireshark解析rtp协议,流媒体中的AMR/H263/H264包的方法
  8. 离线安装pytorch-gpu
  9. 查看本机装的 JDK 是32位还是64位的
  10. 【Amaple教程】4. 组件
  11. 基于snowflake的序列号生成器
  12. 985高校90后博导,7篇一作论文他引过百!想培养更多的“雷军”
  13. 闵梓轩大佬のnoip模拟题D1 总结 2017/10/26
  14. vue构建pc端项目(ElementUI)、vue入门小应用
  15. DM8数据库入门学习总结
  16. LeetCode刷题之575.分糖果
  17. qt invalid use of incomplete type class QDebug
  18. html页面漏斗图,漏斗图 | JShare
  19. 单片机课程设计温控风扇(源代码+Proteus仿真图)
  20. android相机拍照

热门文章

  1. php不能撤销,word2010突然无法撤销怎么解决
  2. 2021年金属非金属矿山支柱考试题库及金属非金属矿山支柱找解析
  3. 团队的英文翻译缩写_动漫团队名称-团队英文名称~~人数不限的、 最好是** – 手机爱问...
  4. 为什么我星际争霸画面是窗口_为什么我喜欢看全球星际联盟
  5. UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb5 in position 2: invalid start byte
  6. 数据分析 学习小结记录
  7. 《数学之美》读后感与商榷
  8. 如何区分加密、压缩、编码?
  9. u盘启动会进入w ndows安装程序,将Windows装进U盘中,随身携带Windows系统
  10. 【Python 实战基础】Pandas如何统筛选复制某个数据