手机版
你好,游客 登录 注册
背景:
阅读新闻

rsync+inotify-tools+ssh实现触发式远程实时同步

[日期:2012-06-03] 来源:Linux社区  作者:navyaijm [字体:大 中 小]

一、环境:

外网IP:114.112.36.69

内网IP:10.20.220.247

外网目录:/data/apps/ksoftmgr/ksafe/client/update

内网目录:/data/appsdata/softmgr-v3/static-file/update

二、项目需求:

外网需要同步内网的数据,从114.112.36.69拉10.20.220.247肯定是实现不了,www.linuxidc.com只能把内网的数据推到外网服务器了,

三、实现步骤:

1.安装需要的软件

114.112.36.69上:

 [root@localhost ~]# yum install rsync -y

 

10.20.220.247上:

 

 [root@localhost ~]# yum install rsync inotify-tools -y

2.新建用来同步的数据的用户(两台机器上做同样的操作)

 [root@localhost ~]# useradd wcm

 [root@localhost ~]# passwd wcm

3.配置ssh无密钥登录

 在10.20.220.247上:

 [root@localhost ~]# su - wcm
 [wcm@localhost ~]$ ssh-keygen -t dsa (一路回车)

 [wcm@localhost ~]$ cd .ssh/
 [wcm@localhost .ssh]$ ssh-copy-id -i id_dsa.pub 114.112.36.69

4.撰写脚本

 [root@localhost ~]# cat /etc/init.d/inotify_rsync1.sh
 #!/bin/sh
 SRC=/data/appsdata/softmgr-v3/static-file/update
 DST=wcm@114.112.36.69:/data/apps/ksoftmgr/ksafe/client
 /usr/bin/inotifywait -mrq -e modify,delete,create,attrib ${SRC} | while read D E F
 do
 /usr/bin/rsync -ahqzt --delete $SRC $DST
 done

 

5.执行脚本

 [root@localhost ~]# /etc/init.d/inotify_rsync.sh &

6.加入开机启动

 [root@localhost ~]# echo "/etc/init.d/inotify_rsync.sh &"  >> /etc/rc.local 

7.测试

 在10.20.220.247的upte目录下写文件,看114.112.36.69对应的目录下是否会也生成。

linux
相关资讯       rsync 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款