0


hadoop集群搭建

准备三台虚拟机

hadoop1 hadoop2 hadoop3 ip分别为:192.168.56.211,192.168.56.212,192.168.56.213

配置三台虚拟机的主机名和映射

vi /etc/hosts 分别添加如下内容:

192.168.56.211 hadoop1
192.168.56.212 hadoop2
192.168.56.213 hadoop3

分别配置三台虚拟机的主机名为:hadoop1 hadoop2 hadoop3
vi /etc/hostname
添加主机名

三台机器上关闭防火墙

systemctl stop firewalld

systemctl disable firewalld

三台机器上安装同步命令

yum install -y rsync

三台机器配置免密登录

分别在三台机器上执行:

a ssh-keygen -t rsa 按三次回车 ----生成ssh登录的公钥和私钥

b ssh-copy-hadoop1 输入对应机器的登录密码
ssh-copy-hadoop2 输入对应机器的登录密码
ssh-copy-hadoop3 输入对应机器的登录密码

创建命令目录

/myshell 用于存放jpsall、xsync、myhadoop命令脚本,并授权:

chmod 777 jpsall
chmod 777 xsync
chmod 777 myhadoop

jpsall脚本如下:

#!/bin/bash

for host in hadoop1 hadoop2 hadoop3
do
        echo ============$host============
        ssh $host jps
done

xsync脚本如下:

#!/bin/bash

if [ $# -lt 1 ]
then 
    echo Not Enough Arguement
    exit;
fi

for host in hadoop1 hadoop2 hadoop3
do 
    echo ======$host=====
    
    for file in $@
    do
        if [ -e $file ]
            then 
                pdir=$(cd -P $(dirname $file); pwd)
                fname=$(basename $file)
                ssh $host "mkdir -p $pdir"
                rsync -av $pdir/$fname $host:$pdir
            else
                echo $file does not exits!
        fi
    done
done

myhadoop脚本如下:

#!/bin/bash

if [ $# -lt 1 ]
then 
    echo Not Enough Arguement
    exit;
fi

case $1 in
"start")
    echo "=========启动hadoop集群============="
    
    echo "---------启动hdfs-------------------"
    ssh hadoop1 "/soft/hadoop-3.3.1/sbin/start-dfs.sh"
    echo "---------启动yarn-------------------"
    ssh hadoop2 "/soft/hadoop-3.3.1/sbin/start-yarn.sh"
    echo "---------启动hisotryserver----------"
    ssh hadoop1 "/soft/hadoop-3.3.1/bin/mapred --daemon start historyserver"
;;
"stop")
    echo "=========关闭hadoop集群============="
    echo "---------关闭hisotryserver----------"
    ssh hadoop1 "/soft/hadoop-3.3.1/bin/mapred --daemon stop historyserver"
    echo "---------关闭yarn-------------------"
    ssh hadoop2 "/soft/hadoop-3.3.1/sbin/stop-yarn.sh"
    echo "---------关闭hdfs-------------------"
    ssh hadoop1 "/soft/hadoop-3.3.1/sbin/stop-dfs.sh"
;;
*)
    echo "input args error"
esac

上传jdk和hadoop压缩包,并解压缩

jdk-8u321-linux-x64.tar.gz
hadoop-3.3.1.tar.gz

配置环境变量

在/etc/profile.d目录下创建 myenv.sh
输入内容如下:

export JAVA_HOME=/soft/jdk1.8.0_321              
export PATH=$PATH:$JAVA_HOME/bin                
export PATH=$PATH:/soft/hadoop-3.3.1/bin         
export PATH=$PATH:/soft/hadoop-3.3.1/sbin       
export PATH=$PATH:/mycmd/bin   

其中路径根据实际情况填写

使配置立即生效

source /etc/profile

修改hadoop配置文件

配置文件目录:/soft/hadoop-3.3.1/etc/hadoop

core-site.xml配置文件在<configuration>中添加如下:

<property>
        <name>fs.defaultFS</name>
        <value>hdfs://192.168.56.211:8020</value>
 </property>

 <property>
        <name>hadoop.tmp.dir</name>
        <value>/soft/hadoop-3.3.1/data</value>
 </property>

 <property>
        <name>hadoop.http.staticuser.user</name>
        <value>root</value>
 </property>

hdfs-site.xml配置文件在<configuration>中添加如下:

<property>
        <name>dfs.namenode.http-address</name>
        <value>192.168.56.211:9870</value>
 </property>

 <property>
        <name>dfs.namenode.secondary.http-address</name>
        <value>192.168.56.213:9868</value>
 </property>

yarn-site.xml配置文件在<configuration>中添加如下:

<property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
 </property>

 <property>
        <name>yarn.resourcemanager.hostname</name>
        <value>hadoop2</value>
 </property>

  <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>

  <property>
     <name>yarn.log-aggregation-enable</name>
     <value>true</value>
  </property>

  <property>
        <name>yarn.log.server.url</name>
        <value>http://192.168.56.211:19888</value>
    </property>

  <property>
        <name>yarn.log-aggregation.retain-seconds</name>
        <value>640800</value>
    </property>

mapred-site.xml配置文件在<configuration>中添加如下:

<property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.address</name>
        <value>192.168.56.211:10020</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.webapp.address</name>
        <value>192.168.56.211:19888</value>
    </property>

修改workers文件内容为:注意前后不要有空格,不要有空行

hadoop1
hadoop2
hadoop3

修改启动命令(使用root用户启动时需要)

分别修改/soft/hadoop-3.3.1/bin目录下:
start-dfs.sh stop-dfs.sh
在文件最前方添加如下:

HDFS_DATANODE_USER=root
HADOOP_SECURE_DN_USER=hdfs
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root

修改start-yarn.sh stop-yarn.sh
在文件最前方添加如下:

YARN_RESOURCEMANAGER_USER=root
HADOOP_SECURE_DN_USER=yarn
YARN_NODEMANAGER_USER=root

同步hadoop配置和环境配置到hadoop2、hadoop3

xsync /soft/hadoop-3.3.1/
xsync /soft/jdk1.8.0_321/
xsync /etc/profile.d/myenv.sh
xsync /myshell/
并分别到hadoop2、hadoop3上执行source /etc/profile

格式化hadoop(hadoop1上执行)

第一次启动时格式化,后续启动hadoop不要格式化

hdfs namenode -format

启动hadoop集群

myhadoop start --启动hadoop集群

查看集群启动情况

jspall

查看到类似如下内容表示启动成功

 ============hadoop1============
19490 DataNode
19907 JobHistoryServer
20422 Jps
19773 NodeManager
19326 NameNode
============hadoop2============
15920 ResourceManager
15735 DataNode
16061 NodeManager
16861 Jps
============hadoop3============
13089 DataNode
13797 Jps
13270 NodeManager
13193 SecondaryNameNode
标签: hadoop java 服务器

本文转载自: https://blog.csdn.net/qq_39203337/article/details/134311693
版权归原作者 昱宸星光 所有, 如有侵权,请联系我们删除。

“hadoop集群搭建”的评论:

还没有评论