您好,登錄后才能下訂單哦!
本文實(shí)例講述了CentOS平臺(tái)實(shí)現(xiàn)搭建rsync遠(yuǎn)程同步服務(wù)器的方法。分享給大家供大家參考,具體如下:
rsync(remote synchronize)是一個(gè)遠(yuǎn)程數(shù)據(jù)同步工具,可通過(guò)LAN/WAN快速同步多臺(tái)主機(jī)間的文件,也可以使用 rsync 同步本地硬盤(pán)中的不同目錄。
rsync和scp的區(qū)別:
rsync支持增量同步,不管是文件數(shù)量的新增還是文件內(nèi)容的新增,scp不行
注意事項(xiàng):
1、centos默認(rèn)已經(jīng)安裝rsync了,輸入命令rsync查看,如果無(wú)法正常工作可參考文章最后的鏈接進(jìn)行操作
2、rsync只會(huì)增量同步,從服務(wù)器如果刪除 下次同步還會(huì)有,--delete 刪除目標(biāo)目錄比源目錄多余的文件
3、同步命令可用程序執(zhí)行、也可定時(shí)執(zhí)行、手動(dòng)執(zhí)行
4、修改配置文件后 記得重啟service xinetd restart
5、文件很大可先tar打包壓縮后再傳輸
序號(hào) | IP地址 | 簡(jiǎn)稱(chēng) |
1 | 192.168.46.32 | A機(jī)器 |
2 | 192.168.46.11 | B機(jī)器 |
先看下A機(jī)器上,logs文件夾下的文件:
[root@h2 logs]# ll
總用量 4
-rw-r--r-- 1 root root 3 8月 30 02:29 a.txt [root@h2 logs]#
然后,我們?cè)贐機(jī)器上,執(zhí)行同步命令如下:
[root@h3 logs]# ll
總用量 0
[root@h3 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/ receiving incremental file list logs/ logs/a.txt sent 34 bytes received 107 bytes 282.00 bytes/sec total size is 3 speedup is 0.02 [root@h3 logs]# ll
總用量 4
-rw-r--r-- 1 root root 3 8月 30 02:29 a.txt [root@h3 logs]#
然后,我們?cè)贏機(jī)器上的log文件下,新增一個(gè)b.txt,再測(cè)試同步命令:
[root@h3 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/ receiving incremental file list logs/ logs/b.txt sent 34 bytes received 125 bytes 318.00 bytes/sec total size is 5 speedup is 0.03 [root@h3 logs]#
通過(guò)日志,我們發(fā)現(xiàn)如果新增一個(gè)使用rsync僅僅同步了新增的文件: 現(xiàn)在我們?cè)贏服務(wù)器上的log文件夾下的a.txt里面新增一行內(nèi)容,再次執(zhí)行同步命令:
[root@h3 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/ receiving incremental file list logs/a.txt sent 37 bytes received 128 bytes 330.00 bytes/sec total size is 9 speedup is 0.05 [root@h3 logs]#
我們發(fā)現(xiàn)rsync命令也能很好的識(shí)別出來(lái) 最后我們?cè)趤?lái)看下,同時(shí)改動(dòng),A服務(wù)器上的a和 b文件,一個(gè)新增一行,一個(gè)刪除一行,來(lái)測(cè)下增量:
[root@h3 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/ receiving incremental file list logs/ logs/a.txt logs/b.txt sent 65 bytes received 174 bytes 478.00 bytes/sec total size is 10 speedup is 0.04 [root@h3 logs]#
我們發(fā)現(xiàn)rsync也能很好的識(shí)別出來(lái)。 最后,我們?cè)趤?lái)看下,如何在B服務(wù)器上向A服務(wù)器上發(fā)送數(shù)據(jù),注意,散仙剛在上面的演示,是從B服務(wù)器上下載A服務(wù)器上的數(shù)據(jù),現(xiàn)在我們要演示的是如何在B服務(wù)上主動(dòng)發(fā)送數(shù)據(jù)到A服務(wù)器上,原理一樣,都是以增量的方式的操作的,只不過(guò)寫(xiě)IP的方式,變換了一下位置:
[root@h3 logs]# rsync -av --delete /root/logg/logs/b.txt 192.168.46.32:/root/ sending incremental file list b.txt sent 87 bytes received 37 bytes 248.00 bytes/sec total size is 10 speedup is 0.08 [root@h3 logs]#
參考文章:
https://www.jb51.net/article/138864.htm
https://www.jb51.net/article/138866.htm
希望本文所述對(duì)大家CentOS服務(wù)器配置有所幫助。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。