hadoop搭建流程
下載hadoop
由于之后需要搭建hbase,查看hbase兼容hadoop版本,所以選擇Hadoop-2.7.5

下載地址為http://hadoop.apache.org/releases.html
搭建Pseudo-Distributed
本地開發(fā)使用偽分布式集群
修改配置
etc/hadoop/core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/Users/titengjiang/Documents/DeveloperTool/hadoop/local/tmp</value>
</property>
</configuration>
etc/hadoop/hdfs-site.xml,配置副本,以及namenode,datanode數(shù)據(jù)存放路徑
<configuration>
<!-- 設置namenode存放的路徑 -->
<property>
<name>dfs.namenode.name.dir</name>
<value>/Users/titengjiang/Documents/DeveloperTool/hadoop/local/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/Users/titengjiang/Documents/DeveloperTool/hadoop/local/hadoop/hdfs</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
配置ssh免密碼
ssh localhost
如果需要密碼通過以下步驟,生成公鑰并添加到ssh授權文件中
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
啟動
format namenode
第一啟動需要格式化namenode
bin/hdfs namenode -format
啟動本地偽分布式集群
sbin/start-dfs.sh
jps
顯示出如下三個進程表示啟動成功

測試
NameNode - http://localhost:50070/
使用demo測試
bin/hdfs dfs -mkdir /user
bin/hdfs dfs -mkdir /user/titengjiang
bin/hdfs dfs -mkdir input
bin/hdfs dfs -put etc/hadoop/*.xml input
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.5.jar grep input output 'dfs[a-z.]+'

注意user后面的username為當前啟動hadoop的用戶名
生產(chǎn)分布式集群搭建
生產(chǎn)服務器目前使用三臺作為hadoop集群,每臺服務器,每臺服務器掛載12塊硬盤

內(nèi)存為

每臺服務器友90G
部署計劃如下
hadoop-1 namenode
hadoop-2 secondary datanode
hadoop-3 datanode
下載
安裝jdk1.8,下載hadoop-2.7.5解壓到每個服務器上.
創(chuàng)建用戶配置ssh免密
三臺配置ssh authorized_keys,將三臺ssh 公鑰寫入authorized_keys中,通過
scp同步到每臺服務器中
scp -P 2014 authorized_keys xg-mt-grandapm-lindb-1:~/.ssh/
相互測試ssh 是否免密
設置data1-data12目錄權限
sudo chown -R username:usergroup /data2 /data3 /data4 /data5 /data6 /data7 /data8 /data9 /data10 /data11 /data12
username:usergroup為實際的用戶和用戶組
目錄沒有讀寫權限啟動時可能會出現(xiàn)如下錯誤

其實并不是硬盤損壞而是權限問題
配置hadoop-1 namenode
core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://xg-mt-grandapm-lindb-1:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/cassandra/platform/hadoop-2.7.5/tmp</value>
</property>
</configuration>
xg-mt-grandapm-lindb-1為hadoop-1主機名
hdfs-site.xml
<configuration>
<!-- 設置namenode的http通訊地址 -->
<property>
<name>dfs.namenode.http-address</name>
<value>xg-mt-grandapm-lindb-1:50070</value>
</property>
<!-- 設置secondarynamenode的http通訊地址 -->
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>xg-mt-grandapm-lindb-2:50090</value>
</property>
<!-- 設置namenode存放的路徑 -->
<property>
<name>dfs.namenode.name.dir</name>
<value>/home/cassandra/platform/hadoop-2.7.5/name</value>
</property>
<!-- 設置hdfs副本數(shù)量 -->
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.datanode.registration.ip-hostname-check</name>
<value>false</value>
</property>
</configuration>
namenode 節(jié)點不作為datanode使用
mapred-site.xml 啟動yarn
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
yarn-site.xml
<!-- 設置 resourcemanager 在哪個節(jié)點-->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>xg-mt-grandapm-lindb-1</value>
</property>
<!-- reducer取數(shù)據(jù)的方式是mapreduce_shuffle -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
slaves 配置管理的datanodes,每個節(jié)點一行
xg-mt-grandapm-lindb-2
xg-mt-grandapm-lindb-3
配置hadoop-2/3 datanode
scp hadoop-1的配置到2/3節(jié)點中
hdfs-site.xml 增加datanode配置,掛載12塊硬盤
<property>
<name>dfs.datanode.data.dir</name
<value>/data1/hadoop/hdfs,/data2/hadoop/hdfs,/data2/hadoop/hdfs,/data3/hadoop/hdfs,/data4/hadoop/hdfs,/data5/hadoop/hdfs,/data6/hadoop/hdfs,/data7/hadoop/hdfs,/data8/hadoop/hdfs,/data9/hadoop/hdfs,/data10/hadoop/hdfs,/data11/hadoop/hdfs,/data12/hadoop/hdfs</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
namenode節(jié)點啟動整個集群
bin/hdfs namenode -format
sbin/start-dfs.sh
sbin/start-yarn.sh
jps 檢查進程
hadoop-1


hadoop-2

hadoop-3

使用偽分布式集群的方式測試分布測試
namenode

yarn

整個集群搭建完畢