centos6.7rsync端与window2012服务器实时文件同步

windows文件共享我就不截图了,估计大家都会,我就直接在centos6.7上操作了
一、挂载win共享文件夹
mount -t cifs -o username=administrator,password=123.qwe //192.168.1.205/web /web
#如果报错就是没有安装cifs-utils
#yum -y install cifs-utils
df -h
//192.168.1.205/web   60G  8.6G   52G  15% /web
二、安装rsync
yum install rsync xinetd
编辑配置文件,设置开机启动rsync
vi /etc/xinetd.d/rsync
service rsync
{
        disable = no
        flags           = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
}
三、查看系统是否支持inotify并安装
ll /proc/sys/fs/inotify/
-rw-r--r-- 1 root root 0 3月  23 00:47 max_queued_events
-rw-r--r-- 1 root root 0 3月  23 00:47 max_user_instances
-rw-r--r-- 1 root root 0 3月  23 00:47 max_user_watches
tar zxvf inotify-tools-3.13.tar.gz
cd inotify-tools-3.13
./configure --prefix=/usr/local/inotify
make && make install
四、创建脚本,实时触发rsync进行同步

vi rsync.sh
src=/data
target="/web1 /web /web2"
for i in $target;
do
rsync -avH --delete /data/ $i
done
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,delete,create,attrib $src |  while read file
do
for i in $target;
do
rsync -avH --delete /data/ $i
done
done

保存退出啊


五、测试
sh +x rsync.sh
sending incremental file list
./

sent 202 bytes  received 26 bytes  456.00 bytes/sec
total size is 336  speedup is 1.47
sending incremental file list
./
rsync: failed to set times on "/web/.": Permission denied (13)
rsync.sh
1/
10/
2/
3/
4/
5/
6/
7/
8/
9/
lost+found/

sent 614 bytes  received 78 bytes  1384.00 bytes/sec
total size is 336  speedup is 0.49
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
sending incremental file list
./

sent 202 bytes  received 26 bytes  456.00 bytes/sec
total size is 336  speedup is 1.47

查看/web
ll /web
总用量 1
drwxr-xr-x 0 root root   0 3月  22 16:00 1
drwxr-xr-x 0 root root   0 3月  22 16:00 10
drwxr-xr-x 0 root root   0 3月  22 16:00 2
drwxr-xr-x 0 root root   0 3月  22 16:00 3
drwxr-xr-x 0 root root   0 3月  22 16:00 4
drwxr-xr-x 0 root root   0 3月  22 16:00 5
drwxr-xr-x 0 root root   0 3月  22 16:00 6
drwxr-xr-x 0 root root   0 3月  22 16:00 7
drwxr-xr-x 0 root root   0 3月  22 16:00 8
drwxr-xr-x 0 root root   0 3月  22 16:00 9
drwxr-xr-x 0 root root   0 3月  22 14:08 lost+found
-rwxr-xr-x 0 root root 336 3月  22 20:31 rsync.sh

六、添加开机自动挂载

vi /etc/rc.local

mount -t cifs -o username=administrator,password=123.qwe //192.168.1.205/web /web

sh +x /data/rsync.sh >/var/log/rsync.log 2>&1

rsync+inotify实现文件实时同步:

http://www.cnblogs.com/zclzhao/p/4955592.html

原文地址:https://www.cnblogs.com/zclzhao/p/5311696.html