一、簡(jiǎn)單介紹
Hadoop最早誕生于Cutting于1998年左右開(kāi)發(fā)的一個(gè)全文文本搜索引擎
Lucene,這個(gè)搜索引擎在2001年成為Apache基金會(huì)的一個(gè)子項(xiàng)目,也是 ElasticSearch等重要搜索引擎的底層基礎(chǔ)。
項(xiàng)目官方:https://hadoop.apache.org/
二、Linux環(huán)境搭建
首先準(zhǔn)備三臺(tái)Linux服務(wù)器,預(yù)裝CentOS7。三臺(tái)服務(wù)器之間需要網(wǎng)絡(luò)互通。本地測(cè)試環(huán)境的IP地址分別為:192.168.2.128,192.168.2.129,
192.168.2.130
內(nèi)存配置建議不低于4G,硬盤空間建議不低于50G。
1、配置hosts
vi /etc/hosts
這里是給每個(gè)機(jī)器配置一個(gè)機(jī)器名。后續(xù)集群中都會(huì)通過(guò)機(jī)器名進(jìn)行配 置管理,而不會(huì)再關(guān)注IP地址。
2、關(guān)閉防火墻
Hadoop集群節(jié)點(diǎn)之間需要進(jìn)行頻繁復(fù)雜的網(wǎng)絡(luò)交互,在實(shí)驗(yàn)環(huán)境建議關(guān)閉防火墻。生產(chǎn)環(huán)境下,可以根據(jù)情況選擇是按照端口配置復(fù)雜的防火墻規(guī)則或者關(guān)閉內(nèi)部防火墻,使用堡壘機(jī)進(jìn)行統(tǒng)一防護(hù)。
systemctl stop firewalld
systemctl disable firewalld.service
3、配置SSH免密
1、在node01下執(zhí)行,一路回車(四次)
ssh-keygen -t rsa
2、然后在 node01上執(zhí)行
ssh-copy-id node01
3、輸入 yes,然后回車,接著輸入 root 密碼,然后會(huì)得到如下日志
4、驗(yàn)證一下,在 node01節(jié)點(diǎn)執(zhí)行
ssh node01
5、在node02,node03節(jié)點(diǎn)分別執(zhí)行上述四個(gè)步驟(注意節(jié)點(diǎn)名稱的替換)
6、最后分別在node01上執(zhí)行
ssh-copy-id node02
ssh-copy-id node03
在node02上執(zhí)行
ssh-copy-id node01
ssh-copy-id node03
同理,在node03上執(zhí)行
ssh-copy-id node01
ssh-copy-id node02
7、查看是否成功免密登錄
4、安裝JDK
盡量不要使用Linux自帶的OpenJDK。
卸載指令 :rpm -qa | grep -i java | xargs -n1 rpm -e --nodeps
自行下載JDK jdk-8u212-linux-x64.tar.gz。解壓到/usr/java目錄。
最后配置一下jdk的環(huán)境變量
(注:node01、node02、node03三個(gè)節(jié)點(diǎn)都按裝部署jdk環(huán)境)
export JAVA_HOME=/usr/java/jdk1.8.0_291
export CLASSPATH=$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
5、創(chuàng)建用戶(可選)
這里直接使用系統(tǒng)提供的root用戶來(lái)直接進(jìn)行操作。
通常在正是的生產(chǎn)環(huán)境中,root用戶都是要被嚴(yán)格管控的,這時(shí)就需要單獨(dú)創(chuàng)建一個(gè)用戶來(lái)管理這些應(yīng)用
三、Hadoop集群搭建
1、版本選擇
這里選擇的是3.2.2版本 hadoop-3.2.2.tar.gz ,下載地址:https://hadoop.apache.org/release/3.2.2.html
2、 集群機(jī)器角色規(guī)劃
其中,HDFS是一個(gè)分布式的文件系統(tǒng),主要負(fù)責(zé)文件的存儲(chǔ)。由NameNode、Secondary
NameNode和DataNode三種節(jié)點(diǎn)組成。HDFS上的文件,會(huì)以文件塊(Block)的形式存儲(chǔ)到不同的DataNode節(jié)點(diǎn)當(dāng)中。NameNode則用來(lái)存儲(chǔ)文件的相關(guān)元數(shù)據(jù),比如文件名、文件目錄結(jié)果、文件的塊列表等。然后SecondaryNameNode則負(fù)責(zé)每隔一段時(shí)間對(duì)NameNode上的元數(shù)據(jù)進(jìn)行備份。
Yarn是一個(gè)資源調(diào)度的工具,負(fù)責(zé)對(duì)服務(wù)器集群內(nèi)的計(jì)算資源,主要是CPU和內(nèi)存,進(jìn)行合理的分配與調(diào)度。由ResourceManager和NodeManager兩種節(jié)點(diǎn)組成。ResourceManager負(fù)責(zé)對(duì)系統(tǒng)內(nèi)的計(jì)算資源進(jìn)行調(diào)度分配,將計(jì)算任務(wù)分配到具體的NodeManger節(jié)點(diǎn)上執(zhí)行。而NodeManager則負(fù)責(zé)具體的計(jì)算任務(wù)執(zhí)行。
3、按裝Hadoop
1、在所有虛擬機(jī)根目錄下新建文件夾export,export文件夾中新建data、servers和software文件
mkdir -p /export/data
mkdir -p /export/servers
mkdir -p /export/software
2、解壓Hadoop安裝包
cd /export/software
tar -zxvf hadoop-3.2.2.tar.gz -C /export/servers/
3、配置hadoop環(huán)境變量
打開(kāi)配置文件
vi /etc/profile
配置文件最后追加的配置
export HADOOP_HOME=/export/servers/hadoop-3.2.2
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
使配置文件生效
source /etc/profile
4、查看是否配置成功
hadoop version
4、Hadoop集群配置
配置前先介紹一下配置文件
以下所有的配置文件都在hadoop安裝目錄下etc文件中,路徑如下:
需要配置的文件有以下6個(gè)
1、配置hadoop-env.sh文件
vi hadoop-env.sh
#找到相應(yīng)位置添加這段
export JAVA_HOME=/usr/java/jdk1.8.0_291
2、配置core-site.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
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.
-->
<!-- Put site-specific property overrides in this file. -->
<configuration>
<!-- 指定 NameNode 的地址 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://node01:8020</value>
</property>
<!-- 指定 hadoop 數(shù)據(jù)的存儲(chǔ)目錄 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/export/servers/hadoop-3.2.2/data</value>
</property>
<!-- 配置 HDFS 網(wǎng)頁(yè)登錄使用的靜態(tài)用戶為當(dāng)前操作系統(tǒng)用戶 -->
<property>
<name>hadoop.http.staticuser.user</name>
<value>root</value>
</property>
</configuration>
3、配置hdfs-site.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
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.
-->
<!-- Put site-specific property overrides in this file. -->
<configuration>
<!-- NameNode web 端訪問(wèn)地址-->
<property>
<name>dfs.namenode.http-address</name>
<value>node01:9870</value>
</property>
<!-- 2NameNode web 端訪問(wèn)地址-->
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>node03:9868</value>
</property>
<!-- 備份數(shù)量 -->
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<!-- 打開(kāi)webhdfs -->
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
4、配置yarn-site.xml文件
<?xml version="1.0"?>
<!--
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.
-->
<configuration>
<!-- 指定 MR 走 shuffle -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<!-- 指定 ResourceManager 的地址-->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>node02</value>
</property>
<!-- 環(huán)境變量的繼承 跑示例時(shí)要用到-->
<property>
<name>yarn.nodemanager.env-whitelist</name>
<value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>
</property>
<!-- 開(kāi)啟日志聚集功能 -->
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
<!-- 設(shè)置日志聚集服務(wù)器地址 -->
<property>
<name>yarn.log.server.url</name>
<value>http://node01:19888/jobhistory/logs</value>
</property>
<!-- 設(shè)置日志保留時(shí)間為 7 天 -->
<property>
<name>yarn.log-aggregation.retain-seconds</name>
<value>604800</value>
</property>
</configuration>
5、配置mapred-site.xml文件
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
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.
-->
<!-- Put site-specific property overrides in this file. -->
<configuration>
<!-- 指定 MapReduce 程序運(yùn)行在 Yarn 上 -->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<!-- 歷史服務(wù)器 web 端地址 -->
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>node01:19888</value>
</property>
</configuration>
6、配置workers文件
node01
node02
node03
7、將配置完成后的hadoop整體分發(fā)到另外的節(jié)點(diǎn)(完成node02、node03兩個(gè)節(jié)點(diǎn)和node01相同的配置)
scp ~/.bash_profile root@node02:~
scp -r /export/servers/hadoop-3.2.2 root@node02:/export/servers/hadoop-3.2.2
scp ~/.bash_profile root@node03:~
scp -r /export/servers/hadoop-3.2.2 root@node03:/export/servers/hadoop-3.2.2
5、啟動(dòng)Hadoop集群
1、先啟動(dòng)hdfs服務(wù)(在node01上啟動(dòng)NameNode、DataNode)
第一次啟動(dòng)hdfs服務(wù)時(shí),需要先對(duì)NameNode進(jìn)行格式化。在NameNode所
在的node01機(jī)器,執(zhí)行hadoop namenode -format
執(zhí)行,完成初始化。初始化完成后,會(huì)在 /export/servers/hadoop-3.2.2/data/dfs/name/current目錄下創(chuàng)建一個(gè)NameNode的鏡像。
接下來(lái)可以嘗試啟動(dòng)hdfs了。 hadoop的啟動(dòng)腳本在hadoop下的sbin目錄
下。 start-dfs.sh就是啟動(dòng)hdfs的腳本。
當(dāng)前版本hadoop如果不創(chuàng)建單獨(dú)用戶,而是直接使用root用戶啟動(dòng),會(huì)報(bào)錯(cuò)。這時(shí)就需要添加之前配置的HDFS_NAMENODE_USER 等幾個(gè)環(huán)境變量。
打開(kāi)配置文件vi /etc/profile
在最后追加如下內(nèi)容,保存退出source /etc/profile
(node02、node03節(jié)點(diǎn)不要忘記配置)
export HDFS_NAMENODE_USER=root
export HDFS_DATANODE_USER=root
export HDFS_SECONDARYNAMENODE_USER=root
export YARN_RESOURCEMANAGER_USER=root
export YARN_NODEMANAGER_USER=root
export HADOOP_PID_DIR=/export/servers
2、接下來(lái)啟動(dòng)Yarn(node02上啟動(dòng)ResourceManager、DataNoda)
注意下在yarn-site.xml中配置了日志聚合,將yarn的執(zhí)行日志配置到了
hdfs上。所以yarn建議在hdfs后啟動(dòng)。當(dāng)然,在生產(chǎn)環(huán)境下需要評(píng)估這
種日志方式是否合適。
3、查看各個(gè)節(jié)點(diǎn)服務(wù)啟動(dòng)進(jìn)程
DataNode: 數(shù)據(jù)節(jié)點(diǎn)。
NameNode 名稱服務(wù);
SecondaryNameNode 備份名稱服務(wù)
4、訪問(wèn)HDFS的Web頁(yè)面
配置window下的host文件 C:\Windows\System32\drivers\etc打開(kāi)hosts文件
192.168.2.128 node01
192.168.2.129 node02
192.168.2.130 node03
http://node01:9870/
5、訪問(wèn)yarn的管理頁(yè)面
http://node02:8088/文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-779669.html
hadoop集群環(huán)境配置搭建完成!文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-779669.html
到了這里,關(guān)于Hadoop集群環(huán)境配置搭建的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!