设为首页 加入收藏

TOP

Sersync+Rsync实现触发式文件同步(一)
2017-10-13 10:36:46 】 浏览:9354
Tags:Sersync Rsync 实现 发式 文件 同步

背景

  通常我们在服务器上使用rsync加上crontab来定时地完成一些同步、备份文件的任务。随着业务和应用需求的不断扩大、实时性要求越来越高。一般rsync是通过校验所有文件后,进行差量同步,如果文件量十分庞大,那么rsync进行校验的过程也是十分耗时的。而且正在发生变化的往往是其中很少的一部分,这是非常低效的方式。其次,rsync不能实时的去监测、同步数据,虽然它可以通过crontab方式进行触 发同步,但是两次触发动作一定会有时间差,这样就导致了服务端和客户端数据可能出现不一致,无法在应用故障时完全的恢复数据。而Sersync+Rsync的组合能够较好地解决这种问题。

Sersync介绍

1、sersync是使用c++编写,而且对linux系统文 件系统产生的临时文件和重复的文件操作进行过滤(详细见附录,这个过滤脚本程序没有实现),所以在结合rsync同步的时候,节省了运行时耗和网络资源。 因此更快。
2、sersync配置起来很简单,其中bin目录下已经有基本上静态编译的2进制文件,配合bin目录下的xml配置文件直接使用即可。
3、另外本项目相比较其他脚本开源项目,使用多线程进行同步,尤其在同步较大文件时,能够保证多个服务器实时保持同步状 态。
4、本项目有出错处理机制,通过失败队列对出错的文件重新同步,如果仍旧失败,则每10个小时对同步失败的文件重新同步。
5、本项目自带crontab功能,只需在xml配置文件中开启,即可按您的要求,隔一段时间整体同步一次。无需再额外配置crontab功能。
6、本项目socket与http插件扩展,满足您二次开发的需要。

实战过程

一、服务器环境

服务端:172.16.57.26 centos6.7 rsync-server 接收文件
客户端:172.16.57.25 centos6.7 sersync+rsync-client 发送文件

二、服务端安装rsync-server

1、安装rsync

# rpm -qa | grep rsync #查看rsync是否已经安装,如果没有安装,yum install直接安装即可

2、使用xinetd方式启动rsync

# vim /etc/xinetd.d/rsync #修改disable = no,flags = IPv4

3、修改rsync配置文件

# mkdir /etc/rsyncd
# vim /etc/rsyncd/rsyncd.conf #修改配置文件如下

# GLOBAL OPTIONS
motd file=/etc/motd
port=873
pid file=/var/run/rsyncd.pid
lock file = /var/lock/rsyncd
log file=/var/log/rsyncd
transfer logging = yes
log format = [op]:%o [ip]:%a [module]:%m [path]:%P [file]:%f [size]:%l
syslog facility=daemon
max connections=100

[recv]
comment = "recv data from 57.25"
path = /opt/rsync_data/recv #这边的目录的宿主要改为apprun,在这里同步过程中使用的是普通账户apprun
list = yes
use chroot = yes
uid = apprun
gid = apprun
read only = no
write only = no
exclude =
include =
auth users = rsync
secrets file = /etc/rsyncd/rsyncd.secrets
strict modes = yes
hosts allow = 172.16.57.25
hosts deny = *

# ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf

4、建立用户认证文件

# vim /etc/rsyncd/rsyncd.secrets
rsync:111111     #格式 用户名:口令
#chmod 600 /etc/rsyncd/rsyncd.secrets #权限设为600,否则启动会报错

5、启动rsync

# /etc/init.d/xinetd start
# netstat -tpln | grep 873 #查看873端口是否已经在监听了

三、客户端安装sersync+rsync-client

1、安装rsync,和服务端一样,没有安装的话yum install安装
2、安装sersync

# tar xzvf sersync2.5_64bit_binary_stable_final.tar.gz
# mv GNU-Linux-x86 /opt/programs/sersync #解压并拷贝到安装目录

3、配置sersync

<?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="true"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="true"/>
    <modify start="true"/>
    </inotify>

    <sersync>
    <localpath watch="/opt/rsync_data/send"> #监控目录
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Linux 安装与配置 mysql 环境 下一篇Linux shell ftp命令下载文件 根..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目