日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

文件分发系统

發(fā)布時(shí)間:2025/3/17 windows 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 文件分发系统 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文件分發(fā)系統(tǒng)

一個(gè)機(jī)器上的多個(gè)文件要同步到多臺(tái)機(jī)器上,該如何處理?

需求:將192.168.221.10機(jī)器上的/aa/aa.txt、/bb/bb.txt、/cc/cc.txt、/dd/dd.txt同步到192.168.221.20,192.168.221.30這兩臺(tái)機(jī)器上

  • 在192.168.221.10機(jī)器上創(chuàng)建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
  • 實(shí)現(xiàn)文件同步的腳本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 / $user@$host:/ expect { "yes/no" {send "yes\r";exp_continue} "password:" {send "$passwd\r"} } expect eofchmod +x /usr/local/sbin/expect/one-more-rsync.sh
  • 建立一個(gè)同步的文件列表(one-more-rsync.sh中變量file)
vim /tmp/publicfilelist.txt /aa/aa.txt /bb/bb.txt /cc/cc.txt /dd/dd.txt
  • 建立一個(gè)發(fā)送文件目標(biāo)機(jī)器的ip列表
vim /tmp/desip.txt 192.168.221.20 192.168.221.30
  • 寫一個(gè)運(yùn)行的腳本run.sh,調(diào)用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 //注意參數(shù)的順序 done
  • 執(zhí)行run.sh
[root@localhost expect]# bash run.sh spawn rsync -avR --files-from=/tmp/publicfilelist.txt / root@192.168.221.20:/ root@192.168.221.20's password: building file list ... done aa/ aa/aa.txt bb/ bb/bb.txt cc/ cc/cc.txt dd/ dd/dd.txtsent 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 / root@192.168.221.30:/ 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. root@192.168.221.30's password: building file list ... done aa/ aa/aa.txt bb/ bb/bb.txt cc/ cc/cc.txt dd/ dd/dd.txtsent 328 bytes received 100 bytes 285.33 bytes/sec total size is 12 speedup is 0.03

總結(jié):

  • 目標(biāo)機(jī)器的用戶名與密碼都是一樣的(192.168.221.20與192.168.221.30這兩臺(tái)機(jī)器的用戶名與密碼都是一樣的)
  • rsync -R
  • bash腳本中調(diào)用了expect腳本(如 ./one-more-rsync.sh,最好用絕對(duì)路徑,我這兒run.sh與one-more-rsync.sh在同一目錄下)
  • 參數(shù)的對(duì)應(yīng)關(guān)系

轉(zhuǎn)載于:https://blog.51cto.com/13480443/2088161

總結(jié)

以上是生活随笔為你收集整理的文件分发系统的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。