• 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 ~]$
  • 相关阅读:
    Windows7下安装搭建Ngnix教程和配置详解
    CentOS6.6图文详细安装教程(有些设置大部分教程没出现过,附带网络设置等)
    每日一句(2014-8-29)
    每日一句(2014-8-28)
    每日一句(2014-8-27)
    javascript验证键盘keycode
    每日一句(2014-8-26)
    每日一句(2014-8-25)
    javascript 学习记录
    每日一句(2014-8-22)
  • 原文地址:https://www.cnblogs.com/shaozhiqi/p/11534628.html
Copyright © 2020-2023  润新知