一、配置集群
1.配置hadoop-env.sh
Linux系统中获取jdk的安装路径:
[root@ hadoop101 ~]# echo $JAVA_HOME
/opt/module/jdk1.7.0_79
修改JAVA_HOME 路径:
export JAVA_HOME=/opt/module/jdk1.7.0_79
2.配置core-site.xml
<!-- 指定HDFS中NameNode的地址 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop101:9000</value>
</property>
<!-- 指定hadoop运行时产生文件的存储目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/module/hadoop-2.7.2/data/tmp</value>
</property>
3.配置hdfs-site.xml
<!-- 指定HDFS副本的数量 -->
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
二、启动集群
- 格式化namenode(第一次启动时格式化,以后就不要总格式化)
bin/hdfs namenode -format
sbin/hadoop-daemon.sh start namenode
sbin/hadoop-daemon.sh start datanode
三、查看集群
[root@hadoop101 ~]# jps
13586 NameNode
13668 DataNode
13786 Jps
- 查看产生的log日志
当前目录:/opt/module/hadoop-2.7.2/logs
[root@hadoop101 logs]# ls
hadoop-root-datanode-hadoop.honey.com.log
hadoop-root-datanode-hadoop.honey.com.out
hadoop-root-namenode-hadoop.honey.com.log
hadoop-root-namenode-hadoop.honey.com.out
SecurityAuth-root.audit
[root@hadoop101 logs]# cat hadoop-root-datanode-hadoop.honey.com.log
四、操作集群
bin/hdfs dfs -mkdir -p /user/honey/mapreduce/wordcount/input
或者
hadoop fs -mkdir -p /user/honey/mapreduce/wordcount/input
bin/hdfs dfs -put wcinput/wc.input /user/honey/mapreduce/wordcount/input/
或者
hadoop fs -put wcinput/wc.input /user/honey/mapreduce/wordcount/input/
bin/hdfs dfs -ls /user/honey/mapreduce/wordcount/input/
bin/hdfs dfs -cat /user/honey/mapreduce/wordcount/input/wc.input
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /user/honey/mapreduce/wordcount/input/ /user/honey/mapreduce/wordcount/output
bin/hdfs dfs -cat /user/honey/mapreduce/wordcount/output/*
或者
hadoop fs -cat /user/honey/mapreduce/wordcount/output/*
hadoop fs -get /user/honey/mapreduce/wordcount/output/part-r-00000 ./wcoutput/
hdfs dfs -rm -r /user/honey/mapreduce/wordcount/output
或者
hadoop fs -rm -r /user/honey/mapreduce/wordcount/output
五、其他操作
sbin/hadoop-daemon.sh stop datanode
sbin/hadoop-daemon.sh stop namenode