星外飞客

windows做为文件服务器,使用rsync的windows服务版本:cwRsyncServer 下载地址:http://rsync.samba.org

 

安装过程要设置用于系统服务的帐号和密码,可以默认。

注:此帐号用于启用crsync server服务,需要分配给帐号对要同步文件的相应权限,否则无法操作被同步的文件。

 

安装完成后修改配置文件 rsyncd.conf, 配置文件内容如下:

 

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

 

即添加了一个用户 coldstar,密码为 123456。

 

 

 

Linux服务器上执行同步命令:

 

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

 

将以上命令写入计划任务,每1分钟执行,即可实现实时同步的效果。

 

注:

上面这个命令行中-vzrtopg里的v是verbose,z是压缩,r是recursive,topg都是保持文件原有属性如属主、时间的参数。– progress是指显示出详细的进度情况,–delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。

 

附,rsync使用时的常见问题:

 

错误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]

解决:很大可能是服务器端没有开启 rsync 服务。开启服务。 或者开启了防火墙指定的端口无法访问。

 

错误2:@ERROR: chdir failed 

rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]

解决:服务器端同步目录没有权限,cwrsync默认用户是Svcwrsync。为同步目录添加用户Svcwrsync权限。 

 

错误3:@ERROR: failed to open lock file 

rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]

解决:服务器端配置文件 rsyncd.conf中添加 lock file = rsyncd.lock 即可解决。

 

错误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

 

错误5:@ERROR: auth failed on module test2

rsync error: error starting client-server protocol (code 5) at main.c(1296) [receiver=3.0.2]

解决:服务端没有指定正确的secrets file,请在 [test2]配置段添加如下配置行:

auth users = coldstar  #同步使用的帐号

secrets file = rsyncd.secrets   #密码文件

 

错误6:password file must not be other-accessible

解决:客户端的pass文件要求权限为600, chmod 600 /etc/rsync.pass 即可。

版权所有,转载请注明出处。
转载自 <a href="http://www.yanghengfei.com/archives/451/" title="用rsync 实现windows与linux文件同步" rel="bookmark">用rsync 实现windows与linux文件同步 | 星外飞客 </a>

我简单说几句

随机推荐

最新评论

无觅相关文章插件,快速提升流量