sersync基于rsync+inotify实现数据实时同步
一、环境描述
需求:服务器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安装软件包
- wget http://rsync.samba.org/ftp/rsync/src/rsync-3.1.1.tar.gz
- tar xf rsync-3.1..tar.gz –C /opt/
- mv /opt/rsync-3.1. /opt/rsync
- cd /opt/rsync
- ./configure
- make && make install
- 创建rsyncd.conf文件
- vi /etc/rsyncd.conf
- vim /etc/rsyncd.conf
- #以root用户运行rsync服务
- uid = root
- #以root用户运行rsync服务
- gid = root
- #增加对目录文件软连接的备份
- use chroot = no
- #最大连接数
- max connections = 1200
- #超时时间
- timeout = 800
- #PID存放位置
- pid file = /var/run/rsyncd.pid
- #锁文件存放位置
- lockfile = /var/run/rsyncd.lock
- #日志存放位置
- log file = /var/log/rsyncd.log
- #认证模块名
- [atlassian]
- path = /var/atlassian
- ignore errors = yes
- hosts allow = 192.168.1.23
- hosts deny = *
- read only = no
- write only = no
- list = yes
#主服务器的同步用户- auth users = ihome
- 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文件
- echo “root:password”>>/etc/rsync.pass
- chmod /etc/rsync.pass
1.3启动服务
- [root@ha-db atlassian]#rsync --daemon –v
- 开机自启动
- [root@ha-db atlassian]#echo "rsync --daemon –v">>/etc/rc.local
2.主服务器192.168.1.23配置
2.1软件安装
- 下载
wget http://rsync.samba.org/ftp/rsync/src/rsync-3.1.1.tar.gz- wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
- wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
- 解压
- tar xf rsync-3.1..tar.gz –C /opt
- tar xf inotify-tools-3.14.tar.gz –C /opt
- tar xf sersync2..4_64bit_binary_stable_final.tar.gz –C /opt
- cd /opt
- mv rsync-3.1. rsync
- mv inotify-tools-.14 inotify-tools
- mv GNU-Linux-x86 sersync
- 编译安装rsync
- cd rsync
- ./configure && make && make install
- 编译安装inotify-tools
- cd inotify-tools
- ./configure && make && make install
2.3 sersync服务配置
vim /opt/sersync/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>
- <delete start="true"/>
- <createFolder start="true"/>
- <createFile start="false"/>
- <closeWrite start="true"/>
- <moveFrom start="true"/>
- <moveTo start="true"/>
- <attrib start="false"/>
- <modify start="false"/>
- </inotify>
- <sersync>
- <localpath watch="/var/atlassian">
- <remote ip="192.168.1.243" name="atlassian"/>
- <!--<remote ip="192.168.8.39" name="tongbu"/>-->
- <!--<remote ip="192.168.8.40" name="tongbu"/>-->
- </localpath>
- <rsync>
- <commonParams params="-artuzlpog"/>
- <auth start="true" users="ihome" passwordfile="/opt/sersync/user.pass"/>
- <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 every 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>
- <plugin name="command">
- <param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
- <filter start="false">
- <include expression="(.*)\.php"/>
- <include expression="(.*)\.sh"/>
- </filter>
- </plugin>
- <plugin name="socket">
- <localpath watch="/var/atlassian">
- <deshost ip="192.168.1.243" port="8009"/>
- </localpath>
- </plugin>
- <plugin name="refreshCDN">
- <localpath watch="/data0/htdocs/cms.xoyo.com/site/">
- <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
- <sendurl base="http://pic.xoyo.com/cms"/>
- <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
- </localpath>
- </plugin>
- </head>
配置密码文件
- echo “password”>>/opt/sersync/user.pass
注:文件权限必须为600否则启动异常
2.4服务启动
- nohup /opt/sersync/sersync2 -r -d -o /opt/sersync/confxml.xml >/opt/sersync/rsync.log >& &
- #######如果是多个目录同步需要启动两个进程
- nohup /opt/sersync/sersync2 -r -d -o /opt/sersync/downxml.xml >/opt/sersync/downrsync.log >&1
- -d:启用守护进程模式
- -r:在监控前,将监控目录与远程主机用rsync命令推送一遍
- -n:指定开启守护线程的数量,默认为10个
- -o:指定配置文件,默认使用confxml.xml文件
- 开机启动
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实现数据实时同步的更多相关文章
- CentOS 6.5 rsync+inotify实现数据实时同步备份
CentOS 6.5 rsync+inotify实现数据实时同步备份 rsync remote sync 远程同步,同步是把数据从缓冲区同步到磁盘上去的.数据在内存缓存区完成之后还没有写入到磁盘 ...
- 实战:rsync+inotify实现数据实时同步
Linux 内核从 2.6.13 版本开始提供了 inotify 通知接口,用来监控文件系统的各种变化情况,如文件存取.删除.移动等.利用这一机制,可以非常方便地实现文件异动告警.增量备份,并针对目录 ...
- rsync+inotify磁盘数据实时同步
一.rsync+inotify主服务器部署 1.1安装rsync [root@nginx ~]# cd /usr/src/ [root@nginx src]# tar zxvf rsync-3.0.9 ...
- rsync+inotify实现数据实时同步
rsync rsync是linux系统下的数据镜像备份工具.支持远程同步,本地复制,或者与其他SSH.rsync主机同步. 优点: 1).可以镜像保存整个目录树和文件系统.保存源目录整个目录树和文件系 ...
- 利用rsync+inotify实现数据实时同步脚本文件
将代码放在Server端,实现其它web服务器同步.首先创建rsync.shell,rsync.shell代码如下: #!/bin/bash host1=133.96.7.100 host2=133. ...
- 通过rsync+inotify实现数据实时备份同步
一.环境描述 测试环境 需求:服务器A与服务器B为主备服务模式,需要保持文件一致性,现采用sersync基于rsync+inotify实现数据实时同步 环境描述: 主服务器172.26.7.50 ,从 ...
- Linux下Rsync+Inotify-tools实现数据实时同步
Linux下Rsync+Inotify-tools实现数据实时同步 注意:下面的三个案例都是rsync 每次都是全量的同步(这就坑爹了),而且 file列表是循环形式触发rsync ,等于有10个文件 ...
- centos 6.9使用Rsync+Inotify-tools实现数据实时同步
centos 6.9使用Rsync+Inotify-tools实现数据实时同步 说明: 操作系统:CentOS 6.9 源服务器:192.168.1.222 备份服务器:192.168.1.1.233 ...
- Rsync+inotify实现文件实时同步#附shell脚本
强烈推荐先仔细看此文 https://segmentfault.com/a/1190000002427568 实验环境 centos 7.3 vm2:192.168.221.128 同步服务器 vm1 ...
随机推荐
- http请求报头
客户请求的处理:Http请求报头 创建高效servlet的关键之一,就是要了解如何操纵超文本传输协议(HypeText TransferProtocol, HTTP). HTTP请求报头不同于前一章的 ...
- 彩信的在android里是如何存储的 Android MMS模块数据存取
数据表MMS模块总共包含17张表:addr.android_metadata.attachments.canonical_addresses.drm.part.pdu.pending_msgs.rat ...
- Python seek和tell
f = open("胡辣汤", mode="r+", encoding="utf-8") f.seek(0,2) # 移动到末尾 conte ...
- NBUT 1219 Time 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Digital clock use 4 digits to express time, each digit ...
- Python中的import
模块(module):用来从逻辑(实现一个功能)上组织Python代码(变量.函数.类),本质就是*.py文件.文件是物理上组织方式"module_name.py",模块是逻辑上组 ...
- I.MX6 计算iomux Pin配置
/********************************************************************************* * I.MX6 计算iomux P ...
- Linux下你需要了解的10个网络和监控命令
我下面列出来的10个基础的每个linux用户都应该知道的网络和监控命令.网络和监控命令类似于这些: hostname, ping, ifconfig, iwconfig, netstat, nsloo ...
- [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 ...
- 【图文教程】win7+VMware8.0+CentOS6.4 NAT上网
在win7下面安装VM8.0,里面又安装多个虚拟机,各个虚拟机之间可以互相访问,同时虚拟机可以直接访问外网上网,win7要ping通个虚拟机中的系统.这种方式就使用NAT模式,开启VMware Net ...
- Hibernate4获取sessionFactory
/** * Location of hibernate.cfg.xml file. * Location should be on the classpath as Hibernate uses * ...