不須要啓用單獨進程,直接能夠運行,測試和開發時使用。html
等同於徹底分佈式,只有一個節點。java
多個節點一塊兒運行。node
1)建立在hadoop-2.7.6文件下面建立一個input文件夾web
[root@master hadoop-2.7.6]# mkdir input瀏覽器
2)將hadoop的xml配置文件複製到inputssh
[root@master hadoop-2.7.6]# cp etc/hadoop/*.xml input分佈式
3)執行share目錄下的mapreduce程序oop
[root@master hadoop-2.7.6]# bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.6.jar grep input output 'dfs[a-z.]+'測試
4)查看輸出結果ui
[root@master src]# cat output/*
1)分析:
(1)準備1臺客戶機
(2)安裝jdk
(3)配置環境變量
(4)安裝hadoop
(5)配置環境變量
(6)配置集羣
(7)啓動、測試集羣增、刪、查
(8)執行wordcount案例
2)執行步驟
須要配置hadoop文件以下
(1)配置集羣
(a)配置:hadoop-env.sh
修改JAVA_HOME 路徑:
export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
(b)配置:core-site.xml
<!-- 指定HDFS中NameNode的地址 --> <property> <name>fs.defaultFS</name> <value>hdfs://slave1:9000</value> </property> <!-- 指定hadoop運行時產生文件的存儲目錄 --> <property> <name>hadoop.tmp.dir</name> <value>/usr/local/src/hadoop-2.7.6/tmp</value> </property> |
(c)配置:hdfs-site.xml
<!-- 指定HDFS副本的數量 --> <property> <name>dfs.replication</name> <value>1</value> </property> |
(2)啓動集羣
(a)格式化namenode(第一次啓動時格式化,之後就不要總格式化)
bin/hdfs namenode -format
(b)啓動namenode
sbin/hadoop-daemon.sh start namenode
(c)啓動datanode
sbin/hadoop-daemon.sh start datanode
(3)查看集羣
(a)查看是否啓動成功
使用jps命令查看進程
(b)查看產生的log日誌
當前目錄:/usr/local/src/hadoop-2.7.6/logs
(c)web端查看HDFS文件系統
http://localhost:50070/dfshealth.html#tab-overview
注意:若是不能查看,看以下帖子處理
http://www.cnblogs.com/zlslch/p/6604189.html
(4)操做集羣
(a)在hdfs文件系統上建立一個input文件夾
[root@slave1 hadoop-2.7.6]# bin/hdfs dfs -mkdir -p /user/mapreduce/wordcount/input
(b)將測試文件內容上傳到文件系統上
[root@slave1 hadoop-2.7.6]# bin/hdfs dfs -put wcinput/wc.input /user/mapreduce/wordcount/input/
(c)查看上傳的文件是否正確
[root@slave1 hadoop-2.7.6]# bin/hdfs dfs -ls /user/mapreduce/wordcount/input/
[root@slave1 hadoop-2.7.6]# bin/hdfs dfs -cat /user/mapreduce/wordcount/input/wc.input
(d)運行mapreduce程序
[root@slave1 hadoop-2.7.6]# bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /user/mapreduce/wordcount/input/ /user/mapreduce/wordcount/output
(e)查看輸出結果
命令行查看:
[root@slave1 hadoop-2.7.6]# bin/hdfs dfs -cat /user/atguigu/mapreduce/wordcount/output/*
也可瀏覽器查看 http://localhost:50070/dfshealth.html#tab-overview
(f)將測試文件內容下載到本地
[root@slave1 hadoop-2.7.6]# hadoop fs -get /user/mapreduce/wordcount/output/part-r-00000 ./wcoutput/
(g)刪除輸出結果
[root@slave1 hadoop-2.7.6]# hdfs dfs -rmr /user/mapreduce/wordcount/output
1)分析:
(1)準備1臺客戶機
(2)安裝jdk
(3)配置環境變量
(4)安裝hadoop
(5)配置環境變量
(6)配置集羣yarn上運行
(7)啓動、測試集羣增、刪、查
(8)在yarn上執行wordcount案例
2)執行步驟
(1)配置集羣
(a)配置yarn-env.sh
配置一下JAVA_HOME
export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
(b)配置yarn-site.xml
<!-- reducer獲取數據的方式 --> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property>
<!-- 指定YARN的ResourceManager的地址 --> <property> <name>yarn.resourcemanager.hostname</name> <value>hadoop61</value> </property> |
(c)配置:mapred-env.sh
配置一下JAVA_HOME
export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
(d)配置: (對mapred-site.xml.template從新命名爲) mapred-site.xml
<!-- 指定mr運行在yarn上 --> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> |
(2)啓動集羣
(a)啓動resourcemanager
sbin/yarn-daemon.sh start resourcemanager
(b)啓動nodemanager
sbin/yarn-daemon.sh start nodemanager
(3)集羣操做
(a)yarn的瀏覽器頁面查看
http://192.168.110.61:8088/cluster
(b)刪除文件系統上的output文件
bin/hdfs dfs -rm -R /user/mapreduce/wordcount/output
(c)執行mapreduce程序
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /user/mapreduce/wordcount/input /user/mapreduce/wordcount/output
(d)查看運行結果
bin/hdfs dfs -cat /user/mapreduce/wordcount/output/*
1)準備3臺客戶機(關閉防火牆、靜態ip、主機名稱)
2)安裝jdk
3)配置環境變量
4)安裝hadoop
5)配置環境變量
6)安裝ssh
7)配置集羣
8)啓動測試集羣
參考https://www.cnblogs.com/singlecodeworld/p/9524369.html
參考https://www.cnblogs.com/singlecodeworld/p/9547866.html
1)集羣部署規劃
hadoop61 | hadoop62 | hadoop63 | |
HDFS |
NameNode DataNode |
DataNode | SecondaryNameNode DataNode |
YARN | NodeManager | ResourceManager NodeManager |
NodeManager |
2)配置文件
(1)配置core-site.xml
<!-- 指定HDFS中NameNode的地址 --> <property> <name>fs.defaultFS</name> <value>hdfs://hadoop61:9000</value> </property>
<!-- 指定hadoop運行時產生文件的存儲目錄 --> <property> <name>hadoop.tmp.dir</name> <value>/opt/module/hadoop-2.7.6/tmp</value> </property> |
(2)Hdfs
配置hadoop-env.sh
export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64 |
配置hdfs-site.xml
<configuration> <property> <name>dfs.replication</name> <value>3</value> </property>
<property> <name>dfs.namenode.secondary.http-address</name> <value>hadoop63:50090</value> </property> </configuration> |
配置slaves
[gaokang@hadoop61 hadoop]$ vi slaves
hadoop61 hadoop62 hadoop63 |
(3)yarn
配置yarn-env.sh
[gaokang@hadoop61 hadoop]$ vi yarn-env.sh
export JAVA_HOME=/opt/module/jdk1.8.0_144 |
配置yarn-site.xml
[gaokang@hadoop61 hadoop]$ vi yarn-site.xml
<configuration>
<!-- reducer獲取數據的方式 --> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property>
<!-- 指定YARN的ResourceManager的地址 --> <property> <name>yarn.resourcemanager.hostname</name> <value>hadoop62</value> </property> </configuration> |
(4)mapreduce
配置mapred-env.sh
[gaokang@hadoop61 hadoop]$ vi mapred-env.sh
export JAVA_HOME=/opt/module/jdk1.8.0_144 |
配置mapred-site.xml
[gaokang@hadoop61 hadoop]$ vi mapred-site.xml
<configuration> <!-- 指定mr運行在yarn上 --> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration> |
3)在集羣上分發以上全部文件
[gaokang@hadoop61 hadoop]$ scp * gaokang@hadoop62:/usr/local/src/hadoop-2-7-6/etc/hadoop
[gaokang@hadoop61 hadoop]$ scp * gaokang@hadoop63:/usr/local/src/hadoop-2-7-6/etc/hadoop
1)啓動集羣
(0)若是集羣是第一次啓動,須要格式化namenode
[gaokang@hadoop61 hadoop-2.7.6]$ bin/hdfs namenode -format
(1)啓動HDFS:
[gaokang@hadoop61 hadoop-2.7.6]$ sbin/start-dfs.sh
//查看啓動進程
[gaokang@hadoop61 hadoop-2.7.6]$ jps
[gaokang@hadoop62 hadoop-2.7.6]$ jps
[gaokang@hadoop63 hadoop-2.7.6]$ jps
(2)啓動yarn
[gaokang@hadoop61 hadoop-2.7.6]$ sbin/start-yarn.sh
注意:Namenode和ResourceManger若是不是同一臺機器,不能在NameNode上啓動 yarn,應該在ResouceManager所在的機器上啓動yarn。
2)集羣基本測試
(1)上傳文件到集羣
[gaokang@hadoop61 hadoop-2.7.6]$ bin/hdfs dfs -mkdir -p /user/data
[gaokang@hadoop61 hadoop-2.7.6]$ bin/hdfs dfs -put etc/hadoop/*-site.xml /user/data
(2)上傳文件後查看文件存放在什麼位置
進入臨時數據目錄
[gaokang@hadoop61 hadoop-2.7.6]$ cd tmp/dfs/data/current/BP-1951657529-192.168.110.61-1535407736174/current/finalized/subdir0/subdir0
(3)拼接,將多個文件拼接成一個文件
(4)下載
[gaokang@hadoop61 hadoop-2.7.6]$ bin/hadoop fs -get /usr/data/hadoop-2.7.6.tar.gz
1)各個服務組件逐一啓動
(1)分別啓動hdfs組件
sbin/hadoop-daemon.sh start|stop namenode|datanode|secondarynamenode
(2)啓動yarn
sbin/yarn-daemon.sh start|stop resourcemanager|nodemanager
2)各個模塊分開啓動(配置ssh是前提)經常使用
(1)總體啓動/中止hdfs
sbin/start-dfs.sh
sbin/stop-dfs.sh
(2)總體啓動/中止yarn
sbin/start-yarn.sh
sbin/stop-yarn.sh
3)所有啓動(不建議使用)
sbin/start-all.sh
sbin/stop-all.sh