1、scp(secure copy)安全拷贝

定义

scp可以实现服务器与服务器之间的数据拷贝。(from server1 to server2)

基本语法
scp   -r      $pdir/$fname          $user@$host:$pdir/$fname
命令   递归     要拷贝的文件路径/名称     目的地用户@主机:目的地路径/名称
实操

在 bigdata801,将文件从 bigdata801 堆到 bigdata802

[root@bigdata801 module]# scp -r hadoop-3.3.1/ bigdata802:/opt/module/

在 bigdata803,将文件从 bigdata801 拉到 bigdata803

[root@bigdata803 module]# scp -r bigdata801:/opt/module/hadoop-3.3.1 bigdata803:/opt/module/hadoop-3.3.1

在 bigdata802,将文件从 bigdata801 拷到 bigdata804

[root@bigdata802 module]# scp -r bigdata801:/opt/module/hadoop-3.3.1 bigdata804:/opt/module/hadoop-3.3.1

2、rsync远程同步工具

定义

rsync主要用于备份和镜像。具有速度快、避免复制相同内容和支持符号链接的优点。

rsync和scp区别

用rsync做文件的复制要比scp的速度快,rsync只对差异文件做更新。scp是把所有文件都复制过去。

基本语法
rsync    -av       $pdir/$fname            $user@$host:$pdir/$fname
命令   选项参数      要拷贝的文件路径/名称       目的地用户@主机:目的地路径/名称
选项 功能
-a 归档拷贝
-v 显示复制过程
实操

bigdata801 中的 hadoop 安装目录下,存在 wcinput wcoutput 两个文件夹,而 bigdata802 中没有

[root@bigdata801 hadoop-3.3.1]# pwd
/opt/module/hadoop-3.3.1
[root@bigdata801 hadoop-3.3.1]# ll
总用量 88
drwxr-xr-x 2 1000 1000   203 6月  15 13:52 bin
drwxr-xr-x 3 1000 1000    20 6月  15 13:15 etc
drwxr-xr-x 2 1000 1000   106 6月  15 13:52 include
drwxr-xr-x 3 1000 1000    20 6月  15 13:52 lib
drwxr-xr-x 4 1000 1000   288 6月  15 13:52 libexec
-rw-rw-r-- 1 1000 1000 23450 6月  15 13:02 LICENSE-binary
drwxr-xr-x 2 1000 1000  4096 6月  15 13:52 licenses-binary
-rw-rw-r-- 1 1000 1000 15217 6月  15 13:02 LICENSE.txt
-rw-rw-r-- 1 1000 1000 29473 6月  15 13:02 NOTICE-binary
-rw-rw-r-- 1 1000 1000  1541 5月  22 00:11 NOTICE.txt
-rw-rw-r-- 1 1000 1000   175 5月  22 00:11 README.txt
drwxr-xr-x 3 1000 1000  4096 6月  15 13:15 sbin
drwxr-xr-x 4 1000 1000    31 6月  15 14:18 share
drwxr-xr-x 2 root root    22 8月  22 18:00 wcinput
drwxr-xr-x 2 root root    88 8月  22 18:43 wcoutput
[root@bigdata801 hadoop-3.3.1]#
[root@bigdata802 hadoop-3.3.1]# pwd
/opt/module/hadoop-3.3.1
[root@bigdata802 hadoop-3.3.1]# ll
总用量 88
drwxr-xr-x. 2 root root   203 8月  22 19:23 bin
drwxr-xr-x. 3 root root    20 8月  22 19:23 etc
drwxr-xr-x. 2 root root   106 8月  22 19:23 include
drwxr-xr-x. 3 root root    20 8月  22 19:23 lib
drwxr-xr-x. 4 root root   288 8月  22 19:23 libexec
-rw-r--r--. 1 root root 23450 8月  22 19:23 LICENSE-binary
drwxr-xr-x. 2 root root  4096 8月  22 19:21 licenses-binary
-rw-r--r--. 1 root root 15217 8月  22 19:23 LICENSE.txt
-rw-r--r--. 1 root root 29473 8月  22 19:23 NOTICE-binary
-rw-r--r--. 1 root root  1541 8月  22 19:23 NOTICE.txt
-rw-r--r--. 1 root root   175 8月  22 19:23 README.txt
drwxr-xr-x. 3 root root  4096 8月  22 19:23 sbin
drwxr-xr-x. 4 root root    31 8月  22 19:23 share
[root@bigdata802 hadoop-3.3.1]#

在 bigdata801 上执行如下命令

[root@bigdata801 hadoop-3.3.1]# yum install -y rsync
[root@bigdata801 hadoop-3.3.1]# rsync -av /opt/module/hadoop-3.3.1/ bigdata802:/opt/module/hadoop-3.3.1/

3、xsync集群分发脚本

需求

循环复制文件到所有节点的相同目录下

需求分析

(a)rsync命令原始拷贝:

[root@bigdata801 hadoop-3.3.1]# rsync -av /opt/module/hadoop-3.3.1/ bigdata802:/opt/module/hadoop-3.3.1/

(b)期望脚本:

xsync 要同步的文件名称

(c)期望脚本在任何路径都能使用(脚本放在声明了全局环境变量的路径)

[root@bigdata801 ~]# echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/module/jdk1.8.0_181/bin:/opt/module/hadoop-3.3.1/bin:/opt/module/hadoop-3.3.1/sbin:/root/bin
脚本实现

(a)在/root/bin目录下创建xsync文件

[root@bigdata801 ~]# cd /root/[root@bigdata801 ~]# mkdir bin[root@bigdata801 ~]# cd bin/[root@bigdata801 bin]# vim xsync

在该文件中编写如下代码

#!/bin/bash#1. 判断参数个数if [ $# -lt 1 ]then    echo Not Enough Arguement!    exit;fi#2. 遍历集群所有机器for host in bigdata801 bigdata802 bigdata803 bigdata804do    echo ====================  $host  ====================    #3. 遍历所有目录,挨个发送    for file in $@    do        #4. 判断文件是否存在        if [ -e $file ]            then                #5. 获取父目录                pdir=$(cd -P $(dirname $file); pwd)                #6. 获取当前文件的名称                fname=$(basename $file)                ssh $host "mkdir -p $pdir"                rsync -av $pdir/$fname $host:$pdir            else                echo $file does not exists!        fi    donedone
修改脚本 xsync 具有执行权限
[root@bigdata801 bin]# chmod 777 xsync [root@bigdata801 bin]# ll总用量 4-rwxrwxrwx 1 root root 753 8月  22 20:45 xsync
测试脚本

将刚创建的 bin 分发到其他机器

[root@bigdata801 ~]# xsync bin/

执行过程如下

[root@bigdata801 ~]# xsync bin/==================== bigdata801 ====================sending incremental file listsent 75 bytes  received 17 bytes  184.00 bytes/sectotal size is 753  speedup is 8.18==================== bigdata802 ====================sending incremental file listbin/bin/xsyncsent 878 bytes  received 39 bytes  611.33 bytes/sectotal size is 753  speedup is 0.82==================== bigdata803 ====================sending incremental file listbin/bin/xsyncsent 878 bytes  received 39 bytes  1,834.00 bytes/sectotal size is 753  speedup is 0.82==================== bigdata804 ====================sending incremental file listbin/bin/xsyncsent 878 bytes  received 39 bytes  611.33 bytes/sectotal size is 753  speedup is 0.82[root@bigdata801 ~]#

在 bigdata802上查看文件是否分发成功

[root@bigdata802 hadoop-3.3.1]# cd /root/[root@bigdata802 ~]# ll总用量 4-rw-------. 1 root root 1460 2月  28 19:08 anaconda-ks.cfgdrwxr-xr-x. 2 root root   19 8月  22 20:47 bin[root@bigdata802 ~]#
分发环境变量
[root@bigdata801 ~]# xsync /etc/proprofile    profile.d/ protocols  [root@bigdata801 ~]# xsync /etc/profile==================== bigdata801 ====================sending incremental file listsent 46 bytes  received 12 bytes  116.00 bytes/sectotal size is 2,318  speedup is 39.97==================== bigdata802 ====================sending incremental file listprofilesent 323 bytes  received 59 bytes  764.00 bytes/sectotal size is 2,318  speedup is 6.07==================== bigdata803 ====================sending incremental file listprofilesent 323 bytes  received 59 bytes  764.00 bytes/sectotal size is 2,318  speedup is 6.07==================== bigdata804 ====================sending incremental file listprofilesent 323 bytes  received 59 bytes  764.00 bytes/sectotal size is 2,318  speedup is 6.07[root@bigdata801 ~]#

scp、rsync与集群分发相关推荐

  1. 集群分发脚本xsync

    1. scp(secure copy)安全拷贝 (1)scp定义: scp可以实现服务器与服务器之间的数据拷贝.(from server1 to server2) (2)基本语法 scp -r $pd ...

  2. Hadoop 中xsync集群分发脚本

    1.配置免密登录 2.rsync 远程同步工具 rsync主要用于备份和镜像,具有速度快.避免复制相同内容和支持符号链接的优点,rsync只对差异文件做更新.但是scp是将所有内容都发送过去. 使用方 ...

  3. jenkins~集群分发功能的具体实现

    前一讲主要说了jenkins分发的好处<jenkins~集群分发功能和职责处理>,它可以让具体的节点干自己具体的事,比如windows环境下的节点,它只负责编译,发布windows的生态环 ...

  4. jenkins~集群分发功能和职责处理

    jenkins的多节点集群 在进行自动化部署时,你可以按着它们的项目类型去进行分别部署,这样即可以达到负载均衡,又可以达到一种职责的明确,比如像java的项目你可以使用linux服务来进行部署(拉代码 ...

  5. xsync集群分发脚本

    在/usr/local目录下创建bin目录,并在bin目录下xsync创建文件,文件内容如下: [root@hadoop01 ~]# mkdir bin [root@hadoop01 ~]# cd b ...

  6. KubeVela v1.3 多集群初体验,轻松管理应用分发和差异化配置

    简介:KubeVela v1.3 在之前的多集群功能上进行了迭代,本文将为你揭示,如何使用 KubeVela 进行多集群应用的部署与管理,实现以上的业务需求. 作者:段威(段少) 在当今的多集群业务场 ...

  7. 华为云 和 阿里云 跨服务器搭建Hadoop集群

    目录 华为云 和 阿里云 跨服务器搭建Hadoop集群 说明 期间遇到的问题 CentOS6 7 8更换阿里yum源 修改服务器名称 安装JDK 安装Hadoop 编写集群分发脚本 xsync scp ...

  8. Hadoop |集群的搭建

    Hadoop组成 HDFS(Hadoop Distributed File System)架构概述 NameNode目录--主刀医生(nn):  DataNode(dn)数据: Secondary N ...

  9. 第二节HDFS完全分布式集群搭建与配置及常见问题总结

    提示:此文章内容超级全面和详细 文章目录 前言 一.HDFS完全分布式集群是什么? 二.HDFS完全分布式集群搭建与配置 1.HDFS完全分布式集群搭建库 2.HDFS完全分布式集群搭建配置 HDFS ...

最新文章

  1. 参加Java培训需要注意哪些
  2. oracle解析xml字符串命名空间,XML命名空间
  3. pip安装报错处理+PyPi源切换教程
  4. 2018福大软工实践第八次作业
  5. C#基础 数据类型 类型转换
  6. linux下ftp服务站点,Linux下vsftp服务建立多站点的方法
  7. 管理信息系统案例分析_万华集团 IT 规划案例分析
  8. Python爬虫项目:爬虫爬取正则分析糗百数据
  9. 土方测量-挖方填方量的计算思路
  10. SVG,收藏夹图标以及我们可以用它们做的所有有趣的事情
  11. 陆小曼给徐志摩的挽联
  12. 什么是 “好的“ 逻辑清楚
  13. iOS——调用高德地图SDK
  14. 分支语句和循环语句[一]【详解】
  15. 密度聚类:OPTICS算法详解
  16. 用Assimp模型加载库加载一个Crytek的游戏孤岛危机(Crysis)中的原版纳米装(Nanosuit)
  17. linux骚操作之第八话硬盘分区及挂载
  18. Java算法大全_java贪心算法几个经典例子
  19. 华为设置计算机,华为无线路由器
  20. Flutter自定义控件之饼状图、大转盘

热门文章

  1. 2021年中国电影行业发展现状分析,未来全面均衡发展的前路任重道远「图」
  2. polyrate使用方法_如何装作很懂半导体晶圆制造?
  3. 23、24考研党必备的网站推荐
  4. 新手奶爸,分享一款记录儿童身高体重的APP,并分析其中所用到的技术。
  5. 0.1+0.2等于多少 详解
  6. 自己动手画CPU《计算机组织与结构实验》之计算机数据表示 第1关:汉字国标码转区位码实验 超详细教学
  7. chrome浏览器network报错:ERR_CERT_AUTHORITY_INVALID
  8. 数据仓库框架流程图整理
  9. 广域通信网 - HDLC 高级数据链路控制协议
  10. 保存计算过程的计算器Java实现