(1).实验环境

  源主机:youxi1  192.168.5.101

  目的主机:youxi2  192.168.5.102

  目的:实时同步数据

  sersync默认端口874,rsync默认端口873

(2).实验

1)下载sersync

  wegt https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

  或者Windows下载再上传源主机youxi1。

2)解压

[root@youxi1 ~]# ls
anaconda-ks.cfg sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@youxi1 ~]# tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz  //解压
GNU-Linux-x86/
GNU-Linux-x86/sersync2
GNU-Linux-x86/confxml.xml
[root@youxi1 ~]# ls
anaconda-ks.cfg GNU-Linux-x86 sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@youxi1 ~]# mv GNU-Linux-x86 sersync  改名
[root@youxi1 ~]# ls
anaconda-ks.cfg sersync sersync2.5.4_64bit_binary_stable_final.tar.gz

3)在目标主机youxi2上修改/etc/rsyncd.conf配置文件,以及密码文件

[root@youxi2 ~]# cat /etc/rsyncd.conf
uid = root
gid = root
address = 192.168.5.102
port = 873
hosts allow = 192.168.5.101/24
use chroot = yes
max connections = 5
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
[backupwwwhtml]
path = /backup/www/html
comment = backup /www/html/
read only = false
list = yes
auth users = rsync2
secrets file = /etc/rsync.passwd
[root@youxi2 ~]# cat /etc/rsync.passwd
rsync2:102102
[root@youxi2 ~]# chmod 600 /etc/rsync.passwd

  启动指定配置文件的rsync的守护进程

[root@youxi2 ~]# rsync --daemon --config=/etc/rsyncd.conf
[root@youxi2 ~]# ps aux | grep rsync
root 1478 0.0 0.0 114740 564 ? Ss 11:10 0:00 rsync --daemon --config=/etc/rsyncd.conf
root 1485 0.0 0.0 112720 980 pts/0 R+ 11:12 0:00 grep --color=auto rsync

4)源主机youxi1上修改sersync的配置文件

[root@youxi1 sersync]# vim confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="false">
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify> <sersync>
<localpath watch="/www/html">
<remote ip="192.168.5.102" name="backupwwwhtml"/>  //修改为目标主机IP地址和模块名
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="rsync2" passwordfile="/etc/rsync.passwd"/>  //开启,修改用户名和密码文件地址
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default e
very 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>

  添加密码文件

[root@youxi1 sersync]# vim /etc/rsync.passwd
102102
[root@youxi1 html]# chmod 600 /etc/rsync.passwd

5)开启源主机youxi1的sersync的守护进程

[root@youxi1 sersync]# /root/sersync/sersync2 -dro /root/sersync/confxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: /root/sersync/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
daemon start,sersync run behind the console
use rsync password-file :
user is rsync2
passwordfile is /etc/rsync.passwd
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 /www/html && rsync -artuz -R --delete ./ rsync2@192.168.5.102::backupwwwhtml --password-file=/etc/rsync.passwd >/dev/null 2>&1
run the sersync:
watch path is: /www/html

6)测试

  现在的目的主机youxi2情况如下

[root@youxi2 ~]# ls /backup/www/html/
adm crash empty gopher lib lock mail opt run tmp
cache db games kerberos local log nis preserve spool yp

  对源主机youxi1的/www/html/目录下文件进行操作

[root@youxi1 sersync]# cd /www/html/
[root@youxi1 html]# ls
adm crash empty gopher lib lock mail opt run tmp
cache db games kerberos local log nis preserve spool yp
[root@youxi1 html]# rm -rf adm/
[root@youxi1 html]# touch 1.txt
[root@youxi1 html]# ls
1.txt crash empty gopher lib lock mail opt run tmp
cache db games kerberos local log nis preserve spool yp

  回到目的主机查看情况

[root@youxi2 ~]# ls /backup/www/html/
1.txt crash empty gopher lib lock mail opt run tmp
cache db games kerberos local log nis preserve spool yp

  

sersync+rsync做实时同步的更多相关文章

  1. Linux下Rsync+sersync实现数据实时同步

    inotify 的同步备份机制有着缺点,于是看了sersync同步,弥补了rsync的缺点.以下转自:http://www.osyunwei.com/archives/7447.html 前言: 一. ...

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

    前言: 一.为什么要用Rsync+sersync架构? 1.sersync是基于Inotify开发的,类似于Inotify-tools的工具 2.sersync可以记录下被监听目录中发生变化的(包括增 ...

  3. Rsync+sersync实现数据实时同步

    前言: 一.为什么要用Rsync+sersync架构? 1.sersync是基于Inotify开发的,类似于Inotify-tools的工具 2.sersync可以记录下被监听目录中发生变化的(包括增 ...

  4. CentOS7下Rsync+sersync实现数据实时同步

    近期公司要上线新项目,后台框架选型我选择当前较为流行的laravel,运行环境使用lnmp. 之前我这边项目tp32+apache,开发工具使用phpstorm. 新建/编辑文件通过phpstorm配 ...

  5. centos7服务搭建常用服务配置之二:Rsync+sersync实现数据实时同步

    目录 1.RSYNC数据备份 1.1 rsync服务简介 1.2 rsync特点和优势 1.3 rysnc运行模式简介 1.4 数据同步方式 2 Rsync实验测试 2.1 实验环境说明 2.2 服务 ...

  6. inotify+rsync实现实时同步

    第1章 数据实时同步介绍 1.1 什么是实时同步:如何实现实时同步 A. 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化 B. 发现目录中数据产生变化,就利用rsync服务推送到 ...

  7. 【转】inotify+rsync实现实时同步

    [转]inotify+rsync实现实时同步 1.1 什么是实时同步:如何实现实时同步 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化 发现目录中数据产生变化,就利用rsync服 ...

  8. rsync+inotify实时同步环境部署记录

    随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐渐暴露出了很多不足.首先,rsync在同步数据时,需要扫描所有文件后进行比对,进行差量传输.如果文件 ...

  9. CentOS6.5实现rsync+inotify实时同步

    参考博文: 参考1:CentOS6.5实现rsync+inotify实时同步 参考2:inotify-tools+rsync实时同步文件安装和配置 CentOS 6.3下rsync服务器的安装与配置  ...

随机推荐

  1. 15、TDM模型

    论文:https://arxiv.org/pdf/1801.02294.pdf 解析: 学习基于树的推荐系统深度模型 Learning Tree-based DeepModel for Recomme ...

  2. 【简易DFS/BFS+标记搜索次序的数组】zznu-2025 : 简单环路

    2025 : 简单环路 时间限制:1 Sec 内存限制:128 MiB提交:145 答案正确:41 提交 状态 编辑 讨论区 题目描述 有一个N x M 大小的地图,地图中的每个单元包含一个大写字母. ...

  3. [2019牛客多校第三场][G. Removing Stones]

    题目链接:https://ac.nowcoder.com/acm/contest/883/G 题目大意:有\(n\)堆石头,每堆有\(a_i\)个,每次可以选其中两堆非零的石堆,各取走一个石子,当所有 ...

  4. BZOJ 5496: [2019省队联测]字符串问题 (后缀数组+主席树优化建图+拓扑排序)

    题意 略 分析 考场上写了暴力建图40分溜了-(结果只得了30分) 然后只要优化建边就行了 首先给出的支配关系无法优化,就直接A向它支配的B连边. 考虑B向以B作为前缀的所有A连边,做一遍后缀数组,两 ...

  5. map填充bean赋值,包括父类全部填充。

    有不少工具类给bean填充值.但是填充,很多都是只能填充到当前类的对象.经过需求修改,做了个工具类: import java.lang.reflect.Field; import java.lang. ...

  6. decompiler

    .NET Reflector  trial version http://www.red-gate.com/products/dotnet-development/reflector/ 破解版本 .N ...

  7. 将.mat文件中的数据转换成图片

    %% 如何将.mat文件中的数据转换成图片 clc;clear all; addpath F_data/MAT;load('D:\face.mat') for i=1:q   img=uint8(re ...

  8. GoEasy实现websocket 推送消息通知到客户端

    最近在实现一个推送功能,用户扫描二维码签到,后台及时将签到成功信息推送到浏览器端.排除了前端ajax轮询的方式,决定采用websocket及时推送. 于是发现了第三方websocket推送库GoEas ...

  9. 使用Ajax向SpringMVC传递Json数据

    这篇文章已经过时了. 请参考比较合适的前后端交互方式. 1.保证SpringMVC配置成功了. 2.在pom.xml中追加Jackson相关的依赖 <dependency> <gro ...

  10. MySQL数据分析(16)— 数据操作之增删改查

    前面我们说学习MySQL要从三个层面,四大逻辑来学,三个层面就是库层面,表层面和数据层面对吧,数据库里放数据表,表里放数据是吧,大家可以回忆PPT中jacky的这图,我们已经学完了库层面和表层面,从本 ...