linux目录实时同步,linux实时同步服务

原理部署好rsync守护进程服务,实现数据传输备份

部署好inotify服务,实现目录中数据的增量监控

将rsync服务和inotify服务建立联系,实现实时同步

实时同步服务部署部署rsync守护进程服务端部署

客户端部署部署inotify监控服务1、安装软件 yum install -y inotify-tools

2、查看服务中的文件 rpm -ql inotify-tools

3、熟悉命令

/usr/bin/inotifywait ----监控数据变化

/usr/bin/inotifywatch ----统计监控信息

命令结构: inotifywait 【参数】 监控的目录

参数:-m|--monitor ---实时监控目录数据变化

-r|--recursive ---递归监控

-q|--quiet --尽量减少信息输出

--format 指定输出的格式

--timefmt ---指定输出时间的格式

-e|--event --指定监控的事件信息

创建文件监控信息

1、CREATE ---文件被创建

2、OPEN -----打开创建的文件

3、ATTRIB ----修改文件的属性

4、CLOSE_WRITE,CLOSE ----保存关闭一个文件

PS:监控的事件:create、delete、move_to移入、close_write修改inotify参数事件表格说明事件名称事件说明accessfile or directory contents were read

modifyfile or directory contents were written

attribfile or directory attributes changed

close_writefile or directory closed,after being opened in writeable mode

close_nowritefile or directory closed,after being opened in read-only mode

closefiel or directory closed,regardless of read/write mode

openfile or directory opened

moved_tofile or directory moved to watched directory

moved_fromfile or directory moved from watched directory

movedfile or directory moved to or form watched directory

createfile or directory created within watched directory

deletefile or directory deleted within watched directory

delete_selffile or directory was deleted

unmountfile system containing file or directory unmounted部署inotify监控服务案例1、inotifywait -m /data -e CREATE #只监控create事件

2、inotifywait -mr /data -e CREATE #递归监控create事件

3、inotifywait -mrq /data -e CREATE #递归监控create事件,不提示无用的信息

4、inotifywait -mrq --timefmt "%F" --format "%T %w %f" /data -e CREATE #递归监控create事件+不提示无用的信息+事件格式

5、inotifywait -mrq --timefmt "%F" --format "%T %w %f 事件信息:%e" /data -e CREATE #递归监控create事件+不提示无用的信息+事件格式+事件说明企业应用1、防止系统重要的文件被破坏,进行实时监控目录 /etc passwd /var/spool/cron/root部署sersync同步服务1、安装sersync软件,不在yum仓库,http://github.com/wsgzao/sersync下载好之后上传 rz -y 要上传的文件 PS:保存在一个专门放置软件包的目录

2、解压,将解压的数据包进行保存 unzip zip包 tree 解压的文件

mv 解压的文件 /usr/local

3、编写配置文件 vim confxml.xml

4、启动sersync服务,PS:此处不能使用systemctl启动,因为不是利用yum安装的

sersync -dro /usr/local/sersync/conf/confxml.xml #启动服务

killall 服务名 #停止服务 需要安装使用

/etc/rc.local

export PATH="$PATH:/usr/local/sersync/bin" #升级为全局变量

sersync -h #帮助文档查看

参数说明:

-d:启动守护进程模式

-r:在监控前,将监控目录与远程主机用rsync命令推送一遍 目的:①保证备份服务器与远程服务器数据一致②同步测试

-o:指定配置文件,默认使用confxml.xml,可以加载多个配置文件

bVcIlyb异常总结总结

305

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值