一、rsync环境搭建
1、服务端
(1)、安装rsync
yum install -y rsync
(2)、编辑/etc/rsyncd.conf配置文件
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[data]
path = /data/
ignore errors
read only = false
list = false
hosts allow = 192.168.1.0/24
hosts deny 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
(3)、启动rsync,病修改文件属性
rsync --daemon
netstat -lntp
useradd rsync -s /sbin/nologin
chown -R rsync.rsync /data
echo "rsync_backup:password" > /etc/rsync.password
chmod 600 /etc/rsync.password
2、客户端
(1)、配置密码文件
echo "password" > /etc/rsync.password
(2)、传输文件
rsync -avz /dara [email protected]::data二、inotify实现同步
(1)、安装inotify-tools
wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar xf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure --prefix=/usr/local/inotify
make
make install
或者
yum install -y inotify-tools
(2)、编写脚本实现实时同步
脚本内容:
#!/bin/sh
rsync -az /data/ [email protected]::data --password-file=/etc/rsync.password
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d%m%y %H:%M' --format '%T %w%f' -e create /data|\
while read line
do
rsync -az `echo $line|cut -f3 -d' '` [email protected]::data\
--password-file=/etc/rsync.password
done
(3)、后台运行inotify同步脚本;
sh inotify.sh &