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-utilsdf -h//192.168.1.205/web 60G 8.6G 52G 15% /web二、安装rsyncyum install rsync xinetd编辑配置文件,设置开机启动rsyncvi /etc/xinetd.d/rsyncservice 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_watchestar zxvf inotify-tools-3.13.tar.gzcd inotify-tools-3.13./configure --prefix=/usr/local/inotifymake && make install四、创建脚本,实时触发rsync进行同步
vi rsync.shsrc=/datatarget="/web1 /web /web2"for i in $target;dorsync -avH --delete /data/ $idone/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 filedofor i in $target;dorsync -avH --delete /data/ $idonedone
保存退出啊
五、测试sh +x rsync.sh sending incremental file list./sent 202 bytes received 26 bytes 456.00 bytes/sectotal size is 336 speedup is 1.47sending incremental file list./rsync: failed to set times on "/web/.": Permission denied (13)rsync.sh1/10/2/3/4/5/6/7/8/9/lost+found/sent 614 bytes received 78 bytes 1384.00 bytes/sectotal size is 336 speedup is 0.49rsync 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/sectotal size is 336 speedup is 1.47查看/webll /web总用量 1drwxr-xr-x 0 root root 0 3月 22 16:00 1drwxr-xr-x 0 root root 0 3月 22 16:00 10drwxr-xr-x 0 root root 0 3月 22 16:00 2drwxr-xr-x 0 root root 0 3月 22 16:00 3drwxr-xr-x 0 root root 0 3月 22 16:00 4drwxr-xr-x 0 root root 0 3月 22 16:00 5drwxr-xr-x 0 root root 0 3月 22 16:00 6drwxr-xr-x 0 root root 0 3月 22 16:00 7drwxr-xr-x 0 root root 0 3月 22 16:00 8drwxr-xr-x 0 root root 0 3月 22 16:00 9drwxr-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
