用rsync實(shí)現(xiàn)windows與linux文件同步的方法
更新時(shí)間:2011年02月21日 20:30:18 作者:
windows做為文件服務(wù)器,使用rsync的windows服務(wù)版本,然后配置好就可以了。需要的朋友可以參考下。
windows做為文件服務(wù)器,使用rsync的windows服務(wù)版本:cwRsyncServer 下載地址:http://rsync.samba.org
安裝過程要設(shè)置用于系統(tǒng)服務(wù)的帳號和密碼,可以默認(rèn)。
注:此帳號用于啟用crsync server服務(wù),需要分配給帳號對要同步文件的相應(yīng)權(quán)限,否則無法操作被同步的文件。
安裝完成后修改配置文件 rsyncd.conf, 配置文件內(nèi)容如下:
port = 52326
use chroot = false
strict modes = false
#hosts allow = * #允許所有的訪問
hosts allow = 192.168.10.2 #指定特定的IP允許訪問
log file = rsyncd.log
lock file = rsyncd.lock
max connections = 10
UID = 0
GID = 0
# Module definitions
# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work
#
[test]
path = /cygdrive/c/work
read only = false
transfer logging = no
[test2]
path = /cygdrive/d/wwwroot/yanghengfei_com
read only = yes
transfer logging = no
auth users = coldstar #同步使用的帳號
secrets file = rsyncd.secrets #密碼文件
注:
rsyncd.secrets配置文件的格式為 用戶名:密碼,如:
coldstar:123456
即添加了一個(gè)用戶 coldstar,密碼為 123456。
Linux服務(wù)器上執(zhí)行同步命令:
rsync -vzrtopg --progress --delete rsync://coldstar@192.168.10.1:52326/test2 /root/test2
然后在password: 提示符下輸入密碼即可。
也可以把密碼寫入配置文件引用,如:
rsync -vzrtopg --progress --delete --password-file=/etc/rsync.pass rsync://coldstar@192.168.10.1:52326/test2 /www/users/yanghengfei_com
將以上命令寫入計(jì)劃任務(wù),每1分鐘執(zhí)行,即可實(shí)現(xiàn)實(shí)時(shí)同步的效果。
注:
上面這個(gè)命令行中-vzrtopg里的v是verbose,z是壓縮,r是recursive,topg都是保持文件原有屬性如屬主、時(shí)間的參數(shù)。-- progress是指顯示出詳細(xì)的進(jìn)度情況,--delete是指如果服務(wù)器端刪除了這一文件,那么客戶端也相應(yīng)把文件刪除,保持真正的一致。
附,rsync使用時(shí)的常見問題:
錯(cuò)誤1: rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(794) [receiver=3.0.2]
解決:很大可能是服務(wù)器端沒有開啟 rsync 服務(wù)。開啟服務(wù)。 或者開啟了防火墻指定的端口無法訪問。
錯(cuò)誤2:@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
解決:服務(wù)器端同步目錄沒有權(quán)限,cwrsync默認(rèn)用戶是Svcwrsync。為同步目錄添加用戶Svcwrsync權(quán)限。
錯(cuò)誤3:@ERROR: failed to open lock file
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
解決:服務(wù)器端配置文件 rsyncd.conf中添加 lock file = rsyncd.lock 即可解決。
錯(cuò)誤4:@ERROR: invalid uid nobody
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.2]
解決:在rsyncd.conf文件中添加下面兩行即可解決問題
UID = 0
GID = 0
錯(cuò)誤5:@ERROR: auth failed on module test2
rsync error: error starting client-server protocol (code 5) at main.c(1296) [receiver=3.0.2]
解決:服務(wù)端沒有指定正確的secrets file,請?jiān)?[test2]配置段添加如下配置行:
auth users = coldstar #同步使用的帳號
secrets file = rsyncd.secrets #密碼文件
錯(cuò)誤6:password file must not be other-accessible
解決:客戶端的pass文件要求權(quán)限為600, chmod 600 /etc/rsync.pass 即可。
安裝過程要設(shè)置用于系統(tǒng)服務(wù)的帳號和密碼,可以默認(rèn)。
注:此帳號用于啟用crsync server服務(wù),需要分配給帳號對要同步文件的相應(yīng)權(quán)限,否則無法操作被同步的文件。
安裝完成后修改配置文件 rsyncd.conf, 配置文件內(nèi)容如下:
復(fù)制代碼 代碼如下:
port = 52326
use chroot = false
strict modes = false
#hosts allow = * #允許所有的訪問
hosts allow = 192.168.10.2 #指定特定的IP允許訪問
log file = rsyncd.log
lock file = rsyncd.lock
max connections = 10
UID = 0
GID = 0
# Module definitions
# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work
#
[test]
path = /cygdrive/c/work
read only = false
transfer logging = no
[test2]
path = /cygdrive/d/wwwroot/yanghengfei_com
read only = yes
transfer logging = no
auth users = coldstar #同步使用的帳號
secrets file = rsyncd.secrets #密碼文件
注:
rsyncd.secrets配置文件的格式為 用戶名:密碼,如:
coldstar:123456
即添加了一個(gè)用戶 coldstar,密碼為 123456。
Linux服務(wù)器上執(zhí)行同步命令:
rsync -vzrtopg --progress --delete rsync://coldstar@192.168.10.1:52326/test2 /root/test2
然后在password: 提示符下輸入密碼即可。
也可以把密碼寫入配置文件引用,如:
rsync -vzrtopg --progress --delete --password-file=/etc/rsync.pass rsync://coldstar@192.168.10.1:52326/test2 /www/users/yanghengfei_com
將以上命令寫入計(jì)劃任務(wù),每1分鐘執(zhí)行,即可實(shí)現(xiàn)實(shí)時(shí)同步的效果。
注:
上面這個(gè)命令行中-vzrtopg里的v是verbose,z是壓縮,r是recursive,topg都是保持文件原有屬性如屬主、時(shí)間的參數(shù)。-- progress是指顯示出詳細(xì)的進(jìn)度情況,--delete是指如果服務(wù)器端刪除了這一文件,那么客戶端也相應(yīng)把文件刪除,保持真正的一致。
附,rsync使用時(shí)的常見問題:
錯(cuò)誤1: rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(794) [receiver=3.0.2]
解決:很大可能是服務(wù)器端沒有開啟 rsync 服務(wù)。開啟服務(wù)。 或者開啟了防火墻指定的端口無法訪問。
錯(cuò)誤2:@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
解決:服務(wù)器端同步目錄沒有權(quán)限,cwrsync默認(rèn)用戶是Svcwrsync。為同步目錄添加用戶Svcwrsync權(quán)限。
錯(cuò)誤3:@ERROR: failed to open lock file
rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
解決:服務(wù)器端配置文件 rsyncd.conf中添加 lock file = rsyncd.lock 即可解決。
錯(cuò)誤4:@ERROR: invalid uid nobody
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.2]
解決:在rsyncd.conf文件中添加下面兩行即可解決問題
UID = 0
GID = 0
錯(cuò)誤5:@ERROR: auth failed on module test2
rsync error: error starting client-server protocol (code 5) at main.c(1296) [receiver=3.0.2]
解決:服務(wù)端沒有指定正確的secrets file,請?jiān)?[test2]配置段添加如下配置行:
auth users = coldstar #同步使用的帳號
secrets file = rsyncd.secrets #密碼文件
錯(cuò)誤6:password file must not be other-accessible
解決:客戶端的pass文件要求權(quán)限為600, chmod 600 /etc/rsync.pass 即可。
相關(guān)文章
DELL R720服務(wù)器安裝Windows Server 2008 R2系統(tǒng)的圖文詳解
這篇文章主要介紹了DELL R720服務(wù)器安裝Windows Server 2008 R2系統(tǒng)的圖文詳解,需要的朋友可以參考下2021-03-03
Memcached緩存系統(tǒng)的介紹、安裝以及應(yīng)用方法詳解
這篇文章主要介紹了Memcached緩存系統(tǒng)的介紹、安裝以及應(yīng)用方法,詳細(xì)分析了Memcached的安裝、啟動,并給出了php與C++使用Memcached的方法,需要的朋友可以參考下2016-05-05
php.ini 啟用disable_functions提高安全
如果想保證服務(wù)器的安全,請將這個(gè)函數(shù)加到disable_functions里或者將安全模式打開吧,在安全模式下dl函數(shù)是無條件禁止的2009-07-07
windows服務(wù)器之win2003,win2008R2,win2012,win2016,win2019系統(tǒng)版本區(qū)別
windows服務(wù)器版有window2003,windows server2008,windows server2012 R2,windows server2016,windows 2019他們有什么不同,如何選擇適合自己的服務(wù)器系統(tǒng),需要的朋友可以參考下2020-02-02
CentOS Rsync服務(wù)端與Windows cwRsync客戶端實(shí)現(xiàn)數(shù)據(jù)同步配置方法
這篇文章主要介紹了CentOS Rsync服務(wù)端與Windows cwRsync客戶端實(shí)現(xiàn)數(shù)據(jù)同步配置方法,需要的朋友可以參考下2015-07-07
Tomcat 啟動錯(cuò)誤(8080端口被占用)處理方法
8080端口被占用的解決方法,其實(shí)這個(gè)方法,可以用于其它一些端口被占用的問題。2009-07-07
Centos服務(wù)器部署前后端項(xiàng)目的實(shí)戰(zhàn)教程
這篇文章主要介紹了Centos服務(wù)器部署前后端項(xiàng)目的實(shí)戰(zhàn)教程,本文通過實(shí)例圖文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2024-02-02

