大数据集群(Hadoop生态)安装部署——Linux
简介
1)Hadoop
是一个由Apache
基金会所开发的分布式系统基础架构。
2)主要解决,海量数据的存储和海量数据的分析计算问题。
Hadoop HDFS
提供分布式海量数据存储能力Hadoop YARN
提供分布式集群资源管理能力Hadoop MapReduce
提供分布式海量数据计算能力
前置要求
- 1、请确保完成了集群化环境前置准备
- 即:
JDK
、SSH免密
、关闭防火墙
、配置主机名映射
等前置操作
- 即:
- 2、Zookeeper集群部署
Hadoop集群角色
Hadoop生态体系中总共会出现如下进程
角色:
- Hadoop HDFS的管理角色:
Namenode
进程(仅需1个即可(管理者一个就够)) - Hadoop HDFS的工作角色:
Datanode
进程(需要多个(工人,越多越好,一个机器启动一个)) - Hadoop YARN的管理角色:
ResourceManager
进程(仅需1个即可(管理者一个就够)) - Hadoop YARN的工作角色:
NodeManager
进程(需要多个(工人,越多越好,一个机器启动一个)) - Hadoop 历史记录服务器角色:
HistoryServer
进程(仅需1个即可(功能进程无需太多1个足够)) - Hadoop 代理服务器角色:
WebProxyServer
进程(仅需1个即可(功能进程无需太多1个足够)) - Zookeeper的进程:
QuorumPeerMain
进程(仅需1个即可(Zookeeper的工作者,越多越好))
角色和节点分配
角色分配如下:
node1 | Namenode、Datanode、ResourceManager、NodeManager、HistoryServer、WebProxyServer、QuorumPeerMain |
---|---|
node2 | Datanode、NodeManager、QuorumPeerMain |
node3 | Datanode、NodeManager、QuorumPeerMain |
安装
调整虚拟机内存
如上图,可以看出node1
承载了太多的压力。同时node2
和node3
也同时运行了不少程序
- 为了确保集群的稳定,需要对虚拟机进行内存设置。
请在VMware中,对:
node1
设置4GB或以上内存
node2
和node3
设置2GB或以上内存
大数据的软件本身就是集群化(一堆服务器)一起运行的。
现在我们在一台电脑中以多台虚拟机来模拟集群,确实会有很大的内存压力哦。
Hadoop集群部署
1、下载Hadoop安装包、解压、配置软链接
# 1. 下载
wget http://archive.apache.org/dist/hadoop/common/hadoop-3.3.0/hadoop-3.3.0.tar.gz
直接下载较慢,或者在我百度网盘, 提取码:155l
# 2. 解压
# 请确保目录/export/server存在
tar -zxvf hadoop-3.3.0.tar.gz -C /export/server/
# 3. 构建软链接
ln -s /export/server/hadoop-3.3.0 /export/server/hadoop
2、修改配置文件:hadoop-env.sh
(Hadoop的配置文件要修改的地方很多,请细心!)
- 进入到
/export/server/hadoop/etc/hadoop
,文件夹中,配置文件都在这里修改hadoop-env.sh
文件
cd /export/server/hadoop/etc/hadoop
vim hadoop-env.sh
此文件是配置一些
Hadoop
用到的环境变量
这些是临时变量,在Hadoop
运行时有用
如果要永久生效,需要写到/etc/profile
中
在文件开头加入:
# 配置Java安装路径
export JAVA_HOME=/export/server/jdk
# 配置Hadoop安装路径
export HADOOP_HOME=/export/server/hadoop
# Hadoop hdfs配置文件路径
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
# Hadoop YARN配置文件路径
export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
# Hadoop YARN 日志文件夹
export YARN_LOG_DIR=$HADOOP_HOME/logs/yarn
# Hadoop hdfs 日志文件夹
export HADOOP_LOG_DIR=$HADOOP_HOME/logs/hdfs
# Hadoop的使用启动用户配置
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 YARN_PROXYSERVER_USER=root
3、修改配置文件:core-site.xml
如下,清空文件,填入如下内容
vim core-site.xml
清空文件: 先按d
再按 G
,
再按i
进入插入模式,复制粘贴如下内容:
<?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>
<property>
<name>fs.defaultFS</name>
<value>hdfs://node1:8020</value>
<description></description>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
<description></description>
</property>
</configuration>
4、配置:hdfs-site.xml
文件
vim hdfs-site.xml
清空文件: 先按d
再按 G
,
再按i
进入插入模式,复制粘贴如下内容:
<?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>
<property>
<name>dfs.datanode.data.dir.perm</name>
<value>700</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/data/nn</value>
<description>Path on the local filesystem where the NameNode stores the namespace and transactions logs persistently </description>
</property>
<property>
<name>dfs.namenode.hosts</name>
<value>node1,node2,node3</value>
<description>List of permitted DataNodes.
</description>
</property>
<property>
<name>dfs.blocksize</name>
<value>268435456</value>
<description></description>
</property>
<property>
<name>dfs.namenode.handler.count</name>
<value>100</value>
<description></description>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/data/dn</value>
</property>
</configuration>
5、配置:mapred-env.sh
文件
vim mapred-env.sh
按Shift
+ o
, 在 文件的开头 加入如下环境变量设置:
export JAVA_HOME=/export/server/jdk
export HADOOP_JOB_HISTORYSERVER_HEAPSIZE=1000
export HADOOP_MAPRED_ROOT_LOGGER=INFO,RFA
6、配置:mapred-site.xml
文件
vim mapred-site.xml
:
**清空文件:**先按d
再按 G
, 填入如下内容:
<?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>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
<description></description>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>node1:10020</value>
<description></description>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>node1:19888</value>
<description></description>
</property>
<property>
<name>mapreduce.jobhistory.intermediate-donedir</name>
<value>/data/mr-history/tmp</value>
<description></description>
</property>
<property>
<name>mapreduce.jobhistory.done-dir</name>
<value>/data/mr-history/done</value>
<description></description>
</property>
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=$HADOOP_HOME</value>
</property>
<property>
<name>mapreduce.map.env</name>
<value>HADOOP_MAPRED_HOME=$HADOOP_HOME</value>
</property>
<property>
<name>mapreduce.reduce.env</name>
<value>HADOOP_MAPRED_HOME=$HADOOP_HOME</value>
</property>
</configuration>
7、配置:yarn-env.sh
文件
vim yarn-env.sh
按Shift
+ o
, 在 文件的开头 加入如下环境变量设置:
export JAVA_HOME=/export/server/jdk
export HADOOP_HOME=/export/server/hadoop
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
export YARN_LOG_DIR=$HADOOP_HOME/logs/yarn
export HADOOP_LOG_DIR=$HADOOP_HOME/logs/hdfs
8、配置:yarn-site.xml
文件
vim yarn-site.xml
清空文件: 先按d
再按 G
, 填入如下内容:
<?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>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.log.server.url</name>
<value>http://node1:19888/jobhistory/logs</value>
<description></description>
</property>
<property>
<name>yarn.web-proxy.address</name>
<value>node1:8089</value>
<description>proxy server hostname and port</description>
</property>
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
<description>Configuration to enable or disable log aggregation</description>
</property>
<property>
<name>yarn.nodemanager.remote-app-logdir</name>
<value>/tmp/logs</value>
<description>Configuration to enable or disable log aggregation</description>
</property>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>node1</value>
<description></description>
</property>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
<description></description>
</property>
<property>
<name>yarn.nodemanager.local-dirs</name>
<value>/data/nm-local</value>
<description>Comma-separated list of paths on the local filesystem where intermediate data is written.</description>
</property>
<property>
<name>yarn.nodemanager.log-dirs</name>
<value>/data/nm-log</value>
<description>Comma-separated list of paths on the local filesystem where logs are written.</description>
</property>
<property>
<name>yarn.nodemanager.log.retainseconds</name>
<value>10800</value>
<description>Default time (in seconds) to retain log files on the NodeManager Only applicable if log-aggregation is disabled.</description>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
<description>Shuffle service that needs to be set for Map Reduce applications.</description>
</property>
<!-- 选择调度器,默认容量 -->
<property>
<description>The class to use as the resource scheduler.</description>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>
</property>
</configuration>
9、修改workers
文件
vim workers
全部内容如下:
node1
node2
node3
10、【在node1
执行】 分发hadoop
到其它机器
cd /export/server
scp -r hadoop-3.3.0 node2:`pwd`/
scp -r hadoop-3.3.0 node3:`pwd`/
分发时间挺久的,耐心等待!
11、在node2
、node3
执行
# 创建软链接
ln -s /export/server/hadoop-3.3.0 /export/server/hadoop
12、创建所需目录
- 在
node1
执行:
mkdir -p /data/nn
mkdir -p /data/dn
mkdir -p /data/nm-log
mkdir -p /data/nm-local
- 在
node2
执行:
mkdir -p /data/dn
mkdir -p /data/nm-log
mkdir -p /data/nm-local
- 在
node3
执行:
mkdir -p /data/dn
mkdir -p /data/nm-log
mkdir -p /data/nm-local
13、配置环境变量
在node1
、node2
、node3
修改/etc/profile
vim /etc/profile
在文件最下面添加:
export HADOOP_HOME=/export/server/hadoop
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
生效,执行:
source /etc/profile
14、格式化NameNode
,在node1
执行
hadoop namenode -format
hadoop
这个命令来自于:$HADOOP_HOME/bin
中的程序
由于配置了环境变量PATH
,所以可以在任意位置执行hadoop
命令哦
15、启动hadoop
的hdfs
集群,在node1
执行即可
start-dfs.sh
# 如需停止可以执行
stop-dfs.sh
start-dfs.sh
这个命令来自于:$HADOOP_HOME/sbin
中的程序
由于配置了环境变量PATH
,所以可以在任意位置执行start-dfs.sh
命令哦
16、启动hadoop
的yarn
集群,在node1
执行即可
start-yarn.sh
输入 jps
,查看进程
# 如需停止可以执行
stop-yarn.sh
17、启动历史服务器
mapred --daemon start historyserver
# 如需停止将start更换为stop
18、启动web代理服务器
yarn-daemon.sh start proxyserver
# 如需停止将start更换为stop
验证Hadoop集群运行情况
- 在
node1
、node2
、node3
上通过jps
验证进程是否都启动成功
- 验证
HDFS
,浏览器打开:http://node1:9870
创建文件test.txt
,随意填入内容,
vim test.txt
hhh
hello
Linux
并执行:
hadoop fs -put test.txt /test.txt
hadoop fs -cat /test.txt
- 验证
YARN
,浏览器打开:http://node1:8088
执行:
# 创建文件words.txt,填入如下内容
it itcast hadoop
it hadoop hadoop
it itcast
# 将文件上传到HDFS中
hadoop fs -put words.txt /words.txt
# 执行如下命令验证YARN是否正常
hadoop jar /export/server/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.0.jar wordcount -Dmapred.job.queue.name=root.root /words.txt /output
(附加)集群启动和关闭:
注意:启动集群前,一定要启动zookeeper
三台机器都要执行
/export/server/zookeeper/bin/zkServer.sh start
node1执行
start-dfs.sh
start-yarn.sh
mapred --daemon start historyserver
#如需停止将start更换为stop
node1执行
stop-yarn.sh
stop-dfs.sh
三台机器都要执行
/export/server/zookeeper/bin/zkServer.sh stop
上传到HDFS
hdfs dfs -mkdir -p /usr/hadoop/in
hdfs dfs -ls /usr/hadoop/
hdfs dfs -put data.txt /usr/hadoop/in/
运行
hadoop jar temperature_test-1.0-SNAPSHOT.jar cn.sky.hadoop.JobMain