一、环境描述

需求:服务器A与服务器B为主备服务模式,需要保持文件一致性,现采用sersync基于rsync+inotify实现数据实时同步

主服务器A:192.168.1.23

从服务器B:192.168.1.243

实时同步/var/atlassian目录到从服务器。

二、实施

1.从服务器192.168.1.243 rsync服务搭建

1.1安装软件包

  1. wget http://rsync.samba.org/ftp/rsync/src/rsync-3.1.1.tar.gz
  2. tar xf rsync-3.1..tar.gz C /opt/
  3. mv /opt/rsync-3.1. /opt/rsync
  4. cd /opt/rsync
  5. ./configure
  6. make && make install
  7. 创建rsyncd.conf文件
  8. vi /etc/rsyncd.conf
  1. vim /etc/rsyncd.conf
  1. #以root用户运行rsync服务
  2. uid = root
  3. #以root用户运行rsync服务
  4. gid = root
  5. #增加对目录文件软连接的备份
  6. use chroot = no
  7. #最大连接数
  8. max connections = 1200
  9. #超时时间
  10. timeout = 800
  11. #PID存放位置
  12. pid file = /var/run/rsyncd.pid
  13. #锁文件存放位置
  14. lockfile = /var/run/rsyncd.lock
  15. #日志存放位置
  16. log file = /var/log/rsyncd.log
  17. #认证模块名
  18. [atlassian]
  19. path = /var/atlassian
  20. ignore errors = yes
  21. hosts allow = 192.168.1.23
  22. hosts deny = * 
  23. read only = no
  24. write only = no
  25. list = yes
    #主服务器的同步用户
  26. auth users = ihome
  27. secrets file = /etc/rsync.pass

注:/etc/rsync.pass 文件格式为username:password

文件权限必须为600否则服务不正常

hosts allow 定义可为单独IP也可为网段,网段格式为172.26.7.0/24

也可为172.26.7.0/255.255.255.0

创建rsync.pass文件

  1. echo root:password”>>/etc/rsync.pass
  2. chmod /etc/rsync.pass

1.3启动服务

  1. [root@ha-db atlassian]#rsync --daemon v
  2. 开机自启动
  3. [root@ha-db atlassian]#echo "rsync --daemon –v">>/etc/rc.local

2.主服务器192.168.1.23配置

2.1软件安装

  1. 下载
    wget http://rsync.samba.org/ftp/rsync/src/rsync-3.1.1.tar.gz
  2. wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
  3. wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
  4.  
  5. 解压
  6. tar xf rsync-3.1..tar.gz C /opt
  7. tar xf inotify-tools-3.14.tar.gz C /opt
  8. tar xf sersync2..4_64bit_binary_stable_final.tar.gz C /opt
  9.  
  10. cd /opt
  11. mv rsync-3.1. rsync
  12. mv inotify-tools-.14 inotify-tools
  13. mv GNU-Linux-x86 sersync
  14.  
  15. 编译安装rsync
  16. cd rsync
  17. ./configure && make && make install
  18. 编译安装inotify-tools
  19. cd inotify-tools
  20. ./configure && make && make install

2.3 sersync服务配置

vim /opt/sersync/confxml.xml

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <head version="2.5">
  3. <host hostip="localhost" port="8008"></host>
  4. <debug start="false"/>
  5. <fileSystem xfs="false"/>
  6. <filter start="false">
  7. <exclude expression="(.*)\.svn"></exclude>
  8. <exclude expression="(.*)\.gz"></exclude>
  9. <exclude expression="^info/*"></exclude>
  10. <exclude expression="^static/*"></exclude>
  11. </filter>
  12. <inotify>
  13. <delete start="true"/>
  14. <createFolder start="true"/>
  15. <createFile start="false"/>
  16. <closeWrite start="true"/>
  17. <moveFrom start="true"/>
  18. <moveTo start="true"/>
  19. <attrib start="false"/>
  20. <modify start="false"/>
  21. </inotify>
  22.  
  23. <sersync>
  24. <localpath watch="/var/atlassian">
  25. <remote ip="192.168.1.243" name="atlassian"/>
  26. <!--<remote ip="192.168.8.39" name="tongbu"/>-->
  27. <!--<remote ip="192.168.8.40" name="tongbu"/>-->
  28. </localpath>
  29. <rsync>
  30. <commonParams params="-artuzlpog"/>
  31. <auth start="true" users="ihome" passwordfile="/opt/sersync/user.pass"/>
  32. <userDefinedPort start="false" port="874"/><!-- port=874 -->
  33. <timeout start="false" time="100"/><!-- timeout=100 -->
  34. <ssh start="false"/>
  35. </rsync>
  36. <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
  37. <crontab start="false" schedule="600"><!--600mins-->
  38. <crontabfilter start="false">
  39. <exclude expression="*.php"></exclude>
  40. <exclude expression="info/*"></exclude>
  41. </crontabfilter>
  42. </crontab>
  43. <plugin start="false" name="command"/>
  44. </sersync>
  45.  
  46. <plugin name="command">
  47. <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
  48. <filter start="false">
  49. <include expression="(.*)\.php"/>
  50. <include expression="(.*)\.sh"/>
  51. </filter>
  52. </plugin>
  53.  
  54. <plugin name="socket">
  55. <localpath watch="/var/atlassian">
  56. <deshost ip="192.168.1.243" port="8009"/>
  57. </localpath>
  58. </plugin>
  59. <plugin name="refreshCDN">
  60. <localpath watch="/data0/htdocs/cms.xoyo.com/site/">
  61. <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
  62. <sendurl base="http://pic.xoyo.com/cms"/>
  63. <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
  64. </localpath>
  65. </plugin>
  66. </head>

配置密码文件

  1. echo password”>>/opt/sersync/user.pass

注:文件权限必须为600否则启动异常

2.4服务启动

  1. nohup /opt/sersync/sersync2 -r -d -o /opt/sersync/confxml.xml >/opt/sersync/rsync.log >& &
  2. #######如果是多个目录同步需要启动两个进程
  3. nohup /opt/sersync/sersync2 -r -d -o /opt/sersync/downxml.xml >/opt/sersync/downrsync.log >&1
  1. -d:启用守护进程模式
  2. -r:在监控前,将监控目录与远程主机用rsync命令推送一遍
  3. -n:指定开启守护线程的数量,默认为10
  4. -o:指定配置文件,默认使用confxml.xml文件
  5. 开机启动
    echo "nohup /opt/sersync/sersync2 -r -d -o/opt/sersync/confxml.xml >/opt/sersync/rsync.log 2>&1 & ">>/etc/rc.local

三、验证

在主服务器上的/var/atlassian目录下创建文件查看从服务器192.168.1.243上是否有同步。

参考:http://9402618.blog.51cto.com/9392618/1728794

sersync基于rsync+inotify实现数据实时同步的更多相关文章

  1. CentOS 6.5 rsync+inotify实现数据实时同步备份

    CentOS 6.5 rsync+inotify实现数据实时同步备份 rsync    remote sync 远程同步,同步是把数据从缓冲区同步到磁盘上去的.数据在内存缓存区完成之后还没有写入到磁盘 ...

  2. 实战:rsync+inotify实现数据实时同步

    Linux 内核从 2.6.13 版本开始提供了 inotify 通知接口,用来监控文件系统的各种变化情况,如文件存取.删除.移动等.利用这一机制,可以非常方便地实现文件异动告警.增量备份,并针对目录 ...

  3. rsync+inotify磁盘数据实时同步

    一.rsync+inotify主服务器部署 1.1安装rsync [root@nginx ~]# cd /usr/src/ [root@nginx src]# tar zxvf rsync-3.0.9 ...

  4. rsync+inotify实现数据实时同步

    rsync rsync是linux系统下的数据镜像备份工具.支持远程同步,本地复制,或者与其他SSH.rsync主机同步. 优点: 1).可以镜像保存整个目录树和文件系统.保存源目录整个目录树和文件系 ...

  5. 利用rsync+inotify实现数据实时同步脚本文件

    将代码放在Server端,实现其它web服务器同步.首先创建rsync.shell,rsync.shell代码如下: #!/bin/bash host1=133.96.7.100 host2=133. ...

  6. 通过rsync+inotify实现数据实时备份同步

    一.环境描述 测试环境 需求:服务器A与服务器B为主备服务模式,需要保持文件一致性,现采用sersync基于rsync+inotify实现数据实时同步 环境描述: 主服务器172.26.7.50 ,从 ...

  7. Linux下Rsync+Inotify-tools实现数据实时同步

    Linux下Rsync+Inotify-tools实现数据实时同步 注意:下面的三个案例都是rsync 每次都是全量的同步(这就坑爹了),而且 file列表是循环形式触发rsync ,等于有10个文件 ...

  8. centos 6.9使用Rsync+Inotify-tools实现数据实时同步

    centos 6.9使用Rsync+Inotify-tools实现数据实时同步 说明: 操作系统:CentOS 6.9 源服务器:192.168.1.222 备份服务器:192.168.1.1.233 ...

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

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

随机推荐

  1. http请求报头

    客户请求的处理:Http请求报头 创建高效servlet的关键之一,就是要了解如何操纵超文本传输协议(HypeText TransferProtocol, HTTP). HTTP请求报头不同于前一章的 ...

  2. 彩信的在android里是如何存储的 Android MMS模块数据存取

    数据表MMS模块总共包含17张表:addr.android_metadata.attachments.canonical_addresses.drm.part.pdu.pending_msgs.rat ...

  3. Python seek和tell

    f = open("胡辣汤", mode="r+", encoding="utf-8") f.seek(0,2) # 移动到末尾 conte ...

  4. NBUT 1219 Time 2010辽宁省赛

    Time limit   1000 ms Memory limit   131072 kB Digital clock use 4 digits to express time, each digit ...

  5. Python中的import

    模块(module):用来从逻辑(实现一个功能)上组织Python代码(变量.函数.类),本质就是*.py文件.文件是物理上组织方式"module_name.py",模块是逻辑上组 ...

  6. I.MX6 计算iomux Pin配置

    /********************************************************************************* * I.MX6 计算iomux P ...

  7. Linux下你需要了解的10个网络和监控命令

    我下面列出来的10个基础的每个linux用户都应该知道的网络和监控命令.网络和监控命令类似于这些: hostname, ping, ifconfig, iwconfig, netstat, nsloo ...

  8. [LeetCode&Python] Problem 897. Increasing Order Search Tree

    Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root o ...

  9. 【图文教程】win7+VMware8.0+CentOS6.4 NAT上网

    在win7下面安装VM8.0,里面又安装多个虚拟机,各个虚拟机之间可以互相访问,同时虚拟机可以直接访问外网上网,win7要ping通个虚拟机中的系统.这种方式就使用NAT模式,开启VMware Net ...

  10. Hibernate4获取sessionFactory

    /** * Location of hibernate.cfg.xml file. * Location should be on the classpath as Hibernate uses * ...