全分佈式集羣搭建
前提: 一臺主機,一臺或以上的副機
將虛擬機改爲橋接模式
在VMWare側邊欄右鍵虛擬機名字->選擇"設置"->選擇"橋接模式"
獲取IP
連接上主機的網絡,使虛副機與主機處在同一網絡下。
輸入ifconfig
獲取虛擬機ip
配置文件
-
修改hostname:
在終端輸入
sudo vim /etc/hostname
將默認的名稱刪除,輸入自己要設置的hostname,保存退出。
-
修改hosts文件:
輸入
sudo vim /etc/hosts
註釋掉第二行127.0.1.1,將主機和其它成員的ip與hostname寫入
重啓,使修改生效。
-
切換用戶(如果已是要配置的用戶下則不用切換)
-
轉到用戶家目錄
cd ~
, 查看是否有BigData文件夾, 有則刪去。 -
輸入
cd /opt/hadoop/etc/hadoop/
輸入
sudo vim workers
, 將各副機的hostname寫入
修改xml文件
-
在
/opt/hadoop/etc/hadoop/
目錄下修改core-site.xml
,hdfs-site.xml
,yarn-site.xml
-
core-site.xml
內容:<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>fs.defaultFS</name> <!--修改value--> <value>hdfs://主機的hostname:9000</value> </property> </configuration>
-
hdfs-site.xml
內容:<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>dfs.nameservices</name> <value>hdfs01</value> <!--此處的value集羣機器間要保持一致--> </property> <property> <name>dfs.namenode.secondary.http-address</name> <!--修改value--> <value>主機的hostname:50090</value> </property> <property> <name>dfs.blocksize</name> <value>32m</value> </property> <property> <name>dfs.replication</name> <value>2</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:/home/hdfs/Bigdata/data/hadoop/hdfs/nn</value> </property> <property> <name>fs.checkpoint.dir</name> <value>file:/home/hdfs/Bigdata/data/hadoop/hdfs/snn</value> </property> <property> <name>fs.checkpoint.edits.dir</name> <value>file:/home/hdfs/Bigdata/data/hadoop/hdfs/snn</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/home/hdfs/Bigdata/data/hadoop/hdfs/dn</value> </property> </configuration>
-
yarn-site.xml
內容:<?xml version="1.0"?> <configuration> <property> <name>yarn.resourcemanager.hostname</name> <!--修改value--> <value>主機的hostname</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.nodemanager.local-dirs</name> <value>/home/hdfs/Bigdata/hadoop/data/hadoop/yarn/nm</value> </property> </configuration>
-
附
mapred-site.xml
的內容:<?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration>
啓動服務
- 主機格式化文件系統,副機可以不格式化
- 主機啓動namenode:
hadoop-daemon.sh start namenode
或 hdfs --daemon start namenode
(推薦)- 副機啓動datanode:
hdfs --daemon start datanode
- 主機啓動resourcemanager:
yarn --daemon start resourcemanager
- 副機啓動nodemanager:
yarn --daemon start nodemanager
結果
在瀏覽器輸入https://主機hostname或主機ip:9870,可以看到各副機的信息。主機位啓動datanode,所以沒有它的信息.
零散知識點
-
啓動服務後,可以用jps查看是否已啓動服務。
副機包含
NodeManager,DataNode,Jps
-
殺掉進程:kill -9 進程號
-
如果正確啓動,轉到~/Bigdata/data/hadoop/hdfs
輸入ls可以看到只有一個dn(針對副機)。
如果有nn則會導致連接主機失敗
-
查看集羣ID與數據節點ID:進入dn目錄,輸入cat current, cat VERSION
-
查看日誌:輸入 cd /opt/hadoop/logs, cd hadoop-hdfs-datanode-你的hostname.log。