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 &