前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux下rsync+inotify实时同步

linux下rsync+inotify实时同步

作者头像
dogfei
发布2020-07-31 11:27:06
9930
发布2020-07-31 11:27:06
举报
文章被收录于专栏:devops探索devops探索

系统环境

centos7.4

机器列表

A:172.17.24.139

B:172.17.54.7

C:172.17.24.145

实现目的

要求从A和B两台机器上,将静态文件同步到C机器上。

实现

1、在A、B、C三台机器上分别执行yum -y install rsync xinetd

2、在A、B、C三台机器上分别修改配置文件 /etc/xinetd.d/rsync,没有则创建。

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

# default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no #改为no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } ~ ~

3、修改C机器,配置rsync的配置文件和创建认证密码

vim /etc/rsyncd.conf

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

log file = /var/log/rsyncd.log pidfile = /var/run/rsyncd.pid lock file = /var/run/rsync.lock secrets file = /etc/rsyncd.secrets motd file = /etc/rsyncd.Motd [web] path = /data/web/book_img uid = root gid = root port = 873 use chroot = no read only = no max connections = 200 timeout = 600 hosts allow = A机器 secrets file = /etc/rsyncd.secrets [ad] path = /data/web/ad_img uid = root gid = root port = 873 use chroot = no read only = no max connections = 200 timeout = 600 hosts allow = B地址 secrets file = /etc/rsyncd.secrets [ts] path = /data/web/kf_img uid = root gid = root port = 873 use chroot = no read only = no max connections = 200 timeout = 600 hosts allow = C地址 secrets file = /etc/rsyncd.secrets

vim /etc/rsyncd.secrets

1

xs:123,qwe.

4、重启C的xinetd服务

5、在AB两台机器上安装inotify服务

inotify包

编译安装:./configure --prefix=/usr/local/inotify && make && make install

6、在A、B上编写同步脚本

1 2 3 4 5 6 7 8 9 10

#!/bin/bash SRCDIR=/home/wwwroot/novel3/public/static/book_img #要同步的源路径 USER=xs #同步的用户名 IP=C机器 #同步的目标机器IP,也就是这里的C机器 DESTDIR=book #C机器上的book项,在C机器的rsync配置文件中可看到 /usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move $SRCDIR | while read file do /usr/bin/rsync -rptgoDvLH --port=873 --progress --delete-before $SRCDIR $USER@$IP::$DESTDIR --password-file=/etc/rsyncd.secrets echo " ${file} was rsynced" >> /tmp/rsync.log 2>&1 done

7、测试

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-05-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档