rsync与inotify实现文件实时同步

rsync

一、 安装rsync

1、安装软件

tar -zxvf rsync-3.2.3.tar.gz
cd rsync-3.2.3
./configure --prefix=/usr/local/rsync
make && make install

2、编写配置文件

vim /etc/rsyncd.conf

motd file = /etc/rsyncd.motd
uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
log format = %t %a %m %f %b
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
timeout = 300


[tongbu]  //名称自定义
path=/home/nt/filesystem
list=yes
comment = this is comment
ignore errors = yes
read only = no
hosts allow = 192.168.1.23
hosts deny = *
auth users backup
secrets file = /etc/rsyncd.secrets

3、编写密码文件

rsyncd.secrets  //此文件权限必须设置:600
vim /etc/rsyncd.secrets
markdeng:123 //用户名密码
赋权
chmod 600 /usr/local/rsync/rsyncd.secrets

4、启动rsyncd

/usr/bin/rsyncd --daemon --config=/etc/rsyncd.conf

5、查看rsyncd进程

   ps aux | grep rsyncd

inotifty

二、 安装inotify

1、 修改系统参数

vim /etc/sysctl.conf

fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576

sysctl –p

2、 安装软件

cd /usr/local
tar zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14/
./configure            //编译
make && make install    //安装

3、 写监控脚本

vim /opt/inotify_rsync.sh

#!/bin/bash
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib /home/nt/filesystem/ | while read file
do
/usr/local/rsync/bin/rsync -vzrtopg --delete --progress /home/nt/filesystem/  backup@192.168.1.23::tongbu --password-file=/etc/rsync.password >  /dev/null 2>&1
echo "${file} was rsynced" >> /var/log/rsync.log 2>&1
done

4、后台启动脚本

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值