sersync实时同步
实时同步目的
1.解决单点故障
2.保证数据的统一性
sersync的依赖
1.rsync
2.inotify
# 例子
eusr/bin/inotifywait -mrq --format '%Xe %w %F' -e
create,modify,delete,attrib,close_write /backup
# 选项及例子含义
-m 持续监控
-r 递归
-q 静默
--timefmt 指定输出时间格式
--format 指定事件输出格式
%Xe 事件
%w 目录
%f 文件
-e 指定监控的事件
access 访问
modify 内容修改
attrib 属性修改
close_write 修改真实文件内容
open 打开
create 创建
delete 删除
umount 卸载
实时同步工具选择
sersync+RSYNC(√)
、inotify+rsync
Inotify
是一个通知接口,用来监控文件系统的各种变化,如果文件存取,删除,移动。可以非常方便地实现文件异动告警,增量备份,并针对目录或文件的变化及时作出响应。rsync
+inotify
可以实触发式实时同步增量备份sersync
是国人基于rsync
+inotify-tools
开发的工具,不仅保留了优点同时还强化了实时监控,文件过滤,简化配置等功能,帮助用户提高运行效率,节省时间和网络资源。sersync项目地址
环境准备
主机名 | 外网 | 内网 | 角色 |
---|---|---|---|
web01 | 10.0.0.7 | 172.16.1.7 | nfs客户端 |
web02 | 10.0.0.8 | 172.16.1.8 | nfs客户端 |
nfs | 10.0.0.31 | 172.16.1.31 | nfs服务端和rsync客户端 |
backup | 10.0.0.41 | 172.16.1.41 | rsync服务端 nfs服务端(备机) |
在nfs部署sersync
# 安装sersync的依赖
yum install -y inotify-tools
# 下载sersync的包
wget http://test.driverzeng.com/other/sersync2.5.4_64bit_binary_stable_final.tar.gz
# 创建安装目录
mkdir /application
# 解压到安装目录
tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /application/
# 改名
mv /application/GNU-Linux-x86/ /application/sersync
# 修改配置文件
vim /application/sersync/confxml.xml
## 将以下内容全改为true(全开)
<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>
rsync --delete /data rsync_backup@172.16.1.41::backup --passwd-file=/etc/rsyncd.pass
## 监控目录,推送数据的目录/data
<sersync>
<localpath watch="/data">
## rsync服务端的地址:172.16.1.41 和 模块名 backup
<remote ip="172.16.1.41" name="backup"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
## rsync命令执行时的选项
<rsync>
<commonParams params="-az --delete"/>
# 打开变为true 虚拟用户 指定密码文件
<auth start="true" users="rsync_backup" passwordfile="/etc/rsyncd.pass"/>
# 启动sersync
/application/sersync/sersync2 -rdo /application/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: -r rsync all the local files to the remote servers before the sersync work
option: -d run as a daemon
option: -o config xml name: /application/sersync/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
will ignore the inotify createFile event
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_backup
passwordfile is /etc/rsyncd.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 -az --delete -R --delete ./ rsync_backup@172.16.1.41::backup --password-file=/etc/rsyncd.pass >/dev/null 2>&1
run the sersync:
watch path is: /data
--------------------------------
# 参数
-d:启用守护进程模式
-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
-n: 指定开启守护线程的数量,默认为10个
-o:指定配置文件,默认使用confxml.xml文件
-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
-m:单独启用其他模块,使用 -m socket 开启socket模块
-m:单独启用其他模块,使用 -m http 开启http模块
不加-m参数,则默认执行同步程序