linux使用rsync、inotify-tools实现多台服务器文件实时同步
需求:将本地192.168.1.10上的/data/wwwroot目录同步到
1、来源服务器上安装rsync、inotify-tools
yum -y install rsync
yum -y install inotify-tools
2、新建同步脚本(inotify_bak.sh)
#!/bin/bash
src=/data/wwwroot/
des1=web1
des2=web2
des3=web3
host1=192.168.1.12
host2=192.168.1.13
host3=192.168.1.14
user1=web
user2=web
user3=web
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e modify,delete,create,attrib $src | while read file DATE TIME DIR;
do
/usr/local/rsync/bin/rsync -vzrtopg --delete --exclude-from=/etc/exclude.txt --progress $src $user1@$host1::$des1 --password-file=/etc/web.passwd
/usr/local/rsync/bin/rsync -vzrtopg --delete --exclude-from=/etc/exclude.txt --progress $src $user2@$host2::$des2 --password-file=/etc/web.passwd
/usr/local/rsync/bin/rsync -vzrtopg --delete --exclude-from=/etc/exclude.txt --progress $src $user3@$host3::$des3 --password-file=/etc/web.passwd
echo " ${file} was rsynced" >>/data/logs/rsync/rsync.log 2>&1
done
上面的rsync和 inotifywait 的路径根据实际安装情况而定
注意: 这里的 web 是在目标服务器/etc/rsyncd.conf里配置的模块名称:[web] (后面配置目标服务器会讲到)
赋予执行权限: chmod +x inotify_bak.sh
新增密码文件:touch /etc/web.passwd 内容为密码 设置权限600
新增排除文件:touch /etc/exclude.txt 内容为不需要同步的目录或者文件 (也可以实时--include-from=只同步那些目录或者文件)
例如:
logs/
rubbish/
3、目标服务器配置(需要同步的服务器)
安装rsync 和 xinetd
yum -y install rsync xinetd
#安装后需要新建配置文件:
touch /etc/rsyncd.conf
修改rsyncd内容:
#Global Settings 全局配置
uid = root
gid = root
use chroot = no
max connections = 5
timeout = 600
pid file = /var/run/rsyncd.pid
lockfile = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
#模块配置
[web1]
path = /data/wwwroot/
ignore errors = yes
read only = no
write only = no
hosts allow = 192.168.1.10
hosts deny = *
list = yes
uid = root
gid = root
auth users = web
secrets file = /etc/web.passwd
这里的配置的web1和users就是inotify_bak.sh里面的dest1和user1的值
新增密码文件:内容 用户名:密码 设置权限600 例如:web:123456
touch /etc/web.passwd
注意:这里的密码要跟来源服务器那台的密码文件的密码一样
其他两台目标服务器也是同样的配置,然后都创建/data/wwwroot目录
4、启动运行
目标服务器:先启动rsync后台服务: /usr/bin/rsync --daemon
来源服务器: nohup inotify_bak.sh & 放入后台执行
现在可以试试在来源服务器的/data/wwwroot目录里面新建一个文件,看是否会实时同步到其他三台。
linux使用rsync、inotify-tools实现多台服务器文件实时同步的更多相关文章
- linux下两台服务器文件实时同步方案设计和实现
inux下两台服务器文件实时同步方案设计和实现 假设有如下需求: 假设两个服务器: 192.168.0.1 源服务器 有目录 /opt/test/ 192.168.0.2 目标服务器 有目录 /o ...
- Centos 6.5 rsync+inotify 两台服务器文件实时同步
rsync和inotify是什么我这里就不在介绍了,有专门的文章介绍这两个工具. 1.两台服务器IP地址分别为: 源服务器:192.168.1.2 目标服务器:192.168.1.3 @todo:从源 ...
- linux下两台服务器文件实时同步方案实现-乾颐堂
假设有如下需求: 假设两个服务器: 192.168.0.1 源服务器 有目录 /opt/test/ 192.168.0.2 目标服务器 有目录 /opt/bak/test/ 实现的目的就是保持这两 ...
- sersync+rsync实现服务器文件实时同步
sersync+rsync实现服务器文件实时同步 一.为什么要用rsync+sersync架构? 1.sersync是基于inotify开发的,类似于inotify-tools的工具 2.sersyn ...
- (转)Linux下通过rsync与inotify(异步文件系统事件监控机制)实现文件实时同步
Linux下通过rsync与inotify(异步文件系统事件监控机制)实现文件实时同步原文:http://www.summerspacestation.com/linux%E4%B8%8B%E9%80 ...
- linux系统中rsync+inotify实现服务器之间文件实时同步
最近需要对服务器上的文件实施动态备份,我又不想每次都手动来进行备份,在网上找了挺多资料,发现使用rsync就可以实现,如果想要实现实时同步,还可以使用rsync+inotify组合,本文就是以组合方式 ...
- linux设置rsync+inotify实时同步文件
linux设置rsync+inotify实时同步文件 应用场景: 同步接收方:test01 接收目录:/opt/software/test/a/ 同步发起方:test02 同步目录:/opt/so ...
- rsync+inotify 实现服务器之间目录文件实时同步(转)
软件简介: 1.rsync 与传统的 cp. tar 备份方式相比,rsync 具有安全性高.备份迅速.支持增量备份等优点,通过 rsync 可 以解决对实时性要求不高的数据备份需求,例如定期的备份文 ...
- centos6.5 rsync+inotify实现服务器之间文件实时同步
1. rsync的优点与不足 与传统的cp.tar备份方式相比,rsync具有安全性高.备份迅速.支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需求,例如定期的备份文件服务器数据 ...
随机推荐
- 一个Filter需要配置多个url-pattern
最近做项目遇到一个Filter需要配置多个url-pattern,上网查了下资料,经测试,现总结下 一.完全错误的方式 Java代码 <filter> <filter-name> ...
- 15-Call to your teacher(有向图的连通判断)
链接:https://www.nowcoder.net/acm/contest/76/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...
- SQLSERVER Tempdb的作用及优化
tempdb 系统数据库是可供连接到 SQL Server 实例的所有用户使用的全局资源.tempdb 数据库用于存储下列对象:用户对象.内部对象和版本存储区. 用户对象 用户对象由用户显式创建.这些 ...
- Zedboard学习(四):PS+PL搭建SoC最小系统 标签: fpgazedboardxilinxsoczynq 2017-07-07 15:58 7人阅读
zynq最核心的设计理念就是软件加硬件,即PS+PL.通过软硬件协同设计,结合了FPGA与双arm9内核,对于嵌入式拥有极大的优势. SoC:System on Chip的缩写,称为芯片级系统,也有称 ...
- jQuery自动截取文字长度,超过部分
<html> <head> <meta charset="utf-8"> <script src="js/jqu ...
- 黑盒测试实践-任务进度-Day04
任务进度11-29 使用工具 selenium 小组成员 华同学.郭同学.穆同学.沈同学.覃同学.刘同学 任务进度 经过了前两天的学习任务的安排,以下是大家的任务进度: 华同学(任务1) 1.和其他小 ...
- JAVA并发设计模式学习笔记(二)—— Single Threaded Execution Pattern
注:本文的主要参考资料为结城浩所著<JAVA多线程设计模式>. 单线程执行模式(Single Threaded Execution Pattern)是最简单的多线程设计模式,几乎所有其他的 ...
- HBase介绍(3)---框架结构及流程
HBASE依托于Hadoop的HDFS作为存储基础,因此结构也很类似于Hadoop的Master-Slave模式,Hbase Master Server 负责管理所有的HRegion Server,但 ...
- 实战iOS7之NSURLSession
NSURLSession VS NSURLConnection NSURLSession可以看做是NSURLConnection的进化版,其对NSURLConnection的改进点有: * 根据每个S ...
- 性能测试工具Locust的介绍和使用
内容来自网络 https://www.w3xue.com/exp/article/20191/16707.html https://blog.csdn.net/qq_36255988/article/ ...