rsync+inotify-tools与rsync+sersync架构的区别
1,rsync+inotify-tools
只能记录下被监听的目录发生的变化(增删改)并没有把具体变化的文件或目录记录下来
在同步时,并不知道具体哪个文件或目录发送变化而是每次都对整个目录树来进行便利查找变更文件
然触发全部数据进行同步,当数据量很大时,整个目录同步非常耗时,因此效率很低
2,rsync+sersync
sersync可以记录内监听目录中发送的文件或目录(增删改)具体某个文件或目录的名字
rsync 在同步时,只同步发生变化的文件或目录,(每次发送变化的数据相对整个同步目录数据来说很小,rsync
在遍历查找对比文件时,速度很快),因此效率很高

同步过程
1,,在源数据服务器上开启sersync服务,sersync负责监控配置路径中的文件系统事件变化
2,,调用rsync命令把更新的文件同步到目标服务器
3,, 需要在源数据服务器配置sersync ,在同步目标服务器配置rsync server

同步原理
1.用户实时的往sersync服务器上写入更新文件数据
2,此时需要在源数据上配置sersync服务
3,在另一台服务器开启rsync 守护进程服务,以同步拉取来自sersync服务器上的数据
通过rsync的守护进程服务后可以发现,实际上sersync就是监控本地的数据写入或更新事件,然后,在调用rsync
客户端的命令,将写入或更新对应文件通过rsync推送到目标服务器
Centos 7 172.20.10.2(sersync server)
Centos 7 172.20.10.6 (rsync server

关闭防火墙

关闭selinux

iptable -F

setenforce 0

systemctl stop firewalld

systemctl distable firewalld

目标服务器172.20.10.6安装rsync实现同步数据
[root@cheng ~]# yum -y install rsync httpd
[root@cheng ~]# vim /etc/rsyncd.conf

uid = root
gid = root
use chroot = yes
max connections = 100
timeout = 600
ignore errors
list = false
address = 172.20.10.6
port = 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 172.20.10.0/24
[wwwroot]
path = /var/www/html
comment = Document Root os www.zc.com
read only = no
dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
auth users = backuper
secrets file = /etc/rsyncd_users.db
基于安全性考虑,对于rsync的备份源最好仅允许以只读的方式做下同步,另外,同步可以采用匿名的方式,只要将其中的
auth users和secrets file 配置记录去掉就可以了
2,为备份账号创建数据文件,以冒号分割,密码信息在文件中以明文方式存放,为避免信息泄露,需要调整权限
[root@cheng ~]# vim /etc/rsyncd_users.db
backuper:pwd123
[root@cheng ~]# chmod 600 /etc/rsyncd_users.db
备份用户backuper 也需要对/var/www/html 有相应的读取权限,实际上只要other组具有读取权限,
则备份用户backuper和运行nobody用户也就有读取权限了
[root@cheng ~]# ls -ls /var/www/html
3,启动服务,以独立监听服务的方式运行 ,若关闭rsync服务科采取kill进程方式
[root@cheng ~]# rsync --daemon
[root@cheng ~]# netatst -anpt |grep rsync
回显内容:tcp 0 0 172.20.10.6 :873 0.0.0.0:* LISTEN 3650/rsync

在数据源创建密码文件,172.20.10.2,然后在rsync命令中使用rsync --password-file 指定该文件
[root@zhao ~]# echo "pwd123" > /etc/server.pass
[root@zhao ~]# chmod 600 /etc/server.pass
[root@zhao ~]# rsync -az --delete --password-file=/etc/serer.pass /etc/hosts backuper@172.20.10.6::wwwroot

[root@cheng ~]#在另一机器可以看到
cat /var/www/html
有个hosts
测试这一步一定要成功,不然进行不了下一步
部署sersync服务 172.20.10.2部署

[root@zhao ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local
[root@zhao ~]# cd /usr/local
[root@zhao local]# ls
bin boost etc games GNU-Linux-x86 include lib lib64 libexec mysql nginx php5 sbin share src
[root@zhao local]# mv GNU-Linux-x86/ sersync
[root@zhao local]# cd sersync/
[root@zhao sersync]# cp confxml.xml confxml.xml.$(date +%F)
[root@zhao sersync]# vim confxml.xml
修改31行内容 <auth start="true" users="backuper" passwordfile="/etc/server.pass"/>

修改24行 <localpath watch="/var/www/html"
修改25行 <remote ip="172.20.10.6" name="wwwroot"/>

开启server 守护进程,同步数据
[root@zhao sersync]# yum -y install httpd
[root@zhao sersync]# ./sersync2 -d -r -o /usr/local/sersync/confxml.xml set the system param
use rsync password-file :
user is backuper
passwordfile is /etc/server.pass
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /var/www/html && rsync -artuz -R --delete ./ backuper@172.20.10.6::wwwroot --password-file=/etc/server.pass >/dev/null 2>&1

测试同步、添加数据
[root@zhao sersync]# cd /var/www/html
[root@zhao html]# ls
[root@zhao html]# mkdir zc
[root@zhao html]# cd zc
[root@zhao zc]# touch {1..5}.txt
[root@zhao zc]# ls -l
总用量 0
-rw-r--r--. 1 root root 0 3月 7 18:54 1.txt
-rw-r--r--. 1 root root 0 3月 7 18:54 2.txt
-rw-r--r--. 1 root root 0 3月 7 18:54 3.txt
-rw-r--r--. 1 root root 0 3月 7 18:54 4.txt
-rw-r--r--. 1 root root 0 3月 7 18:54 5.txt

[root@cheng ~]# ls /var/www/html
zc
[root@cheng ~]# ls -l /var/www/html/zc
总用量 0
-rw-r--r--. 1 root root 0 3月 7 18:54 1.txt
-rw-r--r--. 1 root root 0 3月 7 18:54 2.txt
-rw-r--r--. 1 root root 0 3月 7 18:54 3.txt
-rw-r--r--. 1 root root 0 3月 7 18:54 4.txt
-rw-r--r--. 1 root root 0 3月 7 18:54 5.txt

Sersync+Rsync实现数据文件实时同步的更多相关文章

  1. CentOS 7 Sersync+Rsync 实现数据文件实时同步

    rsync+inotify-tools与rsync+sersync架构的区别? 1.rsync+inotify-tools inotify只能记录下被监听的目录发生了变化(增,删,改)并没有把具体是哪 ...

  2. sersync+rsync实现服务器文件实时同步

    sersync+rsync实现服务器文件实时同步 一.为什么要用rsync+sersync架构? 1.sersync是基于inotify开发的,类似于inotify-tools的工具 2.sersyn ...

  3. rsync+sersync实现数据文件实时同步

    一.简介 sersync是基于Inotify开发的,类似于Inotify-tools的工具: sersync可以记录下被监听目录中发生变化的(包括增加.删除.修改)具体某一个文件或某一个目录的名字: ...

  4. Rsync+inotify实现文件实时同步#附shell脚本

    强烈推荐先仔细看此文 https://segmentfault.com/a/1190000002427568 实验环境 centos 7.3 vm2:192.168.221.128 同步服务器 vm1 ...

  5. 数据文件实时同步(rsync + sersync2)

    因近期项目需求,需要同步云端服务器的数据给**方做大数据分析. 思路: 起初只要数据同步,准备开放数据采集接口.但实时性较差,会有延迟. 故而寻觅各种解决方案,最终确定使用 rsync 进行文件同步, ...

  6. python自动化运维-编写rsync+sersync安装脚本实现文件实时同步

    rsync+sersync组合可以实时监听目录的变化,实现实时同步数据. 具体安装教程可查看:http://www.osyunwei.com/archives/7447.html. 安装着实有些复杂, ...

  7. Linux学习-利用inotify和rsync实现数据的实时同步

    一.inotify简介 1.inotify介绍 异步的文件系统事件监控机制,利用事件驱动机制,而无须通过诸如cron等的 轮询机制来获取事件,linux内核从2.6.13起支持 inotify,通过i ...

  8. Rsync + inotify 实现文件实时同步

    Rsync 用来实现触发式的文件同步. Inotify-tools是一套组件,Linux内核从2.6.13版本开始提供了inotify通知接口,用来监控文件系统的各种变化情况,如文件存取.删除.移动等 ...

  9. Centos 6.5配置rsync+inotify实现文件实时同步

    1.安装rsync(两台机器执行相同的步骤)yum install gcc yum install rsyncd xinetd -y因为rsync是由xinetd启动的,所以需要修改一个配置vim / ...

随机推荐

  1. Rsync命令的使用

    Rsync的命令格式能够为下面六种: rsync [OPTION]- SRC DEST rsync [OPTION]- SRC [USER@]HOST:DEST rsync [OPTION]- [US ...

  2. Linux下Shell编程

    Linux的shell编程 1.什么是shell? 当一个用户登录Linux系统之后,系统初始化程序init就为每个用户执行一个称为shell(外壳)的程序. shell就是一个命令行解释器,它为用户 ...

  3. 发现所有的字都被加上了 <font> 标签,导致样式全部错乱

    经检查,发现我的浏览器默认打开了翻译软件!!!!!!!

  4. border-image 和 border-color 不能同时使用问题

    遇到如下问题: UI 给的设计,某部分,上边框为 图片,下边框为灰色横线. 看到这个的第一反应是,上边框用 border-image ,为了只让上边框显示图片,所以只给上边框宽度为所需宽度,我的图是 ...

  5. Objective-C NSFileManager 文件管理总结

    createFileAtPath //创建文件 NSFileManager *fm = [NSFileManager defaultManager]; NSString *strpath = [NSS ...

  6. vue cli webstorm

    贫富差距的产生 – 目光博客 http://eyehere.net/2017/1947/ https://github.com/vuejs/vue Vue 2.0 Hello World - JSFi ...

  7. MapReduce04

    ===================== MapReduce内部机制:本地性 ===================== 什么是数据本地性(data locality)--------------- ...

  8. YTU 2706: 编写一个函数求最大的n值

    2706: 编写一个函数求最大的n 值. 时间限制: 1 Sec  内存限制: 128 MB 提交: 341  解决: 132 题目描述 编写一个函数求满足以下条件的最大的n.:12+22+32+-+ ...

  9. .NET平台下Redis使用(二)【StackExchange.Redis学习】

    Program.cs内容: using Newtonsoft.Json; using StackExchange.Redis; using System; using System.Data; usi ...

  10. Coursera Algorithms Programming Assignment 4: 8 Puzzle (100分)

    题目原文:http://coursera.cs.princeton.edu/algs4/assignments/8puzzle.html 题目要求:设计一个程序解决8 puzzle问题以及该问题的推广 ...