Sersync 服务器同步

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


主服务器A:192.168.2.108

目标服务器B:192.168.2.106    主服务器A要把目录同步到B这台目标服务器

将A的信息备份到B

一.目标服务器配置:

1.yum install rsync -y
2.vim /etc/rsyncd.conf  不存在,自己添加

uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid

lock file=/var/run/rsyncd.lock
[rsync]
path=/opt/rsync    将主服务器的资料同步到本目录下
comment=test files
ignore errors=yes
read only=no
hosts allow=192.168.2.108
hosts deny =*

3.mkdir /opt/rsync

4.后台运行 rsync

rsync --daemon       

5.  使用 xinetd 管理 rsync 服务
yum install xinetd -y

6.将rsync设置为开机自启动
chkconfig rsync on

7.
service xinetd restart


二.主服务器配置:

1.tar zxf sersync2.5_64bit_binary_stable_final.tar.gz
2.cd GNU-Linux-x86/
vim confxml.xml, 修改如下行

    <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="/usr/local/lnmp/nginx/html/">
            <remote ip="192.168.2.106" name="rsync"/>
3.启动

sersync 会对目录进行监控,将变化的目录或文件同步到远程服务器。sersync 是递归监控的,如
果有多级目录,都会同步到远程服务器。常用启动方式如下:
在主服务器上开启 sersync 守护进程,使 sersync 在后台运行,开启实时同步。

(1)cd GNU-Linux-x86/
(2)./sersync2 -d -r 

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
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
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
三.多目录配置

1.配置目标服务器

(1)创建同步目录

cd /mnt/
mkdir tongbu

(2)修改配置文件
vim /etc/rsyncd.conf
添加:

[tongbu]
path=/mnt/tongbu
comment = test files
ignore errors = yes
read only = no
hosts allow = 192.168.2.108
hosts deny = *
(3)配置主服务器

cd GNU-Linux-x86/
cp confxml.xml confxml-1.xml
vim confxml-1.xml

<sersync>
<localpath watch="/opt/tongbu1">
<remote ip="192.168.2.106" name="tongbu"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
cd /opt/
mkdir tongbu1
cd GNU-Linux-x86/
./sersync2 -r -d -o confxml-1.xml
cd /opt/tongbu1
touch hello
在目标服务器的/mnt/tongbu 下就会有被同步的文件 hello



在开启实时监控的之前对主服务器目录与远程目标机目录进行一次整体同步
./sersync -r
如果需要将 sersync 运行前,已经存在的所有文件或目录全部同步到远程,要以-r 参数运行
sersync,将本地与远程整体同步一次。如果设置了过滤器,即在 xml 文件中,filter 为 true,则暂时
不能使用-r 参数进行整体同步。-r 参数将会无效
指定配置文件
./sersync -o XXXX.xml
对于 sersync 使用可执行文件目录下的默认配置文件 confxml.xml,如果需要使用另一个配置文
件,可以使用-o 参数指定其它配置文件。
指定默认的线程池的线程总数
./sersync -n num
例如 ./sersync -n 5 则指定线程总数为 5,如果不指定,默认启动线程池数量是 10,如果 cpu 使用
过高,可以通过这个参数调低,如果机器配置较高,可以用-n 跳高线程总数。
不进行同步,只运行插件
./sersync -m pluginName
例如./sersync -m command,则在监控到文件事件后,不对远程目标服务器进行同步,而是直接
运行 command 插件。
多个参数可以配合使用
./sersync -n 8 -o abc.xml -r -d
表示,设置线程池工作线程为 8 个,指定 abc.xml 作为配置文件,在实时监控前作一次整体同步,以
守护进程方式在后台运行。
通常情况下,对本地到远程整体同步一遍后,在后台运行实时同步。
./sersync -r -d

























转载于:https://my.oschina.net/CentralD/blog/373139

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值