• hadoop(五)scp命令copy文件和配置(完全分布式准备二)|7


    机器的克隆参考centos7克隆ip|机器名|映射关系|别名配置(hadoop完全分布式准备一)

    那么问题来了,如果我们有30台机器,之间可以互相访问,那我们如何快速安装配置环境如jdk hadoop等?
    可通过scp命令将配置、下载好的工具等直接copy到我们新的机器上就可以了。

    scp(secure copy)安全copy

    Scp定义:
    Scp可以实现服务器与服务器之间的数据copy。(from server1 to server2)
    基本语法

    Scp     -r         $pair/$fname                 $user@hadoop&host:$pdir/$fname
    命令  递归      要copy的文件路径/名称             目标用户@主机:目标路径名称
    

    操作实例
    在hadoop101上,将hadoop101中/opt/module目录下的软件copy到hadoop102上。

    scp/opt/module shaozhiqi@hadoop102:/opt
    

    实际操作时发现报错了:

    [shaozhiqi@hadoop101 ~]$ scp -r /opt/module shaozhiqi@hadoop102: /opt
    ^Z
    [1]+ Stopped scp -r /opt/module shaozhiqi@hadoop102: /opt/
    [shaozhiqi@hadoop101 ~]$ scp -r /opt/module  shaozhiqi@hadoop102:/opt/
    ssh: Could not resolve hostname hadoop102: Name or service not kno
    lost connection
    

    那就去修改hadoop101的/etc/hosts
    添加上与102/103/104等机器的映射配置,否则在执行命令时只能使用ip

    [shaozhiqi@hadoop101 ~]$ vi /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    192.168.1.101 hadoop101
    192.168.1.102 hadoop102
    192.168.1.103 hadoop103
    192.168.1.104 hadoop104
    192.168.1.105 hadoop105
    192.168.1.106 hadoop106
    192.168.1.107 hadoop107
    192.168.1.108 hadoop108
    

    Reboot后
    再次执行scp

    [shaozhiqi@hadoop101 ~]$ scp -r /opt/module shaozhiqi@hadoop102: /opt/module
    [shaozhiqi@hadoop102 module]$ ll
    total 8
    drwxr-xr-x. 15 shaozhiqi shaozhiqi 4096 Jun 22 22:04 hadoop-3.1.2
    drwxr-xr-x. 7 shaozhiqi shaozhiqi 4096 Jun 22 21:59 jdk1.8.0_211
    [shaozhiqi@hadoop102 module]$
    

    在103上将101的数据copy过来 ./表示当前目录

    [shaozhiqi@hadoop103 module]$ scp –r  shaozhiqi@hadoop101:/opt/module ./
    [shaozhiqi@hadoop103 module]$ ll
    total 8
    drwxr-xr-x. 15 shaozhiqi shaozhiqi 4096 Jun 22 22:41 hadoop-3.1.2
    drwxr-xr-x. 7 shaozhiqi shaozhiqi 4096 Jun 22 22:26 jdk1.8.0_211
    [shaozhiqi@hadoop103 module]$
    

    在103copy 102module到104,执行命令输入102和104的密码

    [shaozhiqi@hadoop103 module]$ scp -r shaozhiqi@hadoop102:/opt/module shaozhiqi@hadoop104:/opt/
    

    如果之前没有module,需要用root用户执行scp
    那么执行结束后就需要执行chown进行授权

    [shaozhiqi@hadoop103 opt]$ cd module/
    [shaozhiqi@hadoop103 module]$ ll
    total 8
    drwxr-xr-x. 15 root root 4096 Jun 23 00:21 hadoop-3.1.2
    drwxr-xr-x. 7 root root 4096 Jun 23 00:19 jdk1.8.0_211
    [shaozhiqi@hadoop103 opt]$ sudo chown shaozhiqi:shaozhiqi module/ -R
    [shaozhiqi@hadoop103 opt]$ ll
    total 0
    drwxr-xr-x. 4 shaozhiqi shaozhiqi 44 Jun 23 00:19 module
    drwxr-xr-x. 2 shaozhiqi shaozhiqi 6 Jun 18 05:58 software
    

    将101上配置的环境变量copy过来
    cat /etc/profile

    [shaozhiqi@hadoop101 ~]$ scp /etc/profile root@hadoop102:/etc/profile
    root@hadoop102's password:
    profile 100% 1985 1.9KB/s 00:00   
    [shaozhiqi@hadoop101 ~]$ scp /etc/profile root@hadoop103:/etc/profile
    root@hadoop103's password:
    profile 100% 1985 1.9KB/s 00:00   
    [shaozhiqi@hadoop101 ~]$ scp /etc/profile root@hadoop104:/etc/profile
    root@hadoop104's password:
    profile 100% 1985 1.9KB/s 00:00   
    [shaozhiqi@hadoop101 ~]$
    

    重新加载环境配置
    source /etc/profile
    java –version
    如果是openJKD则可删除
    删除方式参考[Hadoop学习(一) centos7 jdk安装,hadoop安装
    删除后再次
    source /etc/profile
    验证

    [shaozhiqi@hadoop103 ~]$ java -version
    java version "1.8.0_211"
    Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
    [shaozhiqi@hadoop103 ~]$
  • 相关阅读:
    ArcGis Python脚本——遍历输出面或折线要素的折点坐标
    ArcGis Python脚本——根据接图表批量裁切分幅影像
    ArcGis安装失败提示“需要Microsoft .NET Framework 3.5 sp1或等效环境”的解决方法
    PLSQL Developer 远程连接Oracle数据库
    Oracle使用PLSQL导入数据后中文乱码的解决方法
    使用ArcMap做一个1:5000标准分幅图并编号
    ArcGis地理坐标系转投影坐标系问题的思考与处理
    CI框架 输入类
    PHP获取当前页面的URL作为参数以供下一层的页面可以返回上一层页面
    用js实现返回上一页
  • 原文地址:https://www.cnblogs.com/shaozhiqi/p/11534628.html
Copyright © 2020-2023  润新知