前言
因工作需要验证FlinkCDC相关功能,Flink的checkpoint 信息可以放到Hdfs上,因此想部署一套Hadoop进行验证,鉴于之前部署的都没有做记录,本次安装部署的时候还得重新找安装步骤,因此本次做了记录,方便后续如果需要可以进行快速安装。大神绕过~
一、环境准备
1.集群规划
VMware Workstation 15
CentOS 7.9
192.168.10.21(hadoop01)
192.168.10.22(hadoop02)
192.168.10.23(hadoop03)
2.虚拟机安装、网络配置
略...
3.JDK安装
版本:JDK1.8
步骤:略
- 新增 hadoop 用户增加sudo权限
1.新增用户
useradd hadoop
passwd hadoop
2.增加sudo权限
vi /etc/sudoers
新增 hadoop ALL=(ALL) ALL
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
hadoop ALL=(ALL) ALL
二、zookeeper安装
1.hadoop用户配置免密
1.各节点ssh-keygen生成RSA密钥和公钥(192.168.10.21~23)
ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa
2.将所有的公钥文件汇总到一个总的授权key文件中,在192.168.10.21 执行
ssh 192.168.10.21 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh 192.168.10.22 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh 192.168.10.23 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
3.出于安全性考虑,将这个授权key文件赋予600权限:
chmod 600 ~/.ssh/authorized_keys
4.将这个包含了所有互信机器认证key的认证文件,分发到各个机器中去
scp ~/.ssh/authorized_keys 192.168.10.22:~/.ssh/
scp ~/.ssh/authorized_keys 192.168.10.23:~/.ssh/
- 修改hosts
vi /etc/hosts
#Hadoop Cloud
192.168.10.21 hadoop01
192.168.10.22 hadoop02
192.168.10.23 hadoop03
3.上传安装包到hadoop01
下载:http://archive.apache.org/dist/zookeeper/
版本:apache-zookeeper-3.8.0-bin.tar.gz
注:zookeeper 好像从 3.5 版本以后,命名就发生了改变,如果是 apache-zookeeper-3.5.5.tar.gz 这般命名的,都是未编译的,而 apache-zookeeper-3.5.5-bin.tar.gz 这般命名的,才是已编译的包。
个人喜欢使用rz,先安装这个工具
sudo yum -y install lrzsz
1.创建目录
mkdir -p /home/hadoop/plat/zookeeper
2.上传安装包到该目录
3.解压
cd /home/hadoop/plat/zookeeper
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz
4.更改名称
mv apache-zookeeper-3.8.0-bin zookeeper-3.8.0
5.新增目录
mkdir -p /home/hadoop/plat/zookeeper/zookeeper-3.8.0/data
mkdir -p /home/hadoop/plat/zookeeper/zookeeper-3.8.0/logs
- 修改配置文件
1.配置文件修改
cd /home/hadoop/plat/zookeeper/zookeeper-3.8.0/conf
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
删除其中内容,并更改为
tickTime=2000
dataDir=/home/hadoop/plat/zookeeper/zookeeper-3.8.0/data
dataLogDir=/home/hadoop/plat/zookeeper/zookeeper-3.8.0/logs
clientPort=21001
initLimit=5
syncLimit=2
server.1=192.168.10.21:21002:21003
server.2=192.168.10.22:21002:21003
server.3=192.168.10.23:21002:21003
autopurge.purgeInterval=24
2.myid修改
cd /home/hadoop/plat/zookeeper/zookeeper-3.8.0/data
echo 1 > myid
5.分发到其他主机
1.配置put工具
cd /home/hadoop
vi .bashrc
新增如下内容
export hadoop01=192.168.10.21
export hadoop02=192.168.10.22
export hadoop03=192.168.10.23
put()
{
if [ $# != 2 ]
then
echo " put filename remotedir -- eg: put a.txt /home"
else
FileName=$1
DirName=$2
echo "${FileName} ${DirName}"
echo $hadoop0{2..3} | xargs -n1 |awk '{print $0}'
echo $hadoop0{2..3} | xargs -n1 | xargs -i scp -r ${FileName} {}:${DirName}
fi
}
2. 分发到其他两台主机
目标主机创建目录
mkdir -p /home/hadoop/plat/zookeeper
hadoop01主机
cd /home/hadoop/plat/zookeeper
put zookeeper-3.8.0 /home/hadoop/plat/zookeeper
3.修改hadoop02和hadoop03的myid
hadoop02 修改为 2
hadoop02 修改为 3
6.启动集群
1.配置环境变量
#Zookeeper
export ZOOKEEPER_HOME=/home/hadoop/plat/zookeeper/zookeeper-3.8.0
export PATH=${ZOOKEEPER_HOME}/bin:${PATH}
2.三台机器同时启动
cd /home/hadoop
zkServer.sh start
7.查看集群状态
zkServer.sh status
三、hadoop安装
1、安装jdk
2、配置hostname
3、配置hosts
4、版本选择
地址:http://archive.apache.org/dist/hadoop/core/
版本:hadoop-3.3.1.tar.gz
5、上传压缩包
1.hadoop01 创建目录
mkdir -p /home/hadoop/plat/hadoop
2.上传安装包到该目录并解压
tar -zxvf hadoop-3.3.1.tar.gz
6、配置环境变量
vi ~/.bashrc
#Hadoop
export HADOOP_HOME=/home/hadoop/plat/hadoop/hadoop-3.3.1
export PATH=${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin:${PATH}
7、配置文件修改
7.1 修改 hadoop-env.sh
cd ${HADOOP_HOME}/etc/hadoop
vi hadoop-env.sh
# The java implementation to use. By default, this environment
# variable is REQUIRED on ALL platforms except OS X!
# export JAVA_HOME=
export JAVA_HOME=/usr/local/src/jdk1.8.0_321
7.2 修改 core-site.xml
cd ${HADOOP_HOME}
mkdir data
cd ${HADOOP_HOME}/etc/hadoop
vi core-site.xml
<configuration>
<!-- 指定HADOOP所使用的文件系统schema(URI),HDFS的老大(NameNode)的地址 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop01:9000</value>
</property>
<!-- 指定hadoop运行时产生文件的存储目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoop/plat/hadoop/hadoop-3.3.1/data</value>
</property>
<!-- 在Web UI访问HDFS使用的用户名。-->
<property>
<name>hadoop.http.staticuser.user</name>
<value>hadoop</value>
</property>
</configuration>
7.3 修改 hdfs-site.xml
<configuration>
<!-- 设定SNN运行主机和端口。-->
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>hadoop02:9868</value>
</property>
<!-- 指定HDFS副本的数量 -->
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
7.4 修改 mapred-site.xml
<configuration>
<!-- 指定mapreduce运行在yarn上 -->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</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.5 修改 yarn-site.xml
<configuration>
<!-- 指定YARN的老大(ResourceManager)的地址 -->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>hadoop01</value>
</property>
<!-- reducer获取数据的方式 -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<!-- 关闭yarn内存检查 -->
<property>
<name>yarn.nodemanager.pmem-check-enabled</name>
<value>false</value>
</property>
<property>
<name>yarn.nodemanager.vmem-check-enabled</name>
<value>false</value>
</property>
<!--开启日志聚合-->
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
<!--日志聚合hdfs存储路径-->
<property>
<name>yarn.nodemanager.remote-app-log-dir</name>
<value>/home/hadoop/plat/hadoop/hadoop-3.3.1/logs/nodemanager-remote-app-logs</value>
</property>
<!--hdfs上的日志保留时间-->
<property>
<name>yarn.log-aggregation.retain-seconds</name>
<value>604800</value>
</property>
<!--应用执行时存储路径-->
<property>
<name>yarn.nodemanager.log-dirs</name>
<value>file:///home/hadoop/plat/hadoop/hadoop-3.3.1/logs/nodemanager-logs</value>
</property>
<property>
<!--应用执行完日志保留的时间,默认0,即执行完立刻删除-->
<name>yarn.nodemanager.delete.debug-delay-sec</name>
<value>604800</value>
</property>
</configuration>
7.6 修改workers
hadoop01
hadoop02
hadoop03
7.6 分发到其他主机
cd /home/hadoop/plat
put hadoop /home/hadoop/plat
7.7 初始化namenode
hdfs namenode -format
看到成功的标识
/home/hadoop/plat/hadoop/hadoop-3.3.1/data/dfs/name has been successfully formatted.
7.8 启动 hadoop
start-all.sh