linux hadoop完全分散式叢集搭建圖文詳解
一.前期準備
1.1 Win7官網下載hadoop包
本文使用版本hadoop-2.6.5.tar.gz
1.2 配置jdk
1.3 centos7叢集伺服器
主機名 系統 IP地址
master centos7 192.168.32.128
slave01 centos7 192.168.32.131
slave02 centos7 192.168.32.132
1.4 多伺服器ssh免密碼登陸
由於Hadoop啟動以後,namenode是通過SSH(Secure Shell)來啟動和停止各個節點上的各種守護程序的,這就需要在節點之間執行指令的時候是不需要輸入密碼的方式,故我們需要配置SSH使用無密碼公鑰認證的方式。
1.5 叢集伺服器名稱配置
本文預設使用root使用者登入,未新建hadoop專用登入名。
1.5.1 配置各個伺服器ip地址對應的別名
vi /etc/hosts
#配置ip對應名
192.168.32.128 master
192.168.32.131 slave01
192.168.32.132 slave02
![](http://upload-images.jianshu.io/upload_images/5629542-709f384fd897f6c0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
ip別名配置
1.5.2 本地主機名配置
vi /etc/hostname
master
![](http://upload-images.jianshu.io/upload_images/5629542-d153a463cc6fe2c5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
本地主機名稱
三臺伺服器依次修改,並重啟。
二.hadoop完全分散式叢集搭建
以下操作只針對master主機伺服器,其他主機伺服器類似。
2.1 上傳hadoop包至 /opt/software目錄
2.2 解壓和拷貝hadoop至 /usr/local/hadoop
cd /opt/software
tar -zxvf hadoop-2.6.5.tar.gz
cp -r hadoop-2.6.5 /usr/local/hadoop
![](http://upload-images.jianshu.io/upload_images/5629542-e4a08e1506172f0f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
hadoop解壓和拷貝
hadoop解壓和拷貝完成
三.hadoop完全分散式叢集配置
3.1 系統檔案profile配置
配置系統環境變數
vi /etc/profile #hadoop export HADOOP_HOME=/usr/local/hadoop export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native" export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
![](http://upload-images.jianshu.io/upload_images/5629542-3656b4a0e30cfba7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
系統環境配置
退出儲存,重啟配置
source /etc/profile
3.2 hadoop-env.sh檔案配置
cd /usr/local/hadoop/etc/hadoop
vi hadoop-env.sh
#export JAVA_HOME=${JAVA_HOME}
export JAVA_HOME=/usr/local/jdk
export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_HOME}/lib/native
export HADOOP_OPTS="-Djava.library.path=${HADOOP_HOME}/lib/native/"
退出儲存
![](http://upload-images.jianshu.io/upload_images/5629542-71e5746262dc2995.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
hadoop-env.sh環境配置
3.3 新增namenode和datanode存放,臨時目錄tmp
定位:
cd /usr/local/hadoop
mkdir -p dfs/data
mkdir -p dfs/name
mkdir -p tmp
![](http://upload-images.jianshu.io/upload_images/5629542-ba77d5f4f63338ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
新建目錄
3.4 修改hdfs-site.xml檔案
vi hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>master:50090</value>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/usr/local/hadoop/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/usr/local/hadoop/dfs/data</value>
</property>
</configuration>
![](http://upload-images.jianshu.io/upload_images/5629542-551d09669a922586.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
hdfs-site.xml檔案
3.5 修改core-site.xml檔案
vi core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/hadoop/tmp</value>
</property>
</configuration>
![](http://upload-images.jianshu.io/upload_images/5629542-f10c1fa087f24241.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
core-site.xml檔案
3.6 修改mapred-site.xml檔案
目錄預設只有mapred-site.xml.template檔案,複製生成mapred-site.xml檔案
cp mapred-site.xml.template mapred-site.xml
vi mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
![](http://upload-images.jianshu.io/upload_images/5629542-9ff20facafde858c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
mapred-site.xml檔案
3.7 修改yarn-site.xml檔案
vi yarn-site.xml
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>master</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
![](http://upload-images.jianshu.io/upload_images/5629542-7460588937bac469.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
yarn-site.xml檔案
3.8 修改slaves檔案
vi slaves
![](http://upload-images.jianshu.io/upload_images/5629542-529e0d0a17da8782.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
slaves檔案
3.9 slave01和slave02伺服器修改
3.9.1 hadoop檔案複製
複製master中hadoop檔案到slave01和slave02伺服器的/usr/local目錄
scp -r /usr/local/hadoop [email protected]:/usr/local/hadoop
scp -r /usr/local/hadoop [email protected]:/usr/local/hadoop
3.9.2 系統環境profile配置
類似3.2 分別在salve01和slave02配置系統環境
3.9.3 目錄檔案新建
類似3.3 分別在slave01和slave02新建檔案目錄
3.9.4 配置檔案修改
修改core-site.xml檔案
將fs.defaultFs對應的value中master修改slave02
![](http://upload-images.jianshu.io/upload_images/5629542-2da06c6d594b90e1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
core-site.xml檔案
salve01修改類似。
四.hadoop叢集測試
4.1 測試命令
#啟動
start-all.sh start
#停止
stop-all.sh start
#格式化節點
hadoop namenode -format
或者hdfs namenode -format
4.2 叢集測試
在master伺服器執行啟動命令
進入/usr/local/hadoop目錄
4.2.1 格式化namenode
![](http://upload-images.jianshu.io/upload_images/5629542-524ac4215b3fd7bd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4.2.2 啟動各個節點
sbin/start-all.sh start
![](http://upload-images.jianshu.io/upload_images/5629542-308b47b4179bb61f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
start-all.sh啟動所有節點
4.2.3 檢視節點狀態
jps檢視節點程序
![](http://upload-images.jianshu.io/upload_images/5629542-4bb8df6748d6784d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
master程序
![](http://upload-images.jianshu.io/upload_images/5629542-e97c3292bdcf98c8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
slave程序
檢視節點狀態
http://192.168.32.128:50070/dfshealth.html#tab-overview
![](http://upload-images.jianshu.io/upload_images/5629542-1b893524e0a11cdf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
節點狀態
叢集節點使用
http://192.168.32.128:8088/cluster/nodes
![](http://upload-images.jianshu.io/upload_images/5629542-629989fcb6b1fdcc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
叢集節點使用
至此,hadoop完成分散式叢集搭建完畢。