加入收藏 | 设为首页 | 会员中心 | 我要投稿 温州站长网 (https://www.0577zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Linux文件分发脚本 只要一条命令将你的文件分发到各个服务器上

发布时间:2021-12-02 02:21:11 所属栏目:Linux 来源:互联网
导读:在运维或在日常工作生活中,我们经常会把一个文件拷贝到其它服务器上,或同时分发到多个服务器上,甚至要求目标机将文件放在相同的路径下,方便程序进一步调用。 Linux文件分发脚本,只需一条命令将你的文件分发到各个服务器上 遇到这种问题,我们通常的做
在运维或在日常工作生活中,我们经常会把一个文件拷贝到其它服务器上,或同时分发到多个服务器上,甚至要求目标机将文件放在相同的路径下,方便程序进一步调用。
 
Linux文件分发脚本,只需一条命令将你的文件分发到各个服务器上
遇到这种问题,我们通常的做法是使用scp或rsync命令把文件拷贝一个一个地拷贝到多台服务器上,这样做费事费力;大神的做法是使用ansible的playbook一下把事情干完,前提是你得会ansible;快捷的做法就是使用今天的脚本了。
 
效果演示
目前拥有4台机器,分别为client、node1、node2和node3,client与其它3台机器能够建立ssh链接。在client的/root/test目录下有a.txt和b.txt两个文件。
 
Linux文件分发脚本,只需一条命令将你的文件分发到各个服务器上
[root@client test]# ls /root/test/
a.txt  b.txt
[root@client test]#  
我把文件分发到node1、node2和node3的/root/test下,执行以下命令:
 
# 在/root/test目录下执行, xrsync是我的脚本
[root@client test]# xrsync a.txt b.txt  
执行分发过程:
 
[root@client test]# xrsync a.txt b.txt  
============ node1 ============
sending incremental file list
a.txt
 
sent 93 bytes  received 35 bytes  256.00 bytes/sec
total size is 2  speedup is 0.02
sending incremental file list
b.txt
 
sent 93 bytes  received 35 bytes  85.33 bytes/sec
total size is 2  speedup is 0.02
============ node2 ============
sending incremental file list
a.txt
 
sent 93 bytes  received 35 bytes  256.00 bytes/sec
total size is 2  speedup is 0.02
sending incremental file list
b.txt
 
sent 93 bytes  received 35 bytes  256.00 bytes/sec
total size is 2  speedup is 0.02
============ node3 ============
sending incremental file list
a.txt
 
sent 93 bytes  received 35 bytes  85.33 bytes/sec
total size is 2  speedup is 0.02
sending incremental file list
b.txt
 
sent 93 bytes  received 35 bytes  256.00 bytes/sec
total size is 2  spee 

(编辑:温州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读