Rsync+inotify实现数据实时同步

本文介绍了一种利用inotify-tools监控文件变化并结合rsync进行远程同步的方法。通过编写bash脚本实现自动化文件同步,适用于网站图片等目录的实时更新场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 下载软件
    wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

2.验证Rsync
rsync -avz -e ssh /home/wwwroot/default/images/ root@140.143.*.*:/home/wwwroot/default/images/

3安装软件
tar zxvf inotify-tools-3.14.tar.gz
./configure --prefix=/usr/local/share/inotify-tool
make && make install
echo $?

4.命令简介
Rsync+inotify实现数据实时同步

5.同步脚本
#!/bin/bash
host=140.143.128.231
src=/home/wwwroot/default/images/
/usr/local/inotify/bin/inotifywait -mrq --format '%w%f' -e create,delete,close_write $src \
| while read file
do
/usr/bin/rsync -az "$file" --delete -e ssh /home/wwwroot/default/images/ root@$host:$src
done

6执行脚本
sh +x inotify.sh &

  1. 缺点
    10-100k 并发200-300 极限

转载于:https://blog.51cto.com/benchmarking/2112126

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值