博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Rsync+Inotify
阅读量:6857 次
发布时间:2019-06-26

本文共 1508 字,大约阅读时间需要 5 分钟。

源主机: 192.168.1.111

目的主机: 192.168.1.28(rsync服务端)
实时监控源主机的某个目录,有更新则立即同步到目标主机

1.在目的主机192.168.1.28安装配置Rsync服务端

yum install rsync -y

创建配置文件 /etc/rsyncd.conf

log file = /var/log/rsyncd.log
pidfile = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
uid = root
gid = root
port=873
use chroot = no
read only = no
list = no
max connections = 200
timeout = 600
secrets file = /etc/rsync.pass

[yunwei]

path = /data/www/
comment = yunwei
auth users = rsync_user
hosts allow = 192.168.1.111

服务端的密码文件保存 用户名:密码

客户端的密码文件只需要保存密码

启动rsync服务

rsync --config=/etc/rsyncd.conf --daemon

2.在源主机192.168.1.111上安装inotify和rsync客户端

下载地址
yum install make  gcc gcc-c++ 
cd /usr/local/src
tar zxvf inotify-tools-3.14.tar.gz 
cd inotify-tools-3.14
./configure --prefix=/usr/local/inotify 
make 
make install 

yum install rsync -y

配置密码文件

同步脚本如下,后台运行

#!/bin/bash
src=/data/website/iworker2/
dst=yunwei
excludedir=/data/scripts/exclude.list
rsyncuser=rsync_user
rsyncpass=/etc/rsync.pass
dstIP='192.168.1.28'

for ip in $dstIP

do
rsync -avP --port=873 --delete --exclude-from=$excludedir $src
$rsyncuser@$ip::$dst --password-file=$rsyncpass
done

inotifywait -mrq --timefmt '%d/%m/%y/%H:%M' --format '%T %w %f' -e

modify,delete,create,attrib /data/website/iworker2|while read file
do
for ip in $dstIP
do
rsync -avP --port=873 --delete --exclude-from=$excludedir $src
$rsyncuser@$ip::$dst --password-file=$rsyncpass
done
done

excludedir=/usr/local/inotify/exclude.list 不需要同步的文件,目录,如果有多个,每一行写一个目录,使用相对于同步模块的路径

转载于:https://blog.51cto.com/13666027/2090238

你可能感兴趣的文章
Servlet
查看>>
关于mysql数据库备份的一些选项和参数
查看>>
使用SDL动态显示鼠标的位置信息(四)
查看>>
MYSql安装
查看>>
Xenserver 中为虚拟机增加多个光驱
查看>>
UIPopoverController 常见问题
查看>>
kali linux 2017.2 OpenVAS9.0安装和使用
查看>>
PX Deq: Table Q Normal等待事件
查看>>
Gource,一个神奇的小软件
查看>>
小蚂蚁学习Linux(8)——mount挂载命令、挂载光盘、U盘的方法
查看>>
谈企业的DBA工作职责
查看>>
牛刀小试,Linux实践能力测试终极脚本
查看>>
mybatis in查询实例
查看>>
TypeScript基础入门 - 类型兼容性 - 泛型
查看>>
my-innodb-heavy-4G.cnf1 详解
查看>>
使用nohup让程序在远程主机后台运行
查看>>
mysql主从同步跳过错误的方法
查看>>
linux shell位置参数详解
查看>>
C++内存池的实现
查看>>
我该何去何从?
查看>>