一个伪linux粉丝的blog

  1. 首页
  2. network
  3. 正文

Real Time Sync with Sersync

26 1 月, 2011 2374点热度 0人点赞 0条评论

以前一直使用rsync半夜同步上海、武汉两地之间服务器上的模板文件,最近这个方式出现一个新的问题,原因是不够实时,白天更新的模板,武汉同事常常无法使用,提示模板文件未找到,报错新信发过来,我只好手动启动rsync程序同步一次,几次之后,不胜其烦了,得想办法解决。

网上搜了一圈,发现金山的技术部周洋共享了一个Sersync开源程序,项目地址 http://code.google.com/p/sersync/

Sersync工作原理:
使用 Linux 2.6 内核的新特性, inotify 监控 Linux 文件系统事件,被监听目录下如果有文件发生修改,sersync 将通过内核自动捕获到事件,并将该文件利用 rsync 同步到多台远程服务器。sersync 仅仅同步发生增、删、改事件的单个文件或目录,不像rsync镜像同步那样需要比对双方服务器整个目录下数千万的文件,并且支持多线程同步,因此效率非常高。

教程地址 http://blog.johntechinfo.com/sersyncguild

实战:

1,服务器端下载、安装最新版sersync2.5 http://sersync.googlecode.com/files/sersync2.5_32bit_binary_stable_final.tar.gz

cd /usr/src/
wget http://sersync.googlecode.com/files/sersync2.5_32bit_binary_stable_final.tar.gz
tar zxvf sersync2.5_32bit_binary_stable_final.tar.gz
cd GNU-Linux-x86
vi confxml.xml

confxml.xml文件配置比较简单,修改 false和true搞定,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<host hostip="localhost" port="8081"></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="false"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="false"/>
        <modify start="false"/>
    </inotify>
 
    <sersync>
        <localpath watch="/var/www/shanghai/template">
            <remote ip="192.168.1.2" name="template"/>
                  </localpath>
        <rsync>
            <commonParams params="-vurt"/>
            <auth start="true" users="abc" passwordfile="/etc/rsync.pas"/>
            &lt;userDefinedPort start="true" port="<span style="color: #ff0000;">8081</span>"/&gt;&lt;!-- port=874 --&gt;
            &lt;timeout start="false" time="100"/&gt;&lt;!-- timeout=100 --&gt;
            &lt;ssh start="false"/&gt;
        &lt;/rsync&gt;
        &lt;failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/&gt;
        &lt;crontab start="false" schedule="600"&gt;&lt;!--600mins--&gt;
            &lt;crontabfilter start="false"&gt;
                &lt;exclude expression="*.php"&gt;&lt;/exclude&gt;
                &lt;exclude expression="info/*"&gt;&lt;/exclude&gt;
            &lt;/crontabfilter&gt;
        &lt;/crontab&gt;
        &lt;plugin start="false" name="command"/&gt;
    &lt;/sersync&gt;

启动 服务端 ./sersync2 -d
2,客户端启用rsync daemon进程

vi /etc/rsyncd.conf

uid=webopadmin
gid=webopadmin
use chroot=no
max connections = 100
log file = /var/log/rsync/rsyncd.log
lock file=/var/run/rsyncd.lock
pid file=/var/run/rsyncd.pid

[template]
path = /var/www/wuhan/template
comment = webdesign template
ignore errors = yes
read only=no
hosts allow = 192.168.1.1/24
hosts deny = *
启用 客户端 rsync daemon进程,开始监听,默认873端口
rsync --daemon
也可以增加端口参数 rsync --port=8081 --daemon ,启用了8081端口,以免防火墙被挡,对应的服务器端confxml.xml配置也要监听这个8081端口

搞定收工,另有一些插件可以增加测试,我这里就不试验了。

相关文章:

  1. iWatch monitor ftp site file created and send mail
  2. crontab log error
  3. Moving WordPress blog to a new server
  4. redmine-install-notes
标签: 暂无
最后更新:26 1 月, 2011

wanjie

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

This site uses Akismet to reduce spam. Learn how your comment data is processed.

归档
分类
  • network / 332篇
  • Uncategorized / 116篇
  • unix/linux / 121篇
  • 业界资讯 / 38篇
  • 公司杂事 / 11篇
  • 数码影像 / 12篇
  • 美剧 / 3篇
  • 美图共赏 / 21篇
  • 英语学习 / 3篇
标签聚合
dreamhost空间 Ubuntu deepseek postgres d90 debian k8s kubectl 天翼live ssh ldap dreamhost google-chrome 虚拟主机 VPS 网站运营 Nginx jira kernel 邮件归档 squid 浏览器 泰国 docker openssl wget Google Voice nexus Google gitlab

COPYRIGHT © 2008-2025 wanjie.info. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang