Sersync实时同步

1.实时同步概述
2.实时同步案例
3.实时同步扩展

本章课程大纲

1.什么是实时同步?
2.实时同步的原理
3.实时同步的场景
4.实时同步的工具的选择
5.实时同步的案例演示

1.实时同步的概述

1.什么是实时同步
只要当前目录发生变化则会出发一个事件,事件触发后将变化的目录同步至远程服务器。
2.实时同步的原理
实时同步需要借助inotify通知接口,用来监控本地目录的变化,如果监控本地的目录发生变化,则会触发动作,这个动作可以是进行同步操作,或其他操作。
3.实时同步场景
场景1、解决NFS单点故障、保证同步的数据连续性
场景2、本地无缝迁移云端
4.实时同步工具的选择
sersync(√)、inotify+rsync,通常我们会选择sersync,因为sersync是国人基于rsync+inotify基础之上开发的工具,不仅保留了其优点同时还强化了实时监控,文件过滤,简化配置等功能,帮助用户提高运行效率,sersync项目地址

2.实时同步案例

案例:实现web上传视频文件,实则是写入NFS至存储,当NFS存在新的数据则会实时复制到备份服务器

5.搭建web节点(使用了解)10.0.0.7服务器 对外提供80访问的端口
(1)安装httpd服务
[root@web ~]# yum -y install httpd php
(2)启动
[root@web ~]# systemctl start httpd
(3)页面/var/www/html的这个目录是空的则页面显示这样
[root@web ~]# ll /var/www/html/
total 0

(4)切换到/var/www/html目录上传代码到/var/www/html目录上

[root@web ~]# cd /var/www/html/
[root@web html]# rz 上传到目录中
[root@web html]# ls
kaoshi-download.zip
[root@web html]# unzip kaoshi-download.zip
Archive: kaoshi-download.zip
inflating: upload_file.php
inflating: info.php
inflating: bg.jpg
inflating: index.html
[root@web html]# ls
bg.jpg index.html info.php kaoshi-download.zip upload_file.php
[root@web html]# systemctl restart httpd 上传代码解压并重启一下服务

(5)显示上传成功但是在目录/var/www/html目录查看没有上传的文件
[root@web html]# ll
total 80
-rw-r–r–. 1 root root 38772 Apr 27 2018 bg.jpg
-rw-r–r–. 1 root root 2633 May 4 2018 index.html
-rw-r–r–. 1 root root 52 May 10 2018 info.php
-rw-r–r–. 1 root root 26921 Oct 20 2020 kaoshi-download.zip
-rw-r–r–. 1 root root 1114 Oct 20 2020 upload_file.php
查看日志定位问题
[root@web html]# tail -f /var/log/httpd/error_log
[Wed Apr 13 00:00:27.823706 2022] [core:notice] [pid 1803] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Wed Apr 13 00:00:27.825342 2022] [suexec:notice] [pid 1803] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using fe80::20c:29ff:feeb:f041. Set the ‘ServerName’ directive globally to suppress this message
[Wed Apr 13 00:00:28.041570 2022] [lbmethod_heartbeat:notice] [pid 1803] AH02282: No slotmem from mod_heartmonitor
[Wed Apr 13 00:00:28.049176 2022] [mpm_prefork:notice] [pid 1803] AH00163: Apache/2.4.6 (CentOS) PHP/5.4.16 configured – resuming normal operations
[Wed Apr 13 00:00:28.049224 2022] [core:notice] [pid 1803] AH00094: Command line: ‘/usr/sbin/httpd -D FOREGROUND’
[Wed Apr 13 00:03:42.572387 2022] [:error] [pid 1805] [client 10.0.0.1:63046] PHP Notice: Use of undefined constant download - assumed ‘download’ in /var/www/html/upload_file.php on line 8, referer: http://10.0.0.7/
[Wed Apr 13 00:03:42.572530 2022] [:error] [pid 1805] [client 10.0.0.1:63046] PHP Warning: mkdir(): Permission denied in /var/www/html/upload_file.php on line 15, referer: http://10.0.0.7/
[Wed Apr 13 00:03:42.572574 2022] [:error] [pid 1805] [client 10.0.0.1:63046] PHP Warning: move_uploaded_file(download/1_zhx.txt.txt): failed to open stream: No such file or directory in /var/www/html/upload_file.php on line 45, referer: http://10.0.0.7/
[Wed Apr 13 00:03:42.572582 2022] [:error] [pid 1805] [client 10.0.0.1:63046] PHP Warning: move_uploaded_file(): Unable to move ‘/tmp/phpea8zIh’ to ‘download/1_zhx.txt.txt’ in /var/www/html/upload_file.php on line 45, referer: http://10.0.0.7/
(6)查看服务的进程是啥用户在查看目录是什么用户在运行权限

(7)修改httpd服务进程配置用户身份为www用户
[root@web html]# sed -i ‘/^User/c User www’ /etc/httpd/conf/httpd.conf
[root@web html]# sed -i ‘/^Group/c Group www’ /etc/httpd/conf/httpd.conf
[root@web html]# egrep “User|Group” /etc/httpd/conf/httpd.conf
#User/Group: The name (or #number) of the user/group to run httpd as.
User www
Group www
LogFormat “%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”” combined
LogFormat “%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i” %I %O” combinedio
(8)创建www用户
[root@web html]# groupadd -g666 www
[root@web html]# useradd -u666 -g666 www
[root@web html]# id www
uid=666(www) gid=666(www) groups=666(www)
(9)修该对应的目录权限/var/www/html为www用户
[root@web html]# chown -R www.www /var/www/html/
[root@web html]# ll -d /var/www/html/
drwxr-xr-x. 2 www www 104 Apr 12 23:56 /var/www/html/
(10)此时查看长传成功
[root@web html]# ll
total 80
-rw-r–r–. 1 www www 38772 Apr 27 2018 bg.jpg
drwxr-xr-x. 2 www www 27 Apr 13 00:26 download
-rw-r–r–. 1 www www 2633 May 4 2018 index.html
-rw-r–r–. 1 www www 52 May 10 2018 info.php
-rw-r–r–. 1 www www 26921 Oct 20 2020 kaoshi-download.zip
-rw-r–r–. 1 www www 1114 Oct 20 2020 upload_file.php
[root@web html]# ll download/
total 4
-rw-r–r–. 1 www www 23 Apr 13 00:26 1_zhx.txt.txt
6.搭建NFS节点 服务器10.0.0.31
(1)安装NFS服务
[root@nfs ~]# yum install nfs-untils -y
(2)修改配置
[root@nfs ~]# cat /etc/exports
/data 172.16.1.0/24(rw,async,all_squash,anonuid=666,anongid=666)
创建/data目录
[root@nfs ~]# mkdir /data
修改/data目录属主、属组的用户身份为www用户
[root@nfs ~]# chown -R www.www /data/
[root@nfs ~]#useradd -u666 -g666 www
[root@nfs ~]#groupadd -g666 www
(3)重启
[root@nfs ~]#systemctl restart nfs
7.web节点上传的资源(写入到NFS共享中)
(1)在web服务器挂载操作
[root@web download]# mount -t nfs 172.16.1.31:/data /var/www/html/download/
(2)在nfs服务器查看/data目录
[root@nfs ~]# ll /data/
total 4
-rw-r–r–. 1 www www 23 Apr 12 23:40 1_zhx.txt.txt
8.配置Backup服务器172.16.1.41
(1)(增加一个data模块,让其安装NFS服务器,与31完全保持一致)
1.安装配置Rsync服务器
[root@backup ~]# yum -y install rsync
2.配置Rsync服务器
[root@backup ~]# cat /etc/rsyncd.conf
uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
[backup]
comment = welcome to backup server
path = /backup

[data]
path = /data
3.初始化操作
[root@backup ~]#groupadd -g666 www
[root@backup ~]# useradd -u666 -g666 www
[root@backup ~]# mkdir /data
[root@backup ~]# chown -R www.www /data/ /backup/启动你·
4.准备连接用户的密码文件:
[root@backup ~]# cat /etc/rsync.passwd
rsync_backup:1
[root@backup ~]# chmod 600 /etc/rsync.passwd
5.重启服务
[root@backup ~]# systemctl restart rsyncd
6.配置NFS
[root@backup ~]# yum -y install nfs-utils
[root@backup ~]# cat /etc/exports
/data 172.16.1.0/24(rw,async,all_squash,anonuid=666,anongid=666)
7.启动NFS
[root@backup ~]# systemctl enable nfs
[root@backup ~]# systemctl start nfs
(2)在NFS服务端上安装Sersync实时同步工具 (监控data目录)
1.安装命令
[root@nfs ~]# yum -y install inotify-tools rsync
2.上传软件包并解压软件包和移动到目录/
[root@nfs ~]# rz sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs ~]# ls
anaconda-ks.cfg sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs ~]# ls
anaconda-ks.cfg GNU-Linux-x86 sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs ~]# mv GNU-Linux-x86/ /usr/local/sersync
3.配置Sersync

[root@nfs ~]# file /usr/local/sersync/confxml.xml -------------这是二进制的文件
/usr/local/sersync/confxml.xml: XML 1.0 document, ASCII text
(1)我们要监控的目录
(2)被监控的目录如果有如下事件发生,就会触发动作
(3) 同步到172.16.1.41的data模块 rsync
(4)使用什么选项 -avz
(5)使用什么连接用户
rsync_backup
(6)使用的密码是什么 存储在文件中 /etc/rsync.pass
echo “1” /ect/rsync.pass
chmod 600 /etc/rsync.pass

[root@nfs ~]# 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="true"/><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="true"/><closeWrite start="true"/><moveFrom start="true"/><moveTo start="true"/><attrib start="true"/><modify start="true"/></inotify><sersync><localpath watch="/data"><remote ip="172.16.1.41" name="data"/>    </localpath><rsync><commonParams params="-avz"/><auth start="true" users="rsync_backup" passwordfile="/etc/rsync.pass"/><userDefinedPort start="false" port="874"/><!-- port=874 --><timeout start="true" 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>

[root@nfs ~]# /usr/local/sersync/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参数,则默认执行同步程序


4.启动sersync命令
[root@nfs ~]# /usr/local/sersync/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
will ignore the inotify createFile event
WARNING XFS FILE SYSTEM WORK
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_backup
passwordfile is /etc/rsync.pass
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 && rsync -avz -R --delete ./ --timeout=100 rsync_backup@172.16.1.41::data --password-file=/etc/rsync.pass >/dev/null 2>&1
run the sersync:
watch path is: /data
5.sersync启动与停止:没有提供任何脚本:systemctl
停止:[root@nfs ~]# kill $(ps -ef |grep sersync|grep -v grep |awk ‘{print $2}’)
启动:/usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml

6.模拟NFS故障切换 :[root@nfs ~]# systemctl stop nfs

web服务器操作:强制卸载并挂载172.16.1.41服务器
[root@web ~]# umount -lf /var/www/html/download && mount -t nfs 172.16.1.41:/data /var/www/html/download

3.基于sersync海量文件实时同步

Sersync实时同步相关推荐

  1. rsync+sersync实时同步数据

    前言 rsync+sersync实时同步数据. 简介 rsync+sersync实时同步数据的原理是在客户端安装sersync监控目录的变化,一般是增删改,检测到变化以后,将变化的文件同步到服务端. ...

  2. Rsync+Inotify+Sersync实时同步服务

    目录 实时同步服务原理 实时同步服务部署 部署rsync守护进程 部署inotify监控服务 下载安装软件 熟悉命令使用 inotify企业应用 部署sersync同步服务 下载安装软件 编写配置文件 ...

  3. Sersync 实时同步

    Sersync 实时同步 实时同步概述 什么是实时同步 实时同步是一种只要当前目录发生变化则会触发一个事件,事件触发后会将变化的目录同步至远程服务器. 为什么要实时同步 保证数据的连续性, 减少人力维 ...

  4. Rsync+Sersync实时同步详细配置

    Rsync+Sersync实时同步 一.基本介绍  1.什么是Rsync? Rsync(Remote Synchronize)是一款开源的.快速的.多功能的.可以实现全量及增量的本地或远程数据同步备份 ...

  5. sersync实时同步 sersync项目实战 nfs单点故障解决

    文章目录 sersync实时同步 什么是实时同步 为什么实时同步 实现同步的原理 实时同步工具的选择 sersync项目实战 1.环境准备 安装web服务器(web01和web02两台机器上全需要执行 ...

  6. sersync实时同步 解决单点NFS单点故障问题

    一般中型公司的页面访问量 pv (页面浏览量) 6千万 uv (独立用户浏览量) 2千 QPS (每秒查询率) 10-20 实时同步 rsync + inotify : 适用于文件比较少的情况 ser ...

  7. 20170710L07-09-03老男孩Linux运维实战培训-Sersync实时同步软件实战应用指南07

    接上一节的sersync压力测试 这一节主要是对着上一节的压力测试文本做真实的压力测试 测试出到底sersync的压力极限是多少 从每秒10个到100个 # tree |wc -l  #查看写了多少文 ...

  8. sersync进行实时同步数据

    上面是网络 可以有多个目标服务器,本机同步也可以(要同时开sersync服务和rsync守护进程) 需求: 1.源服务器上 要备份的是  /opt/tongbu1/ /opt/tongbu2/目录包括 ...

  9. sersync+rsync实现实时同步

    在分布式应用中会遇到一个问题,就是多个服务器间的文件如何能始终保持一致.一种经典的办法是将需要保持一致的文件存储在NFS上,这种方法虽然简单方便但却将本来多点的应用在文件存储上又变成了单点,这违背了分 ...

最新文章

  1. anndroid ndk使用
  2. Python教程:zip 函数的用法
  3. 深入学习Mybatis框架(二)- 进阶
  4. 【OJ】洛谷红题题解锦集(Java语言描述)
  5. Ubuntu 命令大全
  6. Gtk的entry传递数据到内部程序
  7. nginx安装与项目发布
  8. HDU5688 Problem D【字符串排序+MAP】
  9. ctrl z撤销后如何恢复_偏瘫后如何恢复?偏瘫家庭功能锻炼方法送给你
  10. 手工删除oracle的方法
  11. 云原生生态周报 Vol. 3 | Java 8 ❤️ Docker
  12. 深入浅出SpringSecurity
  13. markdown生成目录
  14. js 数字转为罗马数字(互转换),I 、II 、 III 、IV、V
  15. Android 省电模式 降频吗,开启省电模式会降频吗
  16. 抽象类 模板设计模式
  17. (六)JAVA设计模式23种设计模式之适配器模式实例demo
  18. 无线点菜宝服务器,餐饮业电子产品无线点菜宝
  19. 【DSA】树-哈弗曼树详解(3)
  20. 如何打造主题公园夜游经济

热门文章

  1. [益智]:谁打碎了花瓶
  2. 44. python的for循环嵌套
  3. tyvj 1023 奶牛的锻炼
  4. 如何使用USER.DB找回丢失QQ中的好友?
  5. 关于Android模块化开发介绍及使用
  6. 烧烫伤急救,跟我冲冲鸭!
  7. 亚信联创公用研发中心WAP2.0手机客户端软件开发
  8. 对信念的理解正确的是_信念-伴随着你的向阳花
  9. 互联网金融银行卡身份证识别
  10. 跨链(cross-chain)与多链(multi-chain),谁才是未来?