Redis的穿透、击穿、雪崩之间的区
286 2023-04-03 05:19:17
系统:centos 7
inotify-tools版本:3.14(3.22版本测试有问题,所以找的比较旧的一版)
主机IP:
需求:客户端的/home/testpath目录和服务端的/home/testpath同步。客户端目录有变动时,同步复制到服务端
流程逻辑:inotify-tools基于linux的inotify事件,监听文件是否有发生增删改查,如果有,就通过rsync将文件发到另一台服务器。
yum install -y autoconf automake libtool make gcc gcc-c++ make
tar xf inotify-tools-3.14.tar.gzcd inotify-tools-3.14./autogen.sh./configure --prefix=/home/apps/inotify-toolsmakemake install# inotifywait: 仅执行阻塞,等待inotify事件# inotifywatch: 收集关于被监视文件系统的统计数据
yum install -y rsync
uid = rootgid = rootusechroot = nomax connections = 20timeout = 600pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.log[testpath]path = /home/testpathignore errorsread only = falsewriteonly = falselist = falsehosts allow = 192.168.137.8auth users = backusersecrets file = /etc/rsync.pass
backuser:123
123
rsync -a --progress /home/tmp/* backuser@192.168.137.7::testpath --password-file=/etc/rsync.pass
#!/bin/bash# 避免空变量set -u# 待同步目录src=/home/testpath# 监听修改、删除、添加、改属性事件/home/apps/inotify-tools/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -emodify,delete,create,attrib $src | while read filedorsync -zrtopg --progress $src/* backuser@192.168.137.7::testpath --password-file=/etc/rsync.passecho "$(date) rsync event occur" >> /home/scripts/inotify.log 2>&1done
chmod +x inotify.sh./inotify.sh &
-h: 帮助信息-m: 接收到事件时不退出。默认接收到一个事件后即退出-r: 监视一个目录下的所有子目录-q: 安静模式-e: 指定监听的事件-timefmt: 指定时间格式,用于format的%T--format: 指定输出格式%T: 时间格式%f: 发生事件的文件%w: 发生事件的目录%e: 发生的事件
access: 文件读取modify: 文件修改attrib: 文件属性修改,如时间、权限delete: 文件或目录删除create: 文件或目录创建