(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. Linux终端彩色显示输出结果

    转义序列符 为了添加个人风格的彩色提示符,我们需要使用转义序列符.一个转义序列符是一个控制命令,它控制Shell执行某个特定的动作.一个转义序列符通常以 ESC开始,在Shell中被记录为" ...

  2. Struts2 Action类的创建以及参数传递以及接收

    一.Struts中Action得创建方式 1,直接创建一个简单的Action类 添加Struts.xml,配置转发方法返回转发的页面. 2,实现一个Action类 Strust.xml配置对应的Url ...

  3. #Python绘制 文本进度条,带刷新、时间暂缓的

    #Python绘制 文本进度条,带刷新.时间暂缓的 #文本进度条 import time as T st=T.perf_counter() print('-'*6,'执行开始','-'*6) maxx ...

  4. Css案例整理

    1.实现两个div并排显示 案例:checkbox的标题和内容需要并排显示,checkbox竖向排列 <head> <style type="text/css"& ...

  5. LINQ to DataSet,对离线数据的Linq支持、AsEnumeable()

    一.DataTable的扩展方法: 1.DataTable转Linq:AsEnumerable 方法 返回IEnumerable<T>对象,其中泛型参数T是DataRow. 此对象可用在 ...

  6. mysql group_concat长度限制

    group_concat函数有长度限制 查找当前数据库长度 show variables like 'group_concat_max_len' 设置当前session的group_concat长度, ...

  7. delegate:动态绑定js事件

    $('.videomodule').delegate("span", "click", function() { var i = $(this).index() ...

  8. P4136 谁能赢呢? 脑子

    思路:脑子(教练说是博弈论?) 提交:1次 题解: 结论:若\(n\)为奇数后手胜,若\(n\)为偶数先手胜. 大致证明: 我们发现,若我们把棋盘黑白染色并设左上角为黑色,那么显然有:若\(n\)为奇 ...

  9. django -过滤器的使用

    前情提要: 最近工作中用到django 中的  自定制过滤器的内容, 再此 复习一波过滤器和自定制 过滤器的内容 自定制过滤器   1.在settings中的INSTALLED_APPS配置当前app ...

  10. Ubuntu 蓝牙鼠标的问题

    问题: 我有一个小巧的蓝牙鼠标,但有一个问题. 当它不使用一段时间时,它会关闭. 好的我得按按钮把它打开. 但是我发现,在我在蓝牙小程序下单击"连接"之前,它不会再被Ubuntu识 ...