Hadoop完全分布式安装

Hadoop完全分布式安装

​ 本节介绍安装Hadoop完全分布式的主要步骤。本次实验使用三个节点来搭建集群环境:一台机器作为Master节点,具体的集群规划如下表所示:

主机名masterslaves1slaves2
HDFSNameNode
DataNode
DataNode
SecondaryNameNode
DataNode
YARNNodeManagerr
ResourceManager
NodeManagerNodeManage

​ 在安装Hadoop完全分布式前,我们需要完成一些准备工作,包括网络配置、关闭防火墙、安装SSH和安装JDK环境等。

一、网络配置:

​ 动态分配的IP地址是临时的,它会在一定时间内释放该IP地址供其他机器使用,因此使用该方式获取的IP地址不是固定的,这样会导致集群不稳定。因此我们需要设置为静态IP,具体操作如下:

  1. 打开【/etc/sysconfig/network-scripts/ifcfg-ens33】文件。

    vi /etc/sysconfig/network-scripts/ifcfg-ens33
    
  2. 该文件为网卡配置文件,对该文件做以下修改:

    BOOTPROTO="static"
    

    打开虚拟机【编辑】->【虚拟网络编辑器】,查看VMnet8网卡的子网IP地址。

    在这里插入图片描述

    点击【NAT设置】界面,查看网关IP地址。

    在这里插入图片描述

    再向ifcfg-ens33添加以下内容:

    IPADDR=192.168.80.160	#前3个数必须与网关IP的前3个数必须一致,最后一个数则随机填入1-255的数字,组成新的IP地址,该IP必须是未被占用的。
    GATEWAY=192.168.80.2	#输入VMnet8网关IP地址
    DNS1=114.114.114.114
    

    注意:此处每台机器节点配置不一样,大家先进行子网IP查询,再添加以上内容。

  3. 重启网络

    systemctl restart network
    
  4. 网络测试,尝试连接百度地址,如果能正常连接成功,则表示网络配置完成。

    ping www.baidu.com
    

在这里插入图片描述

二、关闭防火墙和SELinux

注意:这个步骤只是为了我们学习方便,在实际工作中绝对不可以关闭防火墙,只能在防火墙配置需要开放的端口即可。

  1. 查看当前防火墙状态

    systemctl status firewalld.service
    

    CentOS 7默认是开机启动防火墙。因此我们要关闭防火墙并停止开启自动启动防火墙设置。

    在这里插入图片描述

  2. 关闭当前防火墙

    systemctl stop firewalld.service
    
  3. 关闭防火墙的开机自启

    systemctl disable firewalld
    
  4. 关闭后再查看防火墙状态。

    systemctl status firewalld.service
    

    在这里插入图片描述

    如果防火墙状态变为Inactive(dead)状态,则表示防火墙关闭成功。

    关闭完防火墙后,我们即可使用XShell工具连接。

    1. Linux有一个安全模块:SELinux,用以限制用户和程序的相关权限,来确保系统的安全稳定。SELinux的配置同防火墙一样,非常复杂,课程中不多涉及,后续视情况可以出一章SELinux的配置课程。在当前,我们只需要关闭SELinux功能,避免导致后面的软件运行出现问题即可,

      修改/etc/sysconfig/selinux文件

      vim /etc/sysconfig/selinux
      

      修改文件内容。

      #将第7行的SELINUX=enforcing改为,保存退出后,重启虚拟机即可,千万要注意disabled单词不要写错,不然无法启动系统
      SELINUX=disabled
      
三、安装常用工具
  1. 安装net-tools工具

    yum install -y net-tools
    
  2. 安装vim工具

    yum install -y vim
    
四、安装JDK1.8环境

​ 后续的大数据集群软件,多数是需要Java运行环境的,所以我们为每一台机器都配置JDK环境。

  1. 从Java官网中下载JDK1.8安装包,下载地址为:Java Downloads | Oracle

  2. 上传JDK安装包到CentOS虚拟机。
    创建一个目录/root/module,专门存放软件安装包

    mkdir /root/module
    

    使用XFTP工具上传JDK安装包到/root/module目录下。

  3. 解压JDK安装包。

    cd /root/module
    tar -zxvf jdk-8u391-linux-x64.tar.gz -C /usr/local/
    
  4. 更改jdk目录名字

    cd /usr/local/
    mv jdk1.8.0_391 jdk1.8
    
  5. 配置环境变量,编辑/etc/profile文件,将JDK路径添加到PATH环境变量中。

    vim /etc/profile
    

    在/etc/profile文件末端添加以下内容

    #JAVA HOME
    export JAVA_HOME=/usr/local/jdk1.8
    export PATH=$PATH:$JAVA_HOME/bin
    
  6. 刷新环境变量

    source /etc/profile
    
  7. 验证JDK是否生效

    java -verison
    

在这里插入图片描述

出现Java版本号信息,则证明JDK安装完成。

五、 复制CentOS镜像

安装集群化软件,首要条件就是要有多台Linux服务器可用。我们可以使用VMware提供的克隆功能,将我们的虚拟机额外克隆出3台来使用。

  1. 首先,关闭当前CentOS系统虚拟机

  2. 在VMWare工具中新建文件夹,命名为:Hadoop集群,将master机器拖到Hadoop集群文件夹中。
    在这里插入图片描述

  3. 克隆master节点。鼠标右键点击【master】节点,选择【管理】->【克隆】进入虚拟机克隆管理界面。
    在这里插入图片描述
    克隆虚拟机当前状态。
    在这里插入图片描述
    选择【创建完整克隆】
    在这里插入图片描述

    虚拟机名称为salves1,并设置虚拟机保存路径。点击【完成】。
    在这里插入图片描述

  4. 按照以上操作,克隆出第三个节点:slaves2,并将slaves1与slaves2放到Hadoop集群文件夹中。
    在这里插入图片描述

  5. 开启slaves1节点,修改slaves1节点的配置。

    ① 修改slaves1节点的主机名为slaves1

    hostnamectl set-hostname slaves1
    

    ② 修改slaves1节点的固定ip为:192.168.80.161**(注意IP地址前3个数需跟VMnet8 IP网关地址前3个数必须一致)**

    vim /etc/sysconfig/network-scripts/ifcfg-ens33
    

    修改IPADDR的值

    IPADDR=192.168.80.161
    
  6. 开启slaves2节点,修改slaves2节点的配置。

    按照第5步步骤,将slaves2节点的主机名设置为slaves2,ip设置为:192.168.80.162**(注意IP地址前3个数需跟VMnet8 IP网关地址前3个数必须一致)**

  7. 配置主机名映射

    修改3台节点的/etc/hosts文件。

    vim /etc/hosts
    

    在文件末端添加以下内容

    192.168.80.160	master
    192.168.80.161	slaves1
    192.168.80.162	slaves2
    
六、 配置SSH免密登录

​ 后续安装的集群,都需要远程登录以及远程执行命令,我们可以简单起见,配置三台Linux服务器之间的免密码互相SSH登陆。

  1. 在每一台机器执行

    ssh-keygen -t rsa
    

    一直回车确认即可。

  2. 在每一台机器节点执行一下指令,

    ssh-copy-id master
    ssh-copy-id slaves1
    ssh-copy-id slaves2
    #进行免密操作时会询问是否继续连接,输入“yes”后,再输入登录密码完成操作。
    
  3. 执行完毕后,使用SSH测试远程登录,如果三台机器能相互登录,且无须输入密码,即代表免密配置成功。

    ssh master		#远程登录master节点
    exit			#退出登录
    ssh slaves1		#远程登录slaves1节点
    exit			#退出登录
    ssh slaves2		#远程登录slaves2节点
    exit			#退出登录
    
七、 Hadoop集群部署
  1. 下载Hadoop安装包。打开浏览器,在浏览器地址栏中输入以下地址:https://archive.apache.org/dist/hadoop/common/hadoop-3.1.3/。

  2. 选择hadoop-3.1.3.tar.gz 版本下载hadoop安装包。
    在这里插入图片描述

    下载完毕后,使用XFTP工具将安装包上传到master节点的/root/module目录下。

  3. 解压hadoop安装包

    cd /root/module
    #解压Hadoop压缩包
    tar -zxvf hadoop-3.1.3.tar.gz -C /usr/local/
    
    #更改hadoop目录名称
    mv /usr/local/hadoop-3.1.3 /usr/local/hadoop
    
  4. 配置Hadoop环境变量

    vim /etc/profile
    

    在/etc/profile文件末端添加Hadoop路径到环境变量中。

    #HADOOP ENV
    export HADOOP_HOME=/usr/local/hadoop
    export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
    export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
    export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
    

    保存退出,刷新环境变量。

    source /etc/profile
    
  5. 修改Hadoop配置文件。

    Hadoop的配置文件要修改的地方很多,请细心!!!!进入到/usr/local/hadoop/etc/hadoop文件夹中,配置文件都在这里

    cd /usr/local/hadoop/etc/hadoop
    

    ① 修改hadoop-env.sh

    vim hadoop-env.sh
    

    在文件开头添加以下内容

    export JAVA_HOME=/usr/local/jdk1.8
    
    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
    

    ② 修改core-site.xml

    vim core-site.xml
    

    <configuration>标签之间添加fs.defaultFS属性,具体配置如下:

    <?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://master:9000</value>
        </property>
    	<!--配置Hadoop运行产生的临时数据存储目录-->
        <property>
            <name>hadoop.tmp.dir</name>
            <value>/usr/local/hadoop/tmp</value>                 
            <description>Abase for other temporary directories.</description>
        </property>
    </configuration>
    

    ③ 修改hdfs-site.xml文件

    vim 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>
        <!-- 2nn web端访问地址-->
        <property>
            <name>dfs.namenode.secondary.http-address</name>
            <value>slaves1:9890</value>
        </property>
    	 <!-- namenode 数据存放地址-->
        <property>
         	<name>dfs.namenode.name.dir</name>
         	<value>file:///usr/local/hadoop/tmp/hdfs/name</value>
       </property>
    	<!--  datanode 数据存放地址-->
    	<property>
         	<name>dfs.datanode.data.dir</name>
            <value>file:///usr/local/hadoop/tmp/hdfs/data</value>
    	</property>
        <!-- 设置副本数量 -->
        <property>
            <name>dfs.replication</name>
            <value>3</value>
        </property>
    </configuration>
    

    ④ 修改mapred-site.xml文件

    vim 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程序运行在Yarn上 -->
        <property>
        	<name>mapreduce.framework.name</name>
        	<value>yarn</value>
      	</property>
    
      	<property>
        	<name>mapreduce.jobhistory.address</name>
        	<value>master:10020</value>
      	</property>
      	<property>
        	<name>mapreduce.jobhistory.webapp.address</name>
        	<value>master:19888</value>
      	</property>
    	<property>
      		<name>yarn.app.mapreduce.am.env</name>
      		<value>HADOOP_MAPRED_HOME=/usr/local/hadoop</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>
    

    ⑤ 修改yarn-site.xml文件

    vim yarn-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.
    -->
    <configuration>
    	<!-- 指定MR走shuffle -->
        <property>
            <name>yarn.nodemanager.aux-services</name>
            <value>mapreduce_shuffle</value>
        </property>
        <!-- 指定ResourceManager的地址-->
        <property>
            <name>yarn.resourcemanager.hostname</name>
            <value>master</value>
        </property>
        <!--指定Yarn调度器-->
        <property>
            <name>yarn.resourcemanager.scheduler.class</name>
                						<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
      </property>
    </configuration>
    

    ⑥修改workers文件

    vim workers
    

    在workers文件添加以下内容

    master
    slaves1
    slaves2
    
  6. 分发hadoop文件夹到slaves1与slaves2节点

    #在master节点执行
    cd /usr/local
    #复制hadoop到slaves1与slaves2
    scp -r hadoop slaves1:/usr/local/
    scp -r hadoop slaves2:/usr/local/
    #复制/etc/profile文件到slaves1与slaves2
    scp /etc/profile slaves1:/etc/profile
    scp /etc/profile slaves2:/etc/profile
    
  7. 格式化NameNode,在master节点上运行以下命令,完成格式化

    hdfs namenode -format
    

    当出现【succesfully formatted】的时候,代表格式化成功。
    在这里插入图片描述

  8. 启动hadoop集群,在master节点执行即可

    start-all.sh
    
  9. 使用jps指令查看进程

    master:在master节点运行着 NameNode、DataNode、NodeManager、ResouceManager 4个进程。
    在这里插入图片描述
    slaves1:在slaves1节点运行着 SecondaryNameNode、DataNode、NodeManager3个进程。
    在这里插入图片描述
    slaves2:在slaves2节点运行着 NodeManger、DataNode2个进程。
    在这里插入图片描述

  • 16
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值