sersync 介绍

sersync类似于inotify,同样用于监控,但它克服了inotify的缺点.

inotify最大的不足是会产生重复事件,或者同一个目录下多个文件的操作会产生多个事件,例如,当监
控目录中有5个文件时,删除目录时会产生6个监控事件,从而导致重复调用rsync命令。另外比如:vim
文件时,inotify会监控到临时文件的事件,但这些事件相对于rsync来说是不应该被监控的

sersync 优点:

sersync是使用c++编写,而且对linux系统文件系统产生的临时文件和重复的文件操作进行过滤,
所以在结合rsync同步的时候,节省了运行时耗和网络资源。因此更快。
sersync配置很简单,其中提供了静态编译好的二进制文件和xml配置文件,直接使用即可
sersync使用多线程进行同步,尤其在同步较大文件时,能够保证多个服务器实时保持同步状态
sersync有出错处理机制,通过失败队列对出错的文件重新同步,如果仍旧失败,则按设定时长对
同步失败的文件重新同步
sersync不仅可以实现实时同步,另外还自带crontab功能,只需在xml配置文件中开启,即也可以
按要求隔一段时间整体同步一次,而无需再额外配置crontab功能
sersync 可以二次开发

sersync项目地址: https://code.google.com/archive/p/sersync/
sersync下载地址:https://code.google.com/archive/p/sersync/downloads

案例:基于rsync daemon 实现 sersync

#在数据服务器上下载sersync,并拷贝至相应的目录,设置PATH变量
[root@sz-kx-centos8 ~]# wget https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz# 解压
[root@sz-kx-centos8 ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@sz-kx-centos8 ~]# cp -a GNU-Linux-x86 /usr/local/sersync[root@sz-kx-centos8 ~]# echo 'PATH=/usr/local/sersync:$PATH' > /etc/profile.d/sersync.sh
[root@sz-kx-centos8 ~]# source /etc/profile.d/sersync.sh[root@sz-kx-centos8 ~]# ll /usr/local/sersync/
total 1772
-rwxr-xr-x 1 root root    2214 Oct 26  2011 confxml.xml
-rwxr-xr-x 1 root root 1810128 Oct 26  2011 sersync2#确认安装rsync客户端工具
[root@sz-kx-centos8 ~]# rpm -q rsync &> /dev/null || dnf -y install rsync#备份sersync配置文件
[root@sz-kx-centos8 ~]# cp /usr/local/sersync/confxml.xml{,.bak}#修改sersync配置文件
[20:47:13 root@sz-kx-centos8 ~]# cat /usr/local/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="true"/>   #修改此行为true,文件属性变化后也会同步<modify start="false"/></inotify><sersync><localpath watch="/data/www">  #修改此行,需要同步的源目录或文件,建议同步目录<remote ip="备份服务器IP" name="backup"/>  #修改此行,指定备份服务器地址和rsync daemon的模块名,如果下面开启了ssh start,此时name为远程shell方式运行时的目标目录<!--<remote ip="192.168.8.39" name="tongbu"/>--><!--<remote ip="192.168.8.40" name="tongbu"/>--></localpath><rsync><commonParams params="-artuz"/><auth start="true" users="rsyncuser" passwordfile="/etc/rsync.pas"/>  #修
改此行为true,指定备份服务器的rsync配置的用户和密码文件<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="/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>#创建连接rsynd服务器的用户密码文件,并必须修改权限
[root@sz-kx-centos8 ~]# echo centos > /etc/rsync.pas
[root@sz-kx-centos8 ~]# chmod 600 /etc/rsync.pas#查看帮助
[root@sz-kx-centos8 ~]# sersync2 -h
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
_______________________________________________________
参数-d:启用守护进程模式
参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
c参数-n: 指定开启守护线程的数量,默认为10个
参数-o:指定配置文件,默认使用当前工作目录下的confxml.xml文件
参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
参数-m:单独启用其他模块,使用 -m socket 开启socket模块
参数-m:单独启用其他模块,使用 -m http 开启http模块
不加-m参数,则默认执行同步程序
_______________________________________________________
#以后台方式执行同步
[root@sz-kx-centos8 ~]# sersync2 -dro /usr/local/sersync/confxml.xml#如果同步失败,可以手动执行下面命令,观察过程
[root@sz-kx-centos8 ~]# cd /data/www && rsync -artuz -R --delete ./ rsyncuser@backup-server::backup --password-file=/etc/rsync.pas >/dev/null 2>&1
run the sersync:
watch path is: /data/www#sersync支持多实例,也即监控多个目录时,只需分别配置不同配置文件,然后使用sersync2指定对应配置
文件运行
[root@sz-kx-centos8 ~]# sersync2 -rd -o /etc/sersync.d/nginx.xml

基于远程shell 实现 sersync

#不需要配置rsync daemon,只需要配置基于key验证的ssh即可
[root@sz-kx-centos8 ~]# ssh-keygen
[root@sz-kx-centos8 ~]# ssh-copy-id backup-server
#下载sersync,并拷贝至相应的目录,设置PATH变量同5.5.2
#修改sersync配置文件
[root@sz-kx-centos8 ~]# cat /usr/local/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="true"/> #修改此行为true<modify start="false"/></inotify><sersync><localpath watch="/data/www"> #修改此行,指定源数据目录<remote ip="备份服务器IP" name="/data/backup"/> #修改此行指定备份服务器地址和备份目标目录<!--<remote ip="192.168.8.39" name="tongbu"/>--><!--<remote ip="192.168.8.40" name="tongbu"/>--></localpath><rsync><commonParams params="-artuz"/><auth start="false" users="root" passwordfile="/etc/rsync.pas"/> #必须修改 此行,不启用认证start=false<userDefinedPort start="false" port="874"/><!-- port=874 --><timeout start="false" time="100"/><!-- timeout=100 --><ssh start="true"/> #修改此行为true,使用远程shell方式的rsync连接方式,无需在目标
主机上配置启动rsync daemon服务
#####################################以下行不需要修改
####################################</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>
#将中间的行可以删除
</head>[root@sz-kx-centos8 ~]# sersync2 -dro /usr/local/sersync/confxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches

案例 基于LAMP搭建web服务数据同步

# 安装mysql做主从复制
[root@centos8 ~]# yum install mysql-server -y
[root@centos8 ~]# yum install mysql-server -y开机启动mysql
[root@centos8 ~]# systemctl enable --now mysqld
[root@centos8 ~]# systemctl enable --now mysqld配置主从
#主配置
[root@centos8 ~]# vim /etc/my.cnf
[mysqld]
server-id=28
log-bin=/data/mysql/mysql-bin#创建目录并授权
[root@centos8 ~]# mkdir /data/mysql/ -p
[root@centos8 ~]# chown -R mysql.mysql /data/mysql# 重新启动mysql服务
[root@centos8 ~]# systemctl restart mysqld#从配置[mysqld]
server_id=38
log-bin=/data/mysql/mysql-bin
read_only#创建目录并授权
[root@centos8 ~]# mkdir /data/mysql/ -p
[root@centos8 ~]# chown -R mysql.mysql /data/mysql/# 重新启动mysql服务
[root@centos8 ~]# systemctl restart mysqld主进入数据库创建库并创建用户还有授权
mysql> create database db1;
Query OK, 1 row affected (0.00 sec)mysql> use db1;
Database changed
mysql> show master logs;
+------------------+-----------+-----------+
| Log_name         | File_size | Encrypted |
+------------------+-----------+-----------+
| mysql-bin.000002 |       156 | No        |
+------------------+-----------+-----------+
1 row in set (0.00 sec)# 创建主从同步用户
mysql> create  user repluser@'172.31.0.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)mysql> grant replication slave on *.* to repluser@'172.31.0.%';
Query OK, 0 rows affected (0.00 sec)从配置
使用帮助
mysql> help change master to;mysql> CHANGE MASTER TOMASTER_HOST='172.31.0.28',MASTER_USER='repluser',MASTER_PASSWORD='123456',MASTER_PORT=3306,MASTER_LOG_FILE='mysql-bin.000002',MASTER_LOG_POS=156;mysql> start slave;
Query OK, 0 rows affected (0.00 sec)mysql> show slave status\G
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 172.31.0.28Master_User: repluserMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000002Read_Master_Log_Pos: 1064Relay_Log_File: centos8-relay-bin.000002Relay_Log_Pos: 1232Relay_Master_Log_File: mysql-bin.000002Slave_IO_Running: YesSlave_SQL_Running: Yes# 创建WordPress库
mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)# 创建WordPress用户
mysql> create user wordpress@'172.31.0.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)# 授权
mysql> grant all on wordpress.* to wordpress@'172.31.0.%';
Query OK, 0 rows affected (0.00 sec)创建目录NFS做数据同步
[root@sz-kx-centos8 ~]# mkdir /data/wordpress -p
[root@sz-kx-centos8 ~]# chmod 777 /data/wordpress/
[root@sz-kx-centos8 ~]# vim /etc/exports
/data/wordpress 172.31.0.0/16(rw)# 安装NFS
[root@centos8 ~]# yum install -y nfs-utils
[root@centos8 ~]# yum install -y nfs-utils
# 开机启动
[root@sz-kx-centos8 ~]# systemctl enable --now nfs-server.service
[root@sz-kx-centos8 ~]# systemctl enable --now nfs-server.service# 重读配置
[root@sz-kx-centos8 ~]# exportfs -r# 查看本机所有NFS共享
[root@sz-kx-centos8 ~]# exportfs -v
/data/wordpress172.31.0.0/16(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)##安装web
[root@CentOS8 ~]# yum install httpd php-fpm php-json php-mysqlnd nfs-utils -y
[root@CentOS8 ~]# yum install httpd php-fpm php-json php-mysqlnd nfs-utils -y# 开机启动
[root@localhost ~]# systemctl enable --now httpd php-fpm
[root@localhost ~]# systemctl enable --now httpd php-fpm# 挂载
[root@localhost ~]# vim /etc/fstab
172.31.0.18:/data/wordpress/wp-content/uploads       /var/www/html/wp-content/uploads    nfs  _netdev 0 0[root@localhost ~]# vim /etc/fstab
172.31.0.18:/data/wordpress/wp-content/uploads       /var/www/html/wp-content/uploads    nfs  _netdev 0 0# 创建目录
[root@localhost ~]# mkdir /var/www/html/wp-content/uploads -p
[root@localhost ~]# mkdir /var/www/html/wp-content/uploads -p
[root@localhost ~]# mount -a
[root@localhost ~]# mount -a# 查看能不能看远程主机的共享
[root@localhost ~]# showmount -e 172.31.0.18
Export list for 172.31.0.18:
/data/wordpress 172.31.0.0/16# 授权改所属用户(在挂载的nfs主机改)
[root@sz-kx-centos8 /data/wordpress]# chown -R apache.apache /data/wordpress/*数据同步(需要手动执行同步数据,很是不方便,所以使用以下的方法解决手动执行同步数据问题)
# master机安装软件包
[root@sz-kx-centos8 ~]# yum -y install inotify-tools# back机安装
[root@localhost ~]# yum install -y rsync rsync-daemon# back机操作
[root@localhost ~]# rsync --daemon
[root@localhost ~]# ss -tanlp
State         Recv-Q         Send-Q                  Local Address:Port                    Peer Address:Port
LISTEN        0              128                           0.0.0.0:873                          0.0.0.0:* # back机操作
[root@localhost ~]# vim /etc/rsyncd.conf
[backup]
path = /data/wordpress/
read only = no# 测试master机操作
[root@sz-kx-centos8 ~]# rsync rsync://172.31.0.58
backup# 在master机器手动执行同步
[root@sz-kx-centos8 ~]# echo "centos" > /etc/rsync.pas
[root@sz-kx-centos8 ~]# chmod 600 /etc/rsync.pas先把数据手工推送到back机器
[root@sz-kx-centos8 ~]# rsync /data/wordpress/ rsync://172.31.0.58::backup[root@sz-kx-centos8 ~]# rsync -avz --delete --password-file=/etc/rsync.pas /data/wordpress rsyncuser@172.31.0.18::backup推荐使用这个方式同步数据
sersync 实现实时数据同步
[root@sz-kx-centos8 ~]# wget https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz改配置文件按照上面的改即可# 以后台方式执行同步
[root@sz-kx-centos8 ~]# sersync2 -dro /usr/local/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:  /usr/local/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 rsyncuser
passwordfile is     /etc/rsync.pas
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 /data/wordpress && rsync -artuz -R --delete ./ rsyncuser@172.31.0.58::backup --password-file=/etc/rsync.pas >/dev/null 2>&1
run the sersync:
watch path is: /data/wordpress# 如果同步失败,可以手动执行下面命令,观察过程
[root@sz-kx-centos8 ~]# cd /data/wordpress && rsync -artuz -R --delete ./ rsyncuser@172.31.0.58::backup --password-file=/etc/rsync.pas >/dev/null 2>&1

浏览器同步数据(也可以改成域名解析ip访问)

遇到报错

[root@sz-kx-centos8 ~]# rsync rsync://172.31.0.58
rsync: failed to connect to 172.31.0.58 (172.31.0.58): No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(127) [Receiver=3.1.3]解决方法:使用[root@sz-kx-centos8 ~]# telnet 172.31.0.58 873
看通不通,如果不通可能是防火墙没有关闭,关闭即可重新同步

sersync 实现实时数据同步相关推荐

  1. 金山逍遥网 sersync 服务器实时镜像同步方案

    金山逍遥网 sersync 服务器实时镜像同步方案 1. sersync+rsync原理 2.inotify和sersync同步的区别 3. 配置sersync+rsync实现实时同步 2台cento ...

  2. ubuntun系统mysql数据库同步_Canal 实现 Mysql数据库实时数据同步

    简介 1.1 canal介绍 ​ Canal是一个基于MySQL二进制日志的高性能数据同步系统.Canal广泛用于阿里巴巴集团(包括https://www.taobao.com),以提供可靠的低延迟增 ...

  3. ​inotify+rsync实时数据同步实践讲解17

    inotify+rsync实时数据同步实践讲解17说明:本文来自来自北京老男孩linux运维实战培训中心-运维就业课程免费视频内容,本文内容为系列内容,更多分享信息见:http://oldboy.bl ...

  4. 使用MRS CDL实现实时数据同步的极致性能

    摘要:MRS CDL旨在实现最大的数据复制吞吐量和低复制延迟. 本文分享自华为云社区<使用MRS CDL实现实时数据同步的极致性能>,作者:大数据修行者 . MRS CDL提供从多个RDB ...

  5. 基于数据库数据增量同步_基于 Flink SQL CDC 的实时数据同步方案

    简介:Flink 1.11 引入了 Flink SQL CDC,CDC 能给我们数据和业务间能带来什么变化?本文由 Apache Flink PMC,阿里巴巴技术专家伍翀 (云邪)分享,内容将从传统的 ...

  6. Canal 实现 Mysql数据库实时数据同步

    简介 1.1 canal介绍 Canal是一个基于MySQL二进制日志的高性能数据同步系统.Canal广泛用于阿里巴巴集团(包括https://www.taobao.com),以提供可靠的低延迟增量数 ...

  7. 基于debezium实时数据同步(Oracle为主)

    基于debezium实时数据同步 全部需要下载的内容链接 1.下载zookeeper-3.4.10 2.下载kafka_2.13-2.8.0 3.下载Kafka Connector:建议使用1.6以上 ...

  8. 数仓实时数据同步 debezium

    数仓实时数据同步 debezium 背景 debezium 简介 架构 基本概念 例子 Router 目前遇到的问题 背景 数据湖将源库的数据同步到hive数仓ods层,或直接在kafka中用于后面计 ...

  9. MySQL 到 MongoDB 实时数据同步实操分享

    MySQL数据怎么实时同步到 MongoDB 实践分享系列 摘要:很多 DBA 同学经常会遇到要从一个数据库实时同步到另一个数据库的问题,同构数据还相对容易,遇上异构数据.表多.数据量大等情况就难以同 ...

最新文章

  1. 解决Tomact启动时问题 Port 8080 required by Tomcat v8.0 Server at localhost is already in use.
  2. The 2014 ACM-ICPC BeiJing D - Dire Wolf HDU - 5115 区间dp
  3. C语言第三次博客作业---单层循环结构
  4. Spring Boot静态资源映射规则
  5. STM32 RCC时钟配置
  6. highcharts绘制统计图的应用
  7. SitePoint Podcast#165:您说的是缓存,我说的是Caché
  8. TextView属性总结,简单的控件也可以很复杂
  9. 全自动高清录播服务器,高清高清录播服务器 高清全自动录播系统 方便携带 搭建快捷...
  10. git回退版本 简单易懂
  11. [目标检测]论文翻译代码理解-SCRDet: Towards More Robust Detection for Small, Cluttered and Rotated Objects
  12. w7计算机休眠网络就断了,设置Win7电脑休眠时不断开WiFi教程
  13. yarn unlink 简单使用
  14. STM32 keil5 报错:flash download failed-cortex M3解决方法
  15. 【低功耗蓝牙BLE】连接事件和相关参数
  16. ROS-3DSLAM(十六)lvi-sam项目总结
  17. 开源代码基于深度学习的超分辨率如何让大脑显微镜成像去除毛刺
  18. 服务器导入导出文件,Excel Server Tutorial
  19. 如何从海量特征中选取用户的关键画像特征?
  20. 2K20安卓修改器服务器到期,nba2k20手机版修改器

热门文章

  1. 用定时器实现页面跳转
  2. 亚马逊美国站fbm是什么意思?亚马逊美国站店铺fbm如何发货?
  3. springboot如何创建bean
  4. √[ (11^4+100^4+111^4)÷2]的开根号算法
  5. (六)Java关于内置工具类
  6. Gin使用GORM进行CURD
  7. Scipy.Optimize
  8. 如何用PPT实现属于自己的第一架四轴无人机~
  9. 4月从零学习C语言(第27天)——位运算
  10. 【转载】常用数据增强方法总结及实现