sersync2 文件的实时同步备份
|——需求:
监控192.168.9.5【主】 下的 /data/vmeipai 目录 --> 同步到 192.168.12.8 【备】 下的 /data/vmeipai 目录
|——网络拓扑:

|——准备软件
1,Rsync
2,Sersync
rsync可以从【wget http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz 】获取,不过我这里使用了【yum install rsync -y 】
sersync 详细:【https://code.google.com/p/sersync/】解压之后直接使用无需安装
3,查看本机系统环境:64位的机子我们就下载64的软件包

|——【备环境软件安装】
机器上已经安装过了

没有的话使用下面安装命令:
yum install rsync -y
—配置[备]上的【rsync】
安装好之后 更改 /etc/xinetd.d/rsync 文件 将disable 由【yes 改成 no ,双重否定即为肯定】

—然后创建 /etc/rsyncd.conf 文件 [说明:该文件原来是没有的,这里是新建]
vim /etc/rsyncd.conf
###############################################################
##以下是本机配置
###############################################################
uid = nobody
gid = nobody
use chroot = no
hosts allow = 192.168.9.0/255 #允许的ip
strict modes = yes
max connections = 200
###以下指定具体文件的地址也可以默认
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
#####以上为全局配置,下面为具体模块
[backup] ##模块名
path = /data/vmeipai/ ##指定文件目录,必须
comment = test
read only = no
write only = no
ignore errors = yes ## 忽略IO错误
list = yes
uid = root
gid = root
###以下是同步是验证用的账号,没有则是匿名同步
auth users = rsync
secrets file = /etc/rsync.passwd ##指定密码文件
—创建密码认证文件:[文件格式-> 用户名:密码]
1,
vim /etc/rsync.passwd
rsync:logonmy ##用户名:密码。这个不是系统用户,只是rsync使用认证,所以不需要创建系统用户useradd 【必须与auth users 保持一致】
2,
chmod 600 /etc/rsync.passwd ## [这一步必须]
3,
如果在配置文件中指定了欢迎信息,
vim /etc/rsync.motd
welcome the rsync services!
——开启iptables响应端口[ 不然【主】服务器推过来的文件都被挡在门外进不来了]
iptables -i INPUT -p tcp --dport 873 -j ACCEPT
iptables -L
结果如下
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:rsync
——启动rsync:
# service xinetd start
或者
/usr/bin/rsync --daemon
加入自启动:[很多时候加入自启动能减少很多排错时间]
echo "/usr/bin/rsync --daemon" >> /etc/rc.local
——检查运行情况:

|_______到这里 【备】服务器配置完成并生效
|———【主环境安装】
主环境需要 sersync+rsync
特别说明:主环境上 rsync 不需要配置 ,只要将rsync服务跑起来就可以. 不用配置同步模块等等,但是全局模块还是要指定一下.
——首先安装 sersync
1,解压到 /usr/local/ 下
tar -zxf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
2,重命名 为sersync
# mv GNU-Linux-x86 sersync 这样就好了 ,不需要安装解压就能用。
——配置sersync [配置要注意自己的实际情况]
主要的修改部分在这[改成备服务器上的rsync配置好的模块]
<sersync>
<localpath watch="/data/vmeipai">
<remote ip="192.168.12.8" name="backup"/>
</localpath>
</sersync>
意思是将 监控目录 【localpath watch】 /data/vmeipai 下的任何 增删改事件推到 备服务上的rsync [backup]模块
——尔后安装rsync 这里在备服务器上安装过了 配置的 话 省掉模块的配置即可
|——启动【主】上的sersync,最好写成服务,并且随机启动
首先看下帮助信息

1,
cd /usr/local/sersync
./sersync2 –d
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
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
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)
please according your cpu ,use -n param to adjust the cpu rate
run the sersync:
watch path is: /data/vmeipai
现在sersync已经开启
2,开启实时事件触发的同步,同步之前对【主服务器上的监控目录】做一次整体的同步动作
./sersync –r
3, 最后将同步进程做成守护进程 一直在后台运行 [做到目标目录的任何触发事件都被捕捉到并被推送]
./sersync –r –d
|——【进一步】 和rsync 写入自启动一样,将sersync 写成自启动服务
#cd /etc/init.d/
#vim sersyncd
#! /bin/bash
#chkconfig: 35 10 90
#description: 监控目标目录[事件触发]同步到备份机
#secript: /etc/init.d/sersyncd and chkconfig --level 35 sersyncd on
#with service rsync [echo "/usr/bin/rsync --daemon" >> /etc/rc.local]
#sersyncd
#
. /etc/rc.d/init.d/functions
case "$1" in
start)
cd /usr/local/sersync
./sersync2 -r -d
if [ $? -eq 0 ]
then
echo -e "Staring sersyncd [ OK ]"
exit 0
fi
;;
stop)
kill 'ps aux | grep sersync2 | grep -v grep | awk '{print $2}''
if [ $? -eq 0 ]
then
echo -e "Stopping sersyncd [ OK ]"
exit 0
fi
;;
status)
ps aux | grep sersync2 | grep -v grep
;;
esac
|____然后 执行 chkconfig --level 35 sersyncd on
这样整个过程就完整了。完成了我们实时同步的需求!
参考:
http://fenglingcorp.iteye.com/blog/1218401 服务器同步(sersync2 完全安装配置说明(一)----基本功能使用)
http://www.kankanews.com/ICkengine/archives/92550.shtml sersync2+rsync目录文件实时同步备份
http://blog.sina.com.cn/s/blog_5eda2dda01015fcs.html rsync安装、配置、实例
http://www.nginx.cn/tag/rsync rsync备份同步文件教程
sersync2 文件的实时同步备份的更多相关文章
- sersync + rsync 实现文件的实时同步
这里有一点要特别注意了,就是在你完成备份之后,先不要把本地的文件都给删除了,先把服务停了之后再删除文件, 因为你已删除,检查到两边不一致,他又会把备份端给删除了.所以特别得注意了.这里吃过一次亏. 还 ...
- CentOS 6.5 rsync+inotify实现数据实时同步备份
CentOS 6.5 rsync+inotify实现数据实时同步备份 rsync remote sync 远程同步,同步是把数据从缓冲区同步到磁盘上去的.数据在内存缓存区完成之后还没有写入到磁盘 ...
- rsync + inotify-tools实现文件的实时同步
文章摘自:http://lxw66.blog.51cto.com/5547576/1331048 rsync 帮助文档:http://man.linuxde.net/rsync 最近有个想法就是部署一 ...
- Rsync + sersync 实时同步备份
一 Rsync + Sersync 实时同步介绍 1.Rsync 服务搭建介绍 云机上搭建Rsync server,在本地搭建Rsync Clinet. 2. Sersync 服务搭建介绍 ...
- rsync 远程同步 实时同步备份 两种免交互的方式实现实时备份
rsync 远程同步: 一款快速增量备份工具 Remote Sync,远程同步 支持本地复制,或者与其他SSH.rsync主机同步 作用:做数据备份 备份方式: 完全备份 增量备份 ...
- rsync 与 inotify 的使用 & 实现实时同步备份
今日内容 rsync 内容详细 上一篇内容问题 1.yum源问题 2.VPN链接正常,但是没办法通过172 3.VPN链接时,出现了DNS错误 4.掩码不对 5.openvpn开启错误 复制的命令 1 ...
- CentOS 7.2 Ubuntu 18部署Rsync + Lsyncd服务实现文件实时同步/备份
发送端配置: 一.配置密钥 1. 主/从服务器之间启用基于密钥的身份验证.登录发送端服务器并用 " ssh-keygen " 命令生成公共或私有的密钥. 2. 使用 " ...
- Rsync + Lsyncd服务实现文件实时同步/备份
1.接受端安装rsync yum -y install rsync 2.配置同步模块 vim /etc/rsyncd.conf # any name you like [backup] # desti ...
- CentOS 7.2 部署Rsync + Lsyncd服务实现文件实时同步/备份 (三)
配置过程中遇到的错误与查看日志 以下错误是在服务正常开启的情况下发生的,请先查看服务是否正常启动. 一.错误 1. rsync: failed to set times on "." ...
随机推荐
- LeetCode——Arithmetic Slices
Question A sequence of number is called arithmetic if it consists of at least three elements and if ...
- Win10 initluictrl failed问题
问题描述 启动win10之后,所有的软件.快捷方式无法访问,双击之后没有响应但联网正常. 解决方法 win键+S弹出选项框,选择cmd(管理员). 键入命令:netsh winsock reset c ...
- 经典C#面试题
1.在下面的代码中,如何引用命名空间fabulous中的great? namespace fabulous{// code in fabulous namespace}namespace super{ ...
- Qwt中鼠标获取坐标点
void getPoint(QwtPlot *plot) { QPoint point = plot->canvas()->mapFromGlobal(QCursor::pos()); Q ...
- [Eclipse]保存java文件时,自动删除不需要的包import
1.修改设定:Window->Preferences 2.效果: =>
- 使用IDEA创建SpringBoot自定义注解
创建SpringBoot项目 添加组织名 选择web 输入项目名称 创建后目录结构为 使用Spring的AOP先加入Maven依赖 <dependency> <groupId> ...
- 玲珑oj 1129 ST
1129 - 喵哈哈村的战斗魔法师丶坏坏い月 Time Limit:3s Memory Limit:256MByte Submissions:490Solved:107 DESCRIPTION 坏坏い ...
- Qt5全局热键-QxtGlobalShortcut
最近做一个项目需要注册全局热键,在网上搜索发现有个第三方库 libqxt 中给出一个比较好的跨平台的解决方案,就是 QxtGlobalShortcut. 但是编译过程中发现这个库用到的QAbstrac ...
- 我要复习python啦(一)
一.变量 那些曾经怎么也看不懂的东西,突然有一天就懂了.这就是复习的力量吗? 1 变量的赋值 a = 10 做了上面的图所描述的事情 1)开辟一块内存,创建一个值为10的整数 2)创建一个a的标记 3 ...
- 028——VUE中事件修饰符once
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...