黑猴子的家:Hadoop 伪分布式HDFS运行MapReduce

1、配置集群

和本地模式一样安装

(1) 配置hadoop-env.sh
获取jdk 的安装路径
[victor@node1 hadoop-2.8.2]$ echo $JAVA_HOME
/opt/module/jdk1.8.0_144

修改JAVA_HOME 路径
[victor@node1 hadoop-2.8.2]$ vim etc/hadoop/hadoop-env.sh
export JAVA_HOME=/opt/module/jdk1.8.0_144
(2) 配置:core-site.xml


fs.defaultFS
hdfs://node1:9000




hadoop.tmp.dir
/opt/module/hadoop-2.8.2/data/tmp

(3) 配置:hdfs-site.xml


    dfs.replication
    1

2、启动集群

(1) 格式化namenode(第一次启动时格式化,以后就不要格式化)
[victor@node1 hadoop-2.8.2]$ bin/hdfs namenode -format
(2) 启动namenode
[victor@node1 hadoop-2.8.2]$ sbin/hadoop-daemon.sh start namenode
(3) 启动datanode
[victor@node1 hadoop-2.8.2]$ sbin/hadoop-daemon.sh start datanode

3、 查看集群

(1) 查看是否启动成功
[victor@node1 hadoop-2.8.2]$ jps
13256 NameNode
13278 DataNode
13645 Jps
(2) 查看产生的log日志
[victor@node1 hadoop-2.8.2]$ pwd
/opt/module/hadoop-2.8.2
[victor@node1 hadoop-2.8.2]$ ls logs/
hadoop-victor-datanode-hadoop.victor.com.log
hadoop-victor-datanode-hadoop.victor.com.out
hadoop-victor-namenode-hadoop.victor.com.log
hadoop-victor-namenode-hadoop.victor.com.out
(3) web端浏览器查看HDFS文件系统
http://node1:50070/dfshealth.html#tab-overview

4、操作集群

(1) 在hdfs文件系统上创建一个input文件夹
[victor@node1 hadoop-2.8.2]$ bin/hdfs dfs -mkdir -p /user/victor/wordcount/input
(2) 将测试文件内容上传到文件系统上
[victor@node1 hadoop-2.8.2]$bin/hdfs dfs -put wcinput/wc.input /user/victor/wordcount/input/
(3) 查看上传的文件是否正确
[victor@node1 hadoop-2.8.2]$ bin/hdfs dfs -ls /user/victor/wordcount/input/
[victor@node1 hadoop-2.8.2]$ bin/hdfs dfs -cat /user/victor/wordcount/input/wc.input
(4) 运行mapreduce程序
[victor@node1 hadoop-2.8.2]$bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.8.2.jar wordcount /user/victor/wordcount/input/ /user/victor/wordcount/output
(5) 查看输出结果
命令行查看
[victor@node1 hadoop-2.8.2]$ bin/hdfs dfs -cat /user/victor/wordcount/output/*
(6) 将测试文件内容下载到本地
[victor@node1 hadoop-2.8.2]$ hadoop fs -get /user/victor/wordcount/output/part-r-00000 ./wcoutput/
(7) 删除HDFS上的输出结果
[victor@node1 hadoop-2.8.2]$ hdfs dfs -rmr /user/victor/wordcount/output

你可能感兴趣的:(黑猴子的家:Hadoop 伪分布式HDFS运行MapReduce)