海量檔案同步方案 rsync的多程序實現

2021-10-06 10:24:07 字數 4406 閱讀 2560

客戶端

主要是通過rsync配置好服務端的模式來實現

ssh實現參考

yum install -y rsync

#centos,其餘自行搜尋資料

vim /etc/rsyncd.conf
# minimal configuration file for rsync daemon;;

;;;;

;;;;

;;;;

# see rsync(1) and rsyncd.conf(5) man pages for help;;

;;;;

;;;;

;;;;

# this line is required by the /etc/init.d/rsyncd script;;

;;;;

;;;;

;;;;

# global options

uid = root

gid = root

use chroot

= no

read only = no

write only = no

max connections = 5

pid file

= /var/run/rsyncd.pid

secrets file

= /etc/rsyncd/rsyncd.secrets

motd file

= /etc/rsyncd/rsyncd.motd

# this will give you a separate log file

log file

= /var/log/rsyncd.log

# this will log every file transferred - up to 85,000+ per user, per sync

transfer logging =

yeslog format

= %t %a %m %f %b

syslog facility = local3

timeout

= 300

[sync]

#模組名稱

uid = nginx #使用者組

gid = nginx #使用者

port = 873 #埠

motd file

= /etc/rsyncd/rsyncd.motd

syslog facility = local3

log file

= /var/log/rsyncd.log

path = /path/ #路徑

read only =

false

#是否唯讀

write only =

false

#是否只寫

use chroot

=false

#是否啟用 chroot

auth users

= username #授權使用者,注意修改

secrets file

= /etc/rsyncd/rsyncd.secrets

hosts allow = ***.***.***.*** #允許連線該模組的客戶端,不需要可以刪除這行

list =

true

#是否在模組列表中顯示模組

max connections = 0 #最大併發連線數 0沒有限制

:wq
vi /etc/rsyncd/rsyncd.secrets
新增一行

使用者名稱:密碼
:wq
重啟服務

service

rsync restart

開機自動啟動服務

chkconfig

rsync on

客戶端安裝和服務端一樣的

vi /etc/rsyncd.secrets
把在服務端設定的授權使用者的密碼輸入儲存

如果需要排除目錄或檔案,需要執行這一步,最好設定乙個,防止隱藏檔案傳輸過去

vi /etc/lsyncd.exclude
一行一條

#需同步的路徑

ip='***.***.***.***'

#遠端伺服器ip

port=

'873'

#遠端伺服器rsync埠

user=

'username'

#遠端伺服器rsync使用者名稱

des=

'sync'

#遠端伺服器rsync模組名

opt=

'-rq -p -t -l --password-file=/etc/rsyncd.secrets'

#rsync 選項

exclude=

'--exclude-from=/etc/lsyncd.exclude'

#如果上一步沒有建立, 將單引號裡面的刪除

num=20

depth=

'4 3 2 1'

#歸遞目錄深度

# 從深到淺同步目錄

for l in

$depth;do

todo=

`find -l $dir -maxdepth $l -mindepth $l -type d`

# -l 讀取軟鏈結

# 啟動rsync程序

for i in

$todo;do

now_num=

`ps axw |

grep

rsync

|grep $ip |

grep -v '\-\-server'

|wc -l`

echo

"$::$now_num"

while

[$now_num -ge $num];

doecho

'wait 1s'

sleep 1

now_num=

`ps axw |

grep

rsync

|grep $ip |

grep -v '\-\-server'

|wc -l`

done

/usr/bin/rsync $opt

$exclude

$i/ rsync://$user@

$ip:

$port/$des/$/ &

done

done

# 最後再校驗一遍

while

true;do

sleep 5

now_num=

`ps axw |

grep

rsync

|grep $ip |

grep -v '\-\-server'

|wc -l`

if[$now_num -lt 1 ]

;then

/usr/bin/rsync $opt

$exclude

$dir rsync://$user@

$ip:

$port/$des

break

fidone

#儲存

:wq#執行許可權

chmod +x /root/rsync.sh

#後台執行

nohup /root/rsync.sh &

rsync 檔案同步

昨天上網找乙個同步工具,windows同步到linux,額,ms不少,但是配置實在是麻煩,而且很多按照步驟做下來 都不能使用,估計rp問題 最鬱悶的事莫過如此,經過乙個下午的努力,額,原來真的行的,分享給大家。估計很多人會覺得囉嗦 一.介紹 不想看直接可以跳過 rsync 是乙個遠端資料同步工具,可...

檔案同步rsync

命令格式 rsync option 源路徑 目標路徑 其中 option a 使用archive模式,等於 rlptgod,即保持原有的檔案許可權 z 表示傳輸時壓縮資料 v 顯示到螢幕中 e 使用遠端shell程式 可以使用rsh或ssh delete 精確儲存副本,源主機刪除的檔案,目標主機也會...

同步檔案rsync

linux中實現遠端複製檔案的方式常用scp命令,簡單方便,例如 scp r node1 data data 操作與使用都很簡單,不能實現檔案的排除等高階操作,下面介紹下常用的命令rsync rsync實現檔案同步的方式包括 一 首先介紹使用rsync伺服器的操作步驟 安裝rsync伺服器 yum ...