Parallel Rsync for multi hosts


Như bài viết trước đã đề cập, PSSH Tools cung cấp cho bạn nhiều công cụ như pssh, pscp…ngoài ra prsync cũng là 1 công cụ khá hữu ích cho việc rsync cùng lúc với nhiều hosts.
Xem thêm rsync
Bạn có file txt lưu lại các host như sau:

vi hosts.txt
192.168.6.128
192.168.6.129
Bạn muốn rsync thư mục có tên là Empty lên 2 server trên, cách thông thường thực hiện như sau:
[email protected]:~$ while read ip;do rsync -av Empty root@$ip:/root/Empty ;done < hosts.txt
sending incremental file list
Empty/
sent 72 bytes  received 19 bytes  60.67 bytes/sec
total size is 0  speedup is 0.00
sending incremental file list
Empty/
sent 72 bytes  received 19 bytes  60.67 bytes/sec

total size is 0  speedup is 0.00

//comment: Thay vì bạn dùng vòng lặp để thực hiện n lệnh rsync với n host khác nhau thì bạn có thể dùng parallel rsync để thực hiện rsync với n luồng dành cho n host, với việc thực hiện với 1 số lượng lớn hosts thì prsync đem lại hiệu qủa tối đa về tốc độ cũng như hiệu suất.??
[email protected]:~$ prsync -av -h hosts.txt -l root server_infos /root/server_infos

[1] 21:20:37 [SUCCESS] 192.168.6.128

[2] 21:20:37 [SUCCESS] 192.168.6.129

Kết quả thu được sẽ giúp bạn xác nhận là việc rsync đã thành công.
Phụ lục: Trước khi thực hiện rsync thì bạn phải cài đặt rsync trên toàn bộ hosts của bạn. Cài đặt bằng pssh như sau:

[email protected]:~$ pssh -i -H “192.168.6.128 192.168.6.129” -l root “yum install -y rsync”
[1] 21:20:16 [SUCCESS] 192.168.6.129
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirror-fpt-telecom.fpt.net
 * extras: mirror.pregi.net
 * updates: ossm.utm.my
Resolving Dependencies
–> Running transaction check
—> Package rsync.x86_64 0:3.0.6-12.el6 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package         Arch             Version                  Repository      Size
================================================================================
Installing:
 rsync           x86_64           3.0.6-12.el6             base           335 k
Transaction Summary
================================================================================
Install       1 Package(s)
[2] 21:20:20 [SUCCESS] 192.168.6.128
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.digipower.vn
 * extras: virror.hanoilug.org
 * updates: mirrors.vonline.vn
Resolving Dependencies
–> Running transaction check
—> Package rsync.x86_64 0:3.0.6-12.el6 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package         Arch             Version                  Repository      Size
================================================================================
Installing:
 rsync           x86_64           3.0.6-12.el6             base           335 k
Transaction Summary
================================================================================
Install       1 Package(s)

Leave a Reply

Your email address will not be published. Required fields are marked *