文件分发系统
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文件分发系统相关的知识,希望对你有一定的参考价值。
文件分发系统一个机器上的多个文件要同步到多台机器上,该如何处理?
需求:将192.168.221.10机器上的/aa/aa.txt、/bb/bb.txt、/cc/cc.txt、/dd/dd.txt同步到192.168.221.20,192.168.221.30这两台机器上
- 在192.168.221.10机器上创建aa/aa.txt、/bb/bb.txt、/cc/cc.txt、/dd/dd.txt
mkdir {/aa/,/bb/,/cc/,/dd/}
echo "aa" > /aa/aa.txt;echo "bb" > /bb/bb.txt;echo "cc" > /cc/cc.txt;echo "dd" > /dd/dd.txt
- 实现文件同步的脚本one-more-rsync.sh
vim /usr/local/sbin/expect/one-more-rsync.sh
#!/usr/bin/expect
set passwd "root"
set user "root"
set host [lindex $argv 0]
set file [lindex $argv 1]
spawn rsync -avR --files-from=$file / [email protected]$host:/
expect {
"yes/no" {send "yes\r";exp_continue}
"password:" {send "$passwd\r"}
}
expect eof
chmod +x /usr/local/sbin/expect/one-more-rsync.sh
- 建立一个同步的文件列表(one-more-rsync.sh中变量file)
vim /tmp/publicfilelist.txt
/aa/aa.txt
/bb/bb.txt
/cc/cc.txt
/dd/dd.txt
- 建立一个发送文件目标机器的ip列表
vim /tmp/desip.txt
192.168.221.20
192.168.221.30
- 写一个运行的脚本run.sh,调用one-more-rsync.sh
vim /usr/local/sbin/expect/run.sh
#!/bin/bash
publicfilelist="/tmp/publicfilelist.txt"
for desip in `cat /tmp/desip.txt`; do
./one-more-rsync.sh $desip $publicfilelist //注意参数的顺序
done
- 执行run.sh
[[email protected] expect]# bash run.sh
spawn rsync -avR --files-from=/tmp/publicfilelist.txt / [email protected]:/
[email protected]‘s password:
building file list ... done
aa/
aa/aa.txt
bb/
bb/bb.txt
cc/
cc/cc.txt
dd/
dd/dd.txt
sent 328 bytes received 100 bytes 856.00 bytes/sec
total size is 12 speedup is 0.03
spawn rsync -avR --files-from=/tmp/publicfilelist.txt / [email protected]:/
The authenticity of host ‘192.168.221.30 (192.168.221.30)‘ can‘t be established.
ECDSA key fingerprint is SHA256:UiIDDUfExrEZLxrI8+z6PWjWsNCO2GTDDfTKpEhQaWY.
ECDSA key fingerprint is MD5:4e:79:bd:c6:bb:8d:b7:ee:1a:a4:cb:25:03:22:10:5f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.221.30‘ (ECDSA) to the list of known hosts.
[email protected]‘s password:
building file list ... done
aa/
aa/aa.txt
bb/
bb/bb.txt
cc/
cc/cc.txt
dd/
dd/dd.txt
sent 328 bytes received 100 bytes 285.33 bytes/sec
total size is 12 speedup is 0.03
以上是关于文件分发系统的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode810. 黑板异或游戏/455. 分发饼干/剑指Offer 53 - I. 在排序数组中查找数字 I/53 - II. 0~n-1中缺失的数字/54. 二叉搜索树的第k大节点(代码片段