美文网首页
SuSE Linux下 rsync+inotify实现文件自动同

SuSE Linux下 rsync+inotify实现文件自动同

作者: sunland_0416 | 来源:发表于2020-11-13 16:01 被阅读0次

环境:
Suse 11
rsync-3.1.0-12.1.x86_64 (rpm -qa|grep rsync)
inotify-tools-3.13.tar.gz
有两台服务器,165和170,想实现170上增删改目录/home/test/rsync/后会同步到165上

总结:
目标服务器:服务端--165 需要启动rsync服务;写rsync.conf rsync.passwd
源服务器:客户端--170 需要写rsync.conf rsync.passwd;安装inotify-tools,运行inotify脚本

170上rsyncd的配置文件如下:(/home/test/rsync.conf自定义的路径)

uid=root
gid=root
use chroot=no
max connections=10
strict modes=yes
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsync.lock
log file=/home/test/rsyncd.log
[web]
path=/home/test/rsync
comment=web file
ignore errors
read only=no
write only=no
hosts allow=192.168.1.165
host deny =*
list=false
auth users=root
secrets file=/home/test/rsync.passwd

170上rsyncd的密码文件如下:(/home/test/rsync.passwd自定义的路径)

123456

接下来查看170上文件权限ll
确保rsync.passwd跟rsync.conf所有权属于root用户
且密码文件rsync.passwd是600

chmod 600 rsync.passwd

165上rsyncd的配置文件如下:(/home/test/rsync.conf自定义的路径)

uid=root
gid=root
use chroot=no
max connections=10
strict modes=yes
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsync.lock
log file=/home/test/rsyncd.log
[web]
path=/home/test/rsync
comment=web file
ignore errors
read only=no
write only=no
hosts allow=192.168.1.170
host deny =*
list=false
auth users=root
secrets file=/home/test/rsync.passwd

165上rsyncd的密码文件如下:(/home/test/rsync.passwd自定义的路径)

root:123456

同理确保rsync.passwd跟rsync.conf所有权属于root用户且密码文件rsync.passwd是600

接下来,165上启动rsync服务

/usr/bin/rsync --daemon --config=/home/test/rsync.conf

170上测试下

#注意/home/test/rsync/这里一定有/,不然会把170上的/home/test/rsync同步成165上的/home/test/rsync/rsync
rsync -vzrtopg --delete --ignore-errors --password-file=/home/test/rsync.passwd /home/test/rsync/ root@192.168.1.165::web

上面命令会把170上的/home/test/rsync/ 目录文件推到165上同步

接下来请看下一章
SuSE Linux下 rsync+inotify实现文件自动同步(二)

相关文章

网友评论

      本文标题:SuSE Linux下 rsync+inotify实现文件自动同

      本文链接:https://www.haomeiwen.com/subject/syavbktx.html