标签:目录 ane oob 访问时间 输出 加强 用户名 速度 远程
手上有4台阿里云,正好可以搭建集群,就要把刚刚配置的单节点的数据拷贝过去。
(1)scp定义:
scp可以实现服务器与服务器之间的数据拷贝。(from server1 to server2)
(2)基本语法
Linux scp 命令用于 Linux 之间复制文件和目录。
scp 是 secure copy 的缩写, scp 是 linux 系统下基于 ssh 登陆进行安全的远程文件拷贝命令。
scp 是加密的,rcp 是不加密的,scp 是 rcp 的加强版。
scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 [...] [[user@]host2:]file2
简易写法:
scp [可选参数] file_source file_target
参数说明:
命令格式:
scp local_file remote_username@remote_ip:remote_folder 或者 scp local_file remote_username@remote_ip:remote_file 或者 scp local_file remote_ip:remote_folder 或者 scp local_file remote_ip:remote_file
应用实例:
scp /home/space/music/1.mp3 root@www.runoob.com:/home/root/others/music scp /home/space/music/1.mp3 root@www.runoob.com:/home/root/others/music/001.mp3 scp /home/space/music/1.mp3 www.runoob.com:/home/root/others/music scp /home/space/music/1.mp3 www.runoob.com:/home/root/others/music/001.mp3
(3)案例实操
(a)在hadoop101上,将hadoop101中/opt/module目录下的软件拷贝到其他节点上。
[root@hadoop001 hadoop]# scp -r /opt/module root@hadoop002:/opt/module The authenticity of host ‘hadoop002 (47.111.251.212)‘ can‘t be established. ECDSA key fingerprint is SHA256:YNsodxgiTBhRi6BaO1LqQrkOeudAVMaRisZJQdaJdAA. ECDSA key fingerprint is MD5:b5:82:88:93:92:6a:01:ed:4d:6f:80:bc:68:1a:e8:c9. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ‘hadoop002,47.111.251.212‘ (ECDSA) to the list of known hosts. root@hadoop002‘s password: Permission denied, please try again. root@hadoop002‘s password: THIRDPARTYLICENSEREADME.txt 100% 142KB 6.2MB/s 00:00 LICENSE 100% 11KB 1.9MB/s 00:00 NOTICE 100% 13KB 2.2MB/s 00:00 3RDPARTY 100% 11KB 1.8MB/s 00:00 dblook.bat 100% 1387 236.1KB/s 00:00
(b)将hadoop101中/etc/profile文件拷贝到其他节点的/etc/profile上。
[root@hadoop001 hadoop-2.7.2]# scp /etc/profile root@hadoop002:/etc/profile root@hadoop002‘s password: profile 100% 2012 342.8KB/s 00:00 [root@hadoop001 hadoop-2.7.2]# scp /etc/profile root@hadoop003:/etc/profile root@hadoop003‘s password: profile 100% 2012 529.6KB/s 00:00 [root@hadoop001 hadoop-2.7.2]# scp /etc/profile root@hadoop004:/etc/profile
注意:拷贝过来的配置文件别忘了source一下/etc/profile,。
2. rsync 远程同步工具
rsync主要用于备份和镜像。具有速度快、避免复制相同内容和支持符号链接的优点。
rsync和scp区别:用rsync做文件的复制要比scp的速度快,rsync只对差异文件做更新。scp是把所有文件都复制过去。
(1)基本语法
rsync -rvl $pdir/$fname $user@hadoop$host:$pdir/$fname
命令 选项参数 要拷贝的文件路径/名称 目的用户@主机:目的路径/名称
选项参数说明
表2-2
选项 |
功能 |
-r |
递归 |
-v |
显示复制过程 |
-l |
拷贝符号连接 |
(2)案例实操
(a)把hadoop101机器上的/opt/module目录同步到hadoop003服务器的root用户下的/opt/目录
[root@hadoop001 hadoop]# vim /etc/hosts [root@hadoop001 hadoop]# rsync -rvl /opt/module/ root@hadoop003:/opt/module The authenticity of host ‘hadoop003 (47.111.232.53)‘ can‘t be established. ECDSA key fingerprint is SHA256:YKGJjhv5Q/fneno2xR5HWQjFBkeZL09SF4RwtWI8tC4. ECDSA key fingerprint is MD5:30:ad:2b:59:1c:a8:37:d3:bf:69:6b:7d:8f:ee:3b:b8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ‘hadoop003,47.111.232.53‘ (ECDSA) to the list of known hosts. root@hadoop003‘s password: sending incremental file list created directory /opt/module ./ hadoop-2.7.2/ hadoop-2.7.2/LICENSE.txt hadoop-2.7.2/NOTICE.txt hadoop-2.7.2/README.txt hadoop-2.7.2/hdfs-site.xml hadoop-2.7.2/bin/ hadoop-2.7.2/bin/container-executor hadoop-2.7.2/bin/hadoop
3. xsync集群分发脚本
(1)需求:循环复制文件到所有节点的相同目录下
(2)需求分析:
(a)rsync命令原始拷贝:
rsync -rvl /opt/module root@hadoop103:/opt/
(b)期望脚本:
xsync要同步的文件名称
(3)脚本实现
(a)在/usr/local/bin目录下xsync创建文件,文件内容如下:
[root@hadoop002 module]# cd /usr/local/bin [root@hadoop002 bin]# ll total 4 -rw-r--r-- 1 root root 498 Jan 14 22:57 xsync [root@hadoop002 bin]# chmod 777 xsync [root@hadoop002 bin]# ll total 4 -rwxrwxrwx 1 root root 498 Jan 14 22:57 xsync [root@hadoop002 bin]# pwd /usr/local/bin [root@hadoop002 bin]# cat xsync #!/bin/bash #1 获取输入参数个数,如果没有参数,直接退出 pcount=$# if((pcount==0)); then echo no args; exit; fi #2 获取文件名称 p1=$1 fname=`basename $p1` echo fname=$fname #3 获取上级目录到绝对路径 pdir=`cd -P $(dirname $p1); pwd` echo pdir=$pdir #4 获取当前用户名称 user=`whoami` #5 循环 for((host=3; host<5; host++)); do echo ------------------- hadoop$host -------------- rsync -rvl $pdir/$fname $user@hadoop00$host:$pdir done [root@hadoop002 bin]#
标签:目录 ane oob 访问时间 输出 加强 用户名 速度 远程
原文地址:https://www.cnblogs.com/dalianpai/p/12194593.html