安装
代码语言:javascript复制brew install hadoop
Linux用户可以直接下载tar包,解压运行 https://apache.claz.org/hadoop/common/hadoop-3.3.0/hadoop-3.3.0.tar.gz
配置本地登陆
代码语言:javascript复制cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys
**系统配置(仅Mac需要) 系统->共享里的:
配置hadoop四个文件
hadoop-env.sh
添加java home
代码语言:javascript复制export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
mapred-site.xml
添加
代码语言:javascript复制<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9010</value>
</property>
</configuration>
hdfs-site.xml
添加
代码语言:javascript复制<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
yarn-site.xml(修改告警阀值,默认95%,非必须)
添加
代码语言:javascript复制<property>
<name>yarn.nodemanager.disk-health-checker.max-disk-utilization-per-disk-percentage</name>
<value>98.0</value>
</property>
core-site.xml
添加
代码语言:javascript复制<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/Cellar/hadoop/3.3.0/data/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
初始化namenode
代码语言:javascript复制hadoop namenode -format
启动
代码语言:javascript复制/usr/local/Cellar/hadoop/3.3.0/sbin/start-all.sh
查看(node,yarn) http://localhost:8042/node http://localhost:9870/
应用
创建目录和文件
代码语言:javascript复制hadoop fs -mkdir -p /input
echo 'hello word' > word.txt
hadoop fs -put word.txt /input/
使用hadoop 示例: 统计文件中word的数量
代码语言:javascript复制hadoop jar /usr/local/Cellar/hadoop/3.3.0/libexec/share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-3.3.0-sources.jar org.apache.hadoop.examples.WordCount /input/word.txt /input/out/word-out
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100323.html原文链接: