hadoop 将nn节点的环境配置同步到dn节点

发布时间 2023-11-04 01:54:31作者: Evelynlb

使用scp命令克隆配置

输入

sudo scp -r jdk1.8.0_391/ hxf@slaver2:/opt/module

报错ssh: Could not resolve hostname hxf: Temporary failure in name resolution lost connection

发现是主机ip地址映射不对

sudo vim /etc/hosts

查看正确的映射

 代码改为

sudo scp -r jdk1.8.0_391/ hxf@hadoop102:/opt/module

成功解决

然后又报错scp: /opt/module/jdk1.8.0_391: Permission denied(猜测是应该用root权限执行也能解决?前面加个sudo)

发现是/opt/module/文件路径没有对应权限,在所有虚拟机中输入

sudo chmod 777 /opt/module/

问题解决

使用rsync同步配置,rsync和scp的区别就是scp是全量同步,rsync是增量同步

sudo rsync -av hive-3.1.2/ hxf@hadoop103:/opt/module

到dn节点的虚拟机中查看是否同步了文件

 同步成功了

输入

echo $PATH

查看系统路径

 在PATH里选一个路径创建脚本文件xsync(为了能在任何路径执行该文件)

我是在/usr/bin中创建

sudo vim /usr/bin/xsync

编辑

#!/bin/bash

# the numbers of args?
if [ $# -lt 1 ]
then
    echo Not Enough Arguement!
    exit;
fi

#  tarverse the cluster
for host in hadoop100 hadoop102 hadoop103
do
    echo ==================     $host     ========================
    # traverse the catelog
    for file in $@
    do
        #   whether the file exist
        if [ -e $file ]
        then
            # get the parent directory
            pdir=$(cd -P $(dirname $file); pwd)

            #  get the current file name
            fname=$(basename $file)
            ssh $host "mkdir -p $pdir"
            rsync -av $pdir/$fname $host:$pdir
        else
            echo $file does not exists!
        fi
    done
done

输入:wq保存退出

授予xsync执行权限

sudo chmod 777 /usr/bin/xsync

执行

xsync /etc/profile.d/my_env.sh 

无报错就算成功

注意!千万不能

sudo xsync /etc/profile.d/my_env.sh 

会报错permission deny,try again的,即使你的密码输对了具体原因参考SSH连接报错:Permission denied, please try again.的解决方法-腾讯云开发者社区-腾讯云 (tencent.com)

至此配置同步完成