如何实现CentOS 5.4 rsync+inotify配置触发式实时文件远程同步
如何实现CentOS 5.4 rsync+inotify配置触发式实时文件远程同步
1.安装rsync
yum install rsync -y
2.配置rsync服务
vi /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[test]
path = /data/test
ignore errors
read only = false
list = false
auth users = test
secrets file = /etc/rsyncd.secrets
3.配置rsync认证文件
vi /etc/rsyncd.secrets
test:123456
4.启动rsync服务
service rsyncd start
5.配置rsync客户端
vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[test]
path = /data/test
ignore errors
read only = false
list = false
auth users = test
secrets file = /etc/rsyncd.secrets
6.安装inotify
yum install inotify-tools -y
7.配置实时同步脚本
vi /data/test/rsync.sh
#!/bin/bash
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,create,delete,attrib /data/test | while read date time file
do
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.secrets rsync@192.168.1.100::test /data/test
done
8.配置定时任务
crontab -e
00 00 * * * /bin/sh /data/test/rsync.sh &> /dev/null
9.查看日志
tail -f /var/log/rsyncd.log
相关文章