部署 rsync + inotify 实现实时同步

一、配置inotify内核参数

vim /etc/sysctl.conf

fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576
#使其生效
sysctl -p
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576

二、安装inotify

vim /etc/sysctl.conf
[root@serverC ~]# tar xf inotify-tools-3.14.tar.gz
[root@serverC ~]# cd inotify-tools-3.14
[root@serverC inotify-tools-3.14]# ./configure && make && make install

三、将指定目录加入到监控中

inotifywait -mrq -e modify,create,move,delete,attrib /data
----------------------------
#参数解释
-m:表示持续监控
-r:表示递归整个目录
-q:简化输出信息
-e:指定要监控的时间
modify:对文件内容修改
create:创建类操作
move:移动类操作
delete:删除类操作
attrib:对文件权限的修改

四、修改rsync,使其对操作目录进行读写

vim /etc/rsyncd.conf

uid = nobody
gid = nobody
use chroot = yes
address = 192.168.200.113
port = 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.200.0/24


[ftp]
        path = /data
        read only = no
	dont compress = *.gz *.bz2 *.zip
	auth users = backuper
	secrets file = /etc/rsyncd_user.db
----------------------------------------------
#使nobody用户具有对目录的读写权限
chown nobody:nobody /data
#重启服务 ,已经写好服务启动脚本
/etc/init.d/rsyncd restart

  • 测试是否能够上传
rsync -avzH --delete /etc/resolv.conf backuper@192.168.200.113::ftp
Password:
sending incremental file list
resolv.conf
rsync: chgrp "/.resolv.conf.2QyMvE" (in ftp) failed: Operation not permitted (1)

sent 146 bytes  received 120 bytes  17.16 bytes/sec
total size is 57  speedup is 0.21
rsync error: some files/attrs were not transferred (see previous errors)(code 23) at main.c(1178) [sender=3.1.2]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值