本文實例講述了CentOS平臺實現搭建rsync遠程同步服務器的方法。分享給大家供大家參考,具體如下:
rsync(remote synchronize)是一個遠程數據同步工具,可通過LAN/WAN快速同步多臺主機間的文件,也可以使用 rsync 同步本地硬盤中的不同目錄。
rsync和scp的區別:
rsync支持增量同步,不管是文件數量的新增還是文件內容的新增,scp不行
注意事項:
1、centos默認已經安裝rsync了,輸入命令rsync查看,如果無法正常工作可參考文章最后的鏈接進行操作
2、rsync只會增量同步,從服務器如果刪除 下次同步還會有,--delete 刪除目標目錄比源目錄多余的文件
3、同步命令可用程序執行、也可定時執行、手動執行
4、修改配置文件后 記得重啟service xinetd restart
5、文件很大可先tar打包壓縮后再傳輸
序號 | IP地址 | 簡稱 |
1 | 192.168.46.32 | A機器 |
2 | 192.168.46.11 | B機器 |
先看下A機器上,logs文件夾下的文件:
[root@h1 logs]# ll
總用量 4
-rw-r--r-- 1 root root 3 8月 30 02:29 a.txt[root@h1 logs]#
然后,我們在B機器上,執行同步命令如下:
[root@h2 logs]# ll
總用量 0
[root@h2 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/receiving incremental file listlogs/logs/a.txtsent 34 bytes received 107 bytes 282.00 bytes/sectotal size is 3 speedup is 0.02[root@h2 logs]# ll
總用量 4
-rw-r--r-- 1 root root 3 8月 30 02:29 a.txt[root@h2 logs]#
然后,我們在A機器上的log文件下,新增一個b.txt,再測試同步命令:
[root@h2 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/receiving incremental file listlogs/logs/b.txtsent 34 bytes received 125 bytes 318.00 bytes/sectotal size is 5 speedup is 0.03[root@h2 logs]#
通過日志,我們發現如果新增一個使用rsync僅僅同步了新增的文件: 現在我們在A服務器上的log文件夾下的a.txt里面新增一行內容,再次執行同步命令:
[root@h2 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/receiving incremental file listlogs/a.txtsent 37 bytes received 128 bytes 330.00 bytes/sectotal size is 9 speedup is 0.05[root@h2 logs]#
我們發現rsync命令也能很好的識別出來 最后我們在來看下,同時改動,A服務器上的a和 b文件,一個新增一行,一個刪除一行,來測下增量:
[root@h2 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/receiving incremental file listlogs/logs/a.txtlogs/b.txtsent 65 bytes received 174 bytes 478.00 bytes/sectotal size is 10 speedup is 0.04[root@h2 logs]#
我們發現rsync也能很好的識別出來。 最后,我們在來看下,如何在B服務器上向A服務器上發送數據,注意,散仙剛在上面的演示,是從B服務器上下載A服務器上的數據,現在我們要演示的是如何在B服務上主動發送數據到A服務器上,原理一樣,都是以增量的方式的操作的,只不過寫IP的方式,變換了一下位置:
新聞熱點
疑難解答