系统相关
首页 > 系统相关> > Centos7系统的Hadoop3.2.2集群环境搭建

Centos7系统的Hadoop3.2.2集群环境搭建

作者:互联网

Centos7系统的Hadoop3.2.2集群环境搭建

准备工作:

jdk-8u291-linux-x64.tar.gz

image-20210602213855449

hadoop-3.2.2.tar.gz

image-20210602213954837

虚拟机hadoop,hadoop1,hadoop2配置:

hadoop就Hadoop1hadoop2
IP192.168.10.100192.168.10.101192.168.10.102

集群规划:

hadoophadoop1hadoop2
HDFSNameNode DateNodeDateNodeSeconaryNameNode DateNode
YARNNadeManagerResourceManager NodeManagerNodeManager

创建模板机hadoop:

修改网络连接方式为NAT模式
image-20210602175809037
修改虚拟适配器VMnet8:
在这里插入图片描述

(一)IP和主机名:

创建用户hadoop,修改密码为123456:

[root@h ~]# useradd hadoop
[root@h ~]# passwd 

配置hadoop用户具有root权限,方便后期sudo执行root权限的命令:

[root@h ~]# vim /etc/sudoers
# 在最后添加
hadoop   ALL=(ALL)   NOPASSWD:ALL

image-20210602193527970
关闭防火墙:

[root@h ~]# systemctl stop firewalld.service 
[root@h ~]# systemctl disable firewalld.service 

修改主机名:

[root@h ~]# vim /etc/hostname

把原来的主机名删了,修改为hadoop:

image-20210602175148022

修改ip地址映射:

[root@h ~]# vim /etc/hosts

image-20210602175314118
修改为静态ip:

[root@h ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
#修改以下内容:
BOOTPROTO=static  #将dhcp改为static
ONBOOT="yes"        #是否开机启动,将no改为yes
#添加以下内容
IPADDR=192.168.10.100  #ip地址
GATEWAY=192.168.10.2   #网关
DNS1=192.168.10.2      #dns

#重启网卡
[root@h ~]# systemctl restart network
#如果重启网卡失败,尝试关闭NetworkManager
systemctl stop NetworkManager    
systemctl disable NetworkManager #表示开机不启动

切换用户hadoop,创建/opt/jdk—hadoop目录,用来存放jdk,hadoop:

[hadoop@hadoop ~]$ mkdir /opt/jdk-hadoop

(二)克隆模板虚拟机hadoop,生成hadoop1,hadoop2

进入hadoop1,修改主机名与ip(192.168.10.101):

[root@hadoop ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
#修改以下内容
IPADDR=192.168.10.101  #ip地址

修改主机名为hadoop1:

[root@hadoop ~]# vim /etc/hostname

进入hadoop2,修改主机名与ip(192.168.10.102):

[root@hadoop ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
#修改以下内容
IPADDR=192.168.10.102  #ip地址

修改主机名为hadoop2:

[root@hadoop ~]# vim /etc/hostname

(三)ssh免密登录:

1.在虚拟机hadoop的hadoop用户下生成ssh秘钥

[hadoop@hadoop ~]$ ssh-keygen -t rsa #一路回车

2.将公钥分发给其余两台虚拟机的hadoop用户:

[hadoop@hadoop ~]$ ssh-copy-id -i hadoop@192.168.10.100 #本机
[hadoop@hadoop ~]$ ssh-copy-id -i hadoop@192.168.10.101 #hadoop1
[hadoop@hadoop ~]$ ssh-copy-id -i hadoop@192.168.10.102 #hadoop2

3.现在确认能否不输入口令就用ssh登录localhost:

[hadoop@hadoop ~]$ ssh localhost

4.如果不输入口令就无法用ssh登陆localhost,执行下面的命令:

[hadoop@hadoop ~] ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
[hadoop@hadoop ~] cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

进入虚拟机hadoop1,hadoop2重复1~4的操作

(四)jdk安装:

将jdk的压缩包放在/opt/jdk-hadoop目录下并解压到/opt/jdk-hadoop目录下:

# 进入/opt/jdk-hadoop目录中解压得到文件夹 jdk1.8.0_291
tar -zxvf jdk-8u291-linux-x64.tar.gz

编辑/etc/profile文件,在文件末尾添加以下内容

# 设置 jdk 环境变量
export JAVA_HOME=/opt/jdk-hadoop/jdk1.8.0_291
export PATH$PATH:JAVA_HOME/bin:
# 使环境变量生效
source /etc/profile
# 任意目录下测试环境变量是否生效
java -version
java version "1.8.0_291"

image-20210602191102626

(五)Hadoop的安装

将hadoop的压缩包放在/opt/jdk-hadoop目录下并解压到/opt/jdk-hadoop目录下:

# 进入/opt/jdk-hadoop目录中解压 Hadoop 到/opt/jdk-hadoop
tar -zxf hadoop-3.2.2.tar.gz 

编辑/etc/profile文件,在文件末尾添加以下内容:

# set hadoop path
export HADOOP_HOME=/opt/jdk-hadoop/hadoop-3.2.2
export PATH=$PATH:$HADOOP_HOME/bin
# 使环境变量生效
source /etc/profile
# 测试环境变量是否生效,任意目录下输入
hadoop

image-20210602191005999

(六)修改Hadoop文件

(1)hadoop-env.sh

cd /opt/jdk-haoop/hadoop-3.2.2/etc/hadoop/
vim hadoop-env.sh
# 添加以下内容
export JAVA_HOME=/usr/java/jdk1.8.0_291

(2)core-site.xml

<configuration>
   <property>
      <name>fs.defaultFS</name>
      <value>hdfs://hadoop:9000</value>
    </property>
     <property>
           <name>hadoop.tmp.dir</name>
           <value>/opt/jdk-haoop/hadoop-3.2.2/data</value>
     </property>

</configuration>

(3)hdfs-site.xml

<configuration> 
     <property>
           <name>dfs.namenode.http-address</name>
           <value>hadoop:9870</value>
     </property>
     <property>
           <name>dfs.namenode.secondary.http-address</name>
           <value>hadoop2:9868</value>
     </property>
</configuration>

(4)mapred-site.xml

<configuration>
    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
</configuration>

(5)yarn-site.xml

<configuration>
      <property>
           <name>yarn.nodemanager.aux-services</name>
           <value>mapreduce_shuffle</value>
     </property>
     <property>
           <name>yarn.resourcemanager.hostname</name>
           <value>hadoop1</value>
     </property>
</configuration>

分发jdk与hadoop给虚拟机hadoop1,hadooop2

scp -r /opt/jdk-hadoop/hadoop-3.3.2 hadoop@hadoop1:/opt/jdk-hadoop
scp -r /opt/jdk-hadoop/hadoop-3.3.2 hadoop@hadoop2:/opt/jdk-hadoop

格式化namenode:

cd /opt/jdk-hadoop/hadoop-3.2.2
hdfs namenode -format

启动hadoop:

cd /opt/jdk-hadoop/hadoop-3.2.2/sbin
./start-all.sh

在三台虚拟机上分别输入jps,显示如下则符合集群规划:

hadoophadoop1hadoop2
HDFSNameNode DateNodeDateNodeSeconaryNameNode DateNode
YARNNadeManagerResourceManager NodeManagerNodeManager

hadoop:

[hadoop@hadoop hadoop]s ]$
7585 Namenode
7703 Datanode
8344 Jps
8190 Nodemanager
[hadoop@hadoop hadoop]$

hadoop1:

[hadoop@hadoop hadoop]s ]$ jps
2913 Jps
2690 Datanode
2814 Nodemanager
[hadoop@hadoop hadoop]$

hadoop2:

[hadoop@hadoop hadoop]s ]$ jps
2913 Jps
3280 Datanode
2814 SecondaryNameNode
[hadoop@hadoop hadoop]$

参考地址:http://hadoop.apache.org/docs/r1.0.4/cn/cluster_setup.html

标签:opt,jdk,hadoop,Centos7,etc,Hadoop3.2,集群,ssh,root
来源: https://blog.csdn.net/weixin_48646819/article/details/117535285