天天看點

在騰訊雲上搭建 Hadoop 完全分布式叢集

“紙上得來終覺淺,覺知此事要躬行”

本系列文章主要針對騰訊雲上進行大資料系統化操作講解,在網際網路盛行的今日,站在巨人頭上的我們。一門技術得來,百度一下終得解決。然而網際網路上的文章零零碎碎,達不到強度系統化,以及友善性,快捷性,和簡潔性,與針對性準則,這給雲上大資料愛好者們帶來困擾,使适應騰訊雲平台需要花費大量的精力與時間。開發成本大幅增加,然而這些對生産項目尤為重要,

本文章就是為了彌補這些而寫,借助騰訊雲平台進行一些實戰性,選擇性講解。并希望與一些志同道合的小夥伴一起來攻克難關,共同促進雲計算,大資料發展。

在騰訊雲上搭建 Hadoop 完全分布式叢集

三台同号同區騰訊雲伺服器,配置可根據所需求自行加減,三台系統為centos6.5 64位。 如下圖:

在騰訊雲上搭建 Hadoop 完全分布式叢集
在騰訊雲上搭建 Hadoop 完全分布式叢集
在騰訊雲上搭建 Hadoop 完全分布式叢集

騰訊雲主機對應叢集節點和相應功能圖

在騰訊雲上搭建 Hadoop 完全分布式叢集

規劃圖

在騰訊雲上搭建 Hadoop 完全分布式叢集

1.添加hadoop使用者組

2.建立hadoop使用者并添加到使用者組中

3.修改 hadoop 使用者的密碼為hadoop

在騰訊雲上搭建 Hadoop 完全分布式叢集

下載下傳java安裝包 版本:1.8.0_131

微雲java安裝包下載下傳位址:http://url.cn/49Sxz1E

上傳安裝包。

使用ftp上傳工具上傳到伺服器,也可wget進行下載下傳。這裡就不進行講解。

安裝 Java:<code>rmp -ivh java.rpm</code>

驗證安裝是否成功:<code>java -version</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集
在騰訊雲上搭建 Hadoop 完全分布式叢集

修改 hosts 檔案<code>vim /etc/hosts</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集

修改ssh配置檔案取消注釋<code>vim /etc/ssh/sshd_config</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集

重新開機 sshd 服務<code>service sshd restart</code>

上傳檔案在home目錄下

解壓hadoop壓縮包:<code>tar -zxf hadoop-2.7.1.tar.gz</code>。

在home目錄下建立bigdata目錄:<code>mkdir bigdata</code>

移動hadoop目錄及檔案移動到bigdata目錄下:<code>mv hadoop-2.7.1 bigdata/</code>

切換到bigdata目錄下:<code>cd bigdata</code>

修改目錄名稱hadoop-2.7.1為hadoop:<code>mv hadoop-2.7.1 hadoop</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集

配置hadoop配置檔案,檔案如下:

在騰訊雲上搭建 Hadoop 完全分布式叢集

修改core-site.xml檔案:

<code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code> <code>&lt;?xml-stylesheet type="text/xsl" href="configuration.xsl"?&gt;</code> <code>&lt;!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file. --&gt;</code> <code>&lt;!-- Put site-specific property overrides in this file. --&gt;</code> <code>&lt;configuration&gt;</code> <code>&lt;property&gt;</code> <code>&lt;name&gt;fs.defaultFS&lt;/name&gt;</code> <code>&lt;value&gt;hdfs://master:9000&lt;/value&gt;</code> <code>&lt;/property&gt;</code> <code>&lt;property&gt;</code> <code>&lt;name&gt;hadoop:tmp.dir&lt;/name&gt;</code> <code>&lt;value&gt;/home/hadoop/bigdate/data/hadoop/tmp&lt;/value&gt;</code> <code>&lt;/property&gt;</code> <code>&lt;/configuration&gt;</code>

修改hdfs-site.xml檔案

<code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code> <code>&lt;?xml-stylesheet type="text/xsl" href="configuration.xsl"?&gt;</code> <code>&lt;!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file. --&gt;</code> <code>&lt;!-- Put site-specific property overrides in this file. --&gt;</code> <code>&lt;configuration&gt;</code> <code>&lt;property&gt;</code> <code>&lt;name&gt; dfs:namenode.secondary.http-adress&lt;/name&gt;</code> <code>&lt;value&gt;master:9001&lt;/value&gt;</code> <code>&lt;/property&gt;</code> <code>&lt;property&gt;</code> <code>&lt;name&gt;dfs:namenode.name.dir&lt;/name&gt;</code> <code>&lt;value&gt;file:/home/hadoop/bigdate/date/hadoop/hdfs/datanode&lt;/value&gt;</code> <code>&lt;/property&gt;</code> <code>&lt;property&gt;</code> <code>&lt;name&gt;dfs:namenode.name.dir&lt;/name&gt;</code> <code>&lt;value&gt;file:/home/hadoop/bigdate/date/hadoop/hdfs/namenode&lt;/value&gt;</code> <code>&lt;/property&gt;</code> <code>&lt;property&gt;</code> <code>&lt;name&gt;dfs.replication&lt;/name&gt;</code> <code>&lt;value&gt;3&lt;/value&gt;</code> <code>&lt;/property&gt;</code> <code>&lt;/configuration&gt;</code>

修改mapered-site.xml檔案,沒有可以生成一個,也可在mapred-site.xml.template中進行配置

<code>&lt;?xml version="1.0"?&gt;</code> <code>&lt;?xml-stylesheet type="text/xsl" href="configuration.xsl"?&gt;</code> <code>&lt;!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file. --&gt;</code> <code>&lt;!-- Put site-specific property overrides in this file. --&gt;</code> <code>&lt;configuration&gt;</code> <code>&lt;property&gt;</code> <code>&lt;name&gt;mapreduce.framework.name&lt;/name&gt;</code> <code>&lt;value&gt;yarn&lt;/value&gt;</code> <code>&lt;/property&gt;</code> <code>&lt;/configuration&gt;</code>

修改yarn-site.xml配置檔案

<code>&lt;?xml version="1.0"?&gt;</code> <code>&lt;!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file. --&gt;</code> <code>&lt;configuration&gt;</code> <code>&lt;!-- Site specific YARN configuration properties --&gt;</code> <code>&lt;property&gt;</code> <code>&lt;name&gt;yarn.resourcemanager.hostname&lt;/name&gt;</code> <code>&lt;value&gt;master&lt;/value&gt;</code> <code>&lt;/property&gt;</code> <code>&lt;property&gt;</code> <code>&lt;name&gt;yarn.nodemanager.aux-serivices&lt;/name&gt;</code> <code>&lt;value&gt;mapreduce_shuffle&lt;/value&gt;</code> <code>&lt;/property&gt;</code> <code>&lt;/configuration&gt;</code>

修改slaves檔案

<code>slave01 slave02</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集
在騰訊雲上搭建 Hadoop 完全分布式叢集

關機master伺服器進行鏡像制作。

在騰訊雲上搭建 Hadoop 完全分布式叢集

确認後,等待幾分鐘即可制作完成,完成後開機master主機

在騰訊雲上搭建 Hadoop 完全分布式叢集

重裝slave01伺服器和slave02伺服器

在騰訊雲上搭建 Hadoop 完全分布式叢集

修改計算機名稱,修改下圖示紅處:<code>vim /etc/sysconfig/network</code> 。

在騰訊雲上搭建 Hadoop 完全分布式叢集
在騰訊雲上搭建 Hadoop 完全分布式叢集
在騰訊雲上搭建 Hadoop 完全分布式叢集

重新開機伺服器:<code>reboot</code>

切換到hadoop使用者:<code>su - hadoop</code>

切換到家目錄:<code>cd ~</code>

生成密鑰 一路回車即可:<code>ssh-keygen -t rsa</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集

切換到.ssh目錄下:<code>cd .ssh/</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集

将id-rsa_pub内容寫入生成authorized-keys檔案:<code>cat id_rsa.pub &gt;&gt;authorized_keys</code>

8.在master主機中将authorized_keys檔案傳到slave01主機hadoop家目錄.shh目錄下:<code>scp authorized_keys hadoop@slave01:/home/hadoop/.ssh/</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集

在master主機中将authorized_keys檔案傳到slave02主機hadoop家目錄.shh目錄下:<code>scp authorized_keys hadoop@slave02:/home/hadoop/.ssh/</code>

10.目錄權限設定,hadoop使用者目錄權限為755或者700,.ssh目錄是755.id_rsa.pub和authorized_keys權限為644,如下圖

在騰訊雲上搭建 Hadoop 完全分布式叢集

17.使用shh+主機名進行驗證

在騰訊雲上搭建 Hadoop 完全分布式叢集

<code>hadoop namenode -format</code> namenode格式化,如不能操作檢查環境變量或<code>./hadoop namenode -format</code>進行namenode格式化

啟動hadoop程式

切換到sbin目錄下:<code>cd /home/hadoop/bigdata/hadoop/sbin</code>

啟動hadoop程式:<code>sh start-all.sh</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集

檢視:<code>jps</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集

四個程序運作中

<code>ssh slave01</code>

在騰訊雲上搭建 Hadoop 完全分布式叢集

下篇文章,筆者将介紹如何在騰訊雲上完成 Hive 安裝及配置。