使用sersync实现实时同步实战
场景需求:
应用程序会在机器192.168.2.2 /usr/local/news目录中生成一些数据文件,现在需要实时同步到主机192.168.3.3/usr/local/www/cn/news中,同时传送的文件过去的权限必须是tomcat权限
client端:192.168.2.2
server端:192.168.3.3
操作系统:centos6
使用工具sersync rsync
sersync是基于inotify开发的,类似于inotify-tools的工具,Sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或者某一个目录的名字,然后使用rsync同步的时候,只同步发生变化的文件或者目录,因此效率更高。
搭建开始:
server端192.168.3.3配置
1.安装rsync
yum -y install rsync
2.修改配置
vim /etc/rsyncd.conf uid=tomcat
gid=tomcat
max connections=
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock [news]
path=/usr/local/www/cn/news
ignore errors
read only = no
hosts allow = 192.168.2.2/
hosts deny = * auth users = tomcat
secrets file = /etc/rsyncd.password
~
3.创建密码文件
vim /etc/rsyncd.password tomcat:
说明:定义格式 用户:密码
4.修改密码文件权限
chmod /etc/rsyncd.password
5. 创建数据存放目录
mkdir -p /usr/local/www/cn/news
chown tomcat:tomcat /usr/local/www/cn/news
6.启动服务
rsync --daemon
说明:如果配置文件路径不是/etc/rsyncd.conf,启动是需要使用“–config” 参数指定配置文件。
7.查看服务是否启动
ps axu |grep rsync netstat -nlp |grep
client端192.168.2.2配置
1.安装rsync
yum -y install rsync
2.创建密码文件
vim /etc/rsyncd.password
3.修改密码文件权限
chmod /etc/rsyncd.password
4、安装配置sersync
4.1.下载地址
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz
4.2.解压软件包
tar zxvf sersync2..4_64bit_binary_stable_final.tar.gz
4.3.创建目录结构
mkdir /usr/local/sersync mkdir /usr/local/sersync/conf mkdir /usr/local/sersync/logs mkdir /usr/local/sersync/bin
4.4.移动文件
mv GNU-Linux-x86/sersync2 /usr/local/sersync/bin/ mv GNU-Linux-x86/confxml.xml /usr/local/sersync/conf
4.5.配置环境变量
source /etc/profile
添加配置:
SERSYNC2_HOME=/usr/local/sersync
PATH=$SERSYNC2_HOME/bin:$PATH
export PATH=$PATH:/usr/local/bin
source /etc/profile
4.6.配置sersync
cd /usr/local/sersync/conf cp confxml.xml confxml.xml.bak vim confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
# 设置本地IP和端口
<host hostip="localhost" port="8008"></host>
# 开启DUBUG模式
<debug start="false"/>
# 开启xfs文件系统
<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="false"/>
<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=" /usr/local/news/">
#定义同步Server ip和模块
<remote ip="192.168.3.3" name="news"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
# rsync指令参数
<commonParams params="-artuz"/>
# rsync同步认证
<auth start="true" users="tomcat" passwordfile="/etc/rsyncd.password"/>
# 设置rsync远程服务端口,非默认端口需要打开自定义(若开启rsync+ssh, 则这里需定义SSH端口)
<userDefinedPort start="true" port="873"/><!-- port=874 -->
# 设置超时时间
<timeout start="ture" time="100"/><!-- timeout=100 -->
# 设置rsync+ssh加密传输模式,默认关闭,开启需设置SSH加密证书
<ssh start="false"/>
</rsync>
# sersync传输失败日志脚本路径,每隔60会重新执行该脚本,执行完毕会自动清空。
<failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
# 设置rsync定时传输,默认关闭
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
# 设置sersync传输后调用name指定的插件脚本,默认关闭
<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="/opt/tongbu">
<deshost ip="192.168.138.20" 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>
---------------------
4.7 启动sersync
sersync2 -d -r -o /usr/local/sersync/conf/confxml.xml
4.8 测试
在192.168.2.2 /usr/local/news上用tomcat用户创建测试文件,然后在192.168.3.3/usr/local/www/cn/news中查看是否有该文件同步
注意:客户端到server端的873端口必须要通
测试rsync是否生效可用下面命令测试
在客户端使用rsync同步命令,先在192.168.2.2 /usr/local/news目录下创建test.txt文件然后执行命令
rsync -avzP test.txt tomcat@192.168.3.3::news --password-file=/etc/rsyncd.password
使用sersync实现实时同步实战的更多相关文章
- 5、Sersync实时同步实战
1.实时同步概述 1.什么是实时同步, 只要当前目录发生变化则会触发一个事件,事件触发后将变化的目录同步至远程服务器. 2.为什么要实时同步, 保证数据的连续性, 减少人力维护成本, 解决nfs单点故 ...
- (转)Linux系统sersync数据实时同步
Linux系统sersync数据实时同步 原文:http://blog.csdn.net/mingongge/article/details/52985259 前面介绍了以守护进程的方式传输或同步数据 ...
- sersync/lsyncd实时同步
第一章 sersync/lsync实时同步 1.1 实时同步服务原理/概念 1)需要部署好rsync守护进程服务,实现数据传输 2)需要部署好inotify服务,实现目录中数据变化监控 3)将rsyn ...
- Rsync+Sersync数据实时同步(双向)
Rsync+Sersync数据实时同步(双向) 服务介绍 一.为什么要用rsync+sersync架构? 1.sersync是基于inotify开发的,类似于inotify-tools的工具 2.se ...
- sersync实时同步实战
第1章 实时同步 1.1 什么是实时同步 实时同步是一种只要当前目录触发事件,就马上同步到远程的目录.rsync 1.2 为什么要实时同步web->nfs->backup 保证数据的连续性 ...
- Rsync+sersync文件实时同步
一.为什么要用Rsync+sersync架构1.sersync是基于Inotify开发的,类似于Inotify-tools的工具2.sersync可以记录下被监听目录中发生变化的(包括增加.删除.修改 ...
- RedHat Linux下利用sersync进行实时同步数据
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://linux5588.blog.51cto.com/65280/772054 拓扑图 ...
- sersync做实时同步(第二步)
配置文件一般都在sersync2的根目录下.为.xml文件 下面做逐行的进行解释说明: <host hostip="localhost" port="8008&qu ...
- sersync做实时同步(第一步)
两台主机,一台主服务器(192.168.0.109).一台目标服务器(192.168.0.212) 1.配置目标服务器(192.168.0.212);就是配置rsync服务器.在配置文件/etc/rs ...
随机推荐
- bzoj1025 [SCOI2009]游戏——因数DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1025 这篇博客写得真好呢:https://www.cnblogs.com/phile/p/4 ...
- yui压缩js文件
http://ganquan.info/yui/?hl=zh-CN yui压缩js文件 在工程中,js文件的管理是个麻烦事,并且随着项目越做越多,各种js文件混杂,有时候一个页面需要加载好多js文件, ...
- JAVA Synchronized (一)
<编程思想之多线程与多进程(1)——以操作系统的角度述说线程与进程>一文详细讲述了线程.进程的关系及在操作系统中的表现,这是多线程学习必须了解的基础.本文将接着讲一下Java线程同步中的一 ...
- ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 07. View的Model 和 Tag Helpers
student添加一个属性BirthDate 然后把生成数据的地方,字段也加上 建立ViewModel list转换为ViewModel 进一步改进代码 StudentViewModel HomeIn ...
- linux mplayer 播放yuv格式 (转载)
转自:http://blog.csdn.net/ly0303521/article/details/38713791 在mplayer中查看YUV格式的图片或视频,可使用如下命令: mplayer - ...
- hdoj5327【前缀和思想】
题意: 找给定区间的美丽数,美丽数的意思就是这个数每个位上的数都是唯一的. 思路: 前缀和的思想. 感想: 就是你当前位置代表某个特性的前面的所有和(瞎比比的,说了下感觉).前提是你必须找到这样的特性 ...
- PTA 螺旋方阵
所谓"螺旋方阵",是指对任意给定的NNN,将1到N×NN\times NN×N的数字从左上角第1个格子开始,按顺时针螺旋方向顺序填入N×NN\times NN×N的方阵里.本题要求 ...
- hdu1325 Is It A Tree? 基础并查集
#include <stdio.h> #include <string.h> ], g[]; int find(int x) //并查集的查找,找到共同的父亲 { if (f[ ...
- Contextual Action bar(3) 两个示例
一.通过activity启动Context Action Bar 1.主java public class ActivityActionModeFrgmt extends Fragment imple ...
- pwa-serviceWorker与页面通信postMessage
https://ppt.geekbang.org/list/gmtc2018?from=groupmessage&%3Bisappinstalled=0 http://www.sohu. ...