错误集:rsync+inotify实时同步时rsync: failed to set times on “/.“ (in wwwroot): Operation not permitted (1)

rsync+inotify实时同步时报错

一、报错如下:

[root@slave abc]#touch test.html
[root@slave abc]#rsync: failed to set times on "/." (in wwwroot): Operation not permitted (1)
rsync: chgrp "/.test.html.pkEkSr" (in wwwroot) failed: Operation not permitted (1)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179) [sender=3.1.2]
rsync: failed to set permissions on "/." (in wwwroot): Operation not permitted (1)
rsync: chgrp "/test.html" (in wwwroot) failed: Operation not permitted (1)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1179) [sender=3.1.2]

在这里插入图片描述

二、分析原因:

出现rsync: failed to set times on “xxxx”: Operation not permitted的原因大致是对文件夹(或文件)xxxx没有操作权限。如果执行同步的用户是root,是不会有这样的问题,但是rsync也可以不使用root用户来进行同步,不使用root用户的情况下,即使使用了-o,-g,同步到目的文件夹的文件用户和组都变成了同步使用的用户,但是用-p后文件权限可以保留。当目的文件夹(或文件)xxxx事后做过修改使属主不是rsync使用的用户,即使共享目录的权限是777,也会出现上述错误。
未改动配置文件里的属主和属组前,查看/var/www/html的详细信息,其属主和属组为root
在这里插入图片描述
所以就算给了/var/www/html这个目录777的权限,rsync服务的属主和属组为nobody,slave端共享文件的目录创建文件依然没有写权限,所以报错
在这里插入图片描述
slave上创建文件也会报错
在这里插入图片描述

三、解决方法:

这个问题就是,因为 /etc/rsyncd.conf 文件内,你指定的uid 、 gid 的问题, 这样,你同步文件要写的目录 ,他的属主和属组 都要是/etc/rsync.conf 文件内指定的uid和gid为root。
这样就不会 rsync: failed to set times on…之类的错误了 !
Master(192.168.2.4)

vim /etc/rsyncd.conf

uid = root
gid = root

#修改配置文件后重启服务
kill `cat /var/run/rsyncd.pid`
netstat -natp | grep rsync
rsync --daemon
netstat -natp | grep rsync

在这里插入图片描述

在这里插入图片描述
再次验证

Slave(192.168.2.5)

cd /opt/abc
touch test.html
ls
rm -rf test.html
ls

Master(192.168.2.4)

cd /var/www/html
ls

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_35456705/article/details/114642617
今日推荐