说明:该功能服务端安装sersync2,客户端安装rsync,原理就是服务端主动推送设定目录下的所有更新的文件到各个客户端rsync接收。

rsync大家都知道,是Linux自带的数据同步工具,而sersync2是google大神的开源项目http://code.google.com/p/sersync/

下面给出具体的实现步骤,实现的详细原理大家可以去上面的开源网址,上面说的很详细

  1. 客户端配置,首先系统安装rsync工具,

    [root@yo57 ~]# vi /etc/rsyncd.conf
    
    uid=www
    gid=www
    max connections=36000
    use chroot=no
    log file=/var/log/rsyncd.log
    pid file=/var/run/rsyncd.pid
    lock file=/var/run/rsyncd.lock [yowebtongbu]
    path=/Data/code/adserver
    comment = yo web files
    ignore errors = yes
    read only = no
    hosts allow = 192.168.0.0/24
    hosts deny = *
    [root@yo57 ~]# /usr/bin/rsync --daemon --config=/etc/rsyncd.conf
    [root@yo57 ~]# ps -ef|grep rsyn
    root 1070 29923 0 17:04 pts/4 00:00:00 grep rsyn
    root 32069 1 0 16:54 ? 00:00:00 /usr/bin/rsync --daemon --config=/etc/rsyncd.conf
  2. 写入开机启动项
    [root@yo57 ~]# vi /etc/rc.local
    
    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff. touch /var/lock/subsys/local ulimit -SHn 51200
    /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
    /usr/local/nginx/sbin/nginx
    /etc/init.d/php_fpm start
    /usr/bin/rsync --daemon --config=/etc/rsyncd.conf
  3. 服务器端
    [root@10 
    local
    ]
    # tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
    [root@10 
    local
    ]
    # cd sersync2.5.4_64
    [root@10 sersync2.5.4_64]
    # ls
    confxml.xml  sersync2
    [root@10 sersync2.5.4_64]
    # vi confxml.xml

    修改这一段即可

    <localpath 
    watch
    =
    "/Data/code/adserver"
    >
          
    <remote ip=
    "192.168.0.27" 
    name=
    "yowebtongbu"
    />
          
    <!--<remote ip=
    "192.168.8.39" 
    name=
    "tongbu"
    />-->
          
    <!--<remote ip=
    "192.168.8.40" 
    name=
    "tongbu"
    />-->
      
    <
    /localpath
    >

    进行一次完整同步
    [root@10 sersync2.5.4_64]# ./sersync2 -r
    写入脚本并放入开机启动项

    [root@10 sersync2.5.4_64]
    # cat /usr/local/sbin/sersync.sh    
    #!/bin/bash
    PATH=
    /bin
    :
    /sbin
    :
    /usr/bin
    :
    /usr/sbin
    :
    /usr/local/bin
    :
    /usr/local/sbin
    :~
    /bin
    export 
    PATH
       
    SDATH=
    "/usr/local/sersync2.5.4_64"
    SSTART=
    "./sersync2 -r -d"
    SPID=`
    ps 
    -ef|
    grep 
    'sersync2'
    |
    grep 
    -
    v 
    'grep'
    |
    awk 
    '{print $2}'
    `
       
    function_start()
    {
        
    echo 
    -en 
    "\033[32;49;1mStarting sersync2......\n"
        
    echo 
    -en 
    "\033[39;49;0m"
        
    if 
    [ -t ${SPID} ]; 
    then
            
    cd 
    ${SDATH}
            
    ${SSTART} > 
    /dev/null 
    2>&1
            
    printf 
    "Serync2 is the successful start!\n"
        
    else
        
    printf 
    "Sersync2 is runing!\n"
        
    exit 
    1
        
    fi
    }
       
    function_stop()
    {
        
    echo 
    -en 
    "\033[32;49;1mStoping sersync2......\n"
        
    echo 
    -en 
    "\033[39;49;0m"
        
    if  
    [ -t ${SPID} ]; 
    then
            
    printf  
    "Sersync2 program is not runing!\n"
        
    else
            
    kill 
    ${SPID}
            
    printf 
    "Sersync2 program is stoped\n"
        
    fi
    }
       
    function_restart()
    {
        
    echo 
    -en 
    "\033[32;49;1mRestart sersync2......\n"
        
    echo 
    -en 
    "\033[39;49;0m"
        
    if  
    [ -t ${SPID} ]; 
    then
            
    cd 
    ${SDATH}
            
    ${SSTART} > 
    /dev/null 
    2>&1
        
    else
            
    kill 
    ${SPID}
            
    sleep 
    1
            
    cd 
    ${SDATH}
            
    ${SSTART} > 
    /dev/null 
    2>&1
        
    fi
        
    printf 
    "Sersync2 is the successful restart!\n"
    }
       
    function_kill()
    {
        
    killall sersync2
    }
       
    function_status()
    {
        
    if 

    ps 
    -ef|
    grep 
    'sersync2'
    |
    grep 
    -
    v 
    'grep' 

    /dev/null 
    2>&1
        
    then
            
    printf 
    "Sersync2 is down!!!\n"
        
    else
            
    printf 
    "Sersync2 is running now!\n"
        
    fi
    }
       
    if 

    "$1" 

    "start" 
    ]; 
    then
        
    function_start
    elif 

    "$1" 

    "stop" 
    ]; 
    then
        
    function_stop
    elif 

    "$1" 

    "restart" 
    ]; 
    then
        
    function_restart
    elif 

    "$1" 

    "kill" 
    ]; 
    then
        
    function_kill
    elif 

    "$1" 

    "status" 
    ]; 
    then
        
    function_status
    else
        
    echo 
    -en 
    "\033[32;49;1m Usage: sersync2 {start|stop|restart|kill|status}\n"
        
    echo 
    -en 
    "\033[39;49;0m"
    fi


    [root@10 sersync2.5.4_64]
    # vi /etc/rc.local
        
    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.
        
    touch 
    /var/lock/subsys/local
    #/etc/init.d/lemp start
    /usr/local/nginx/sbin/nginx
    /etc/init
    .d
    /php_fpm 
    start
    /usr/local/zabbix/sbin/zabbix_agentd
    /usr/local/sbin/sersync
    .sh start

整个实现就这么简单,以后主服务器上面/Data/code/adserver目录下有新建、删除、修改文件或文件夹(包括下层递归)的的数据会自动推送到下面的各个服务端对应目录下,如果临时不需要该功能,kill掉服务端即可,操作完以后在手动开启服务端(此时客户端不用动)

Linux文件实时同步,可实现一对多的更多相关文章

  1. linux文件实时同步

    参考博客:https://www.cnblogs.com/MacoLee/p/5633650.html 一.文件同步很简单 服务端:被动的接收传输过来的数据 客户端:主动提供数据给服务端 安装思路:服 ...

  2. linux下两台服务器文件实时同步方案设计和实现

    inux下两台服务器文件实时同步方案设计和实现 假设有如下需求: 假设两个服务器: 192.168.0.1 源服务器  有目录 /opt/test/ 192.168.0.2 目标服务器  有目录 /o ...

  3. Linux服务器间文件实时同步的实现

    使用场景 现有服务器A和服务器B,如果服务器A的指定目录(例如 /home/paul/rsync/ )中的内容发生变更(增删改和属性变更),实时将这些变更同步到服务器B的目标目录中(例如 /home/ ...

  4. (转)Linux下通过rsync与inotify(异步文件系统事件监控机制)实现文件实时同步

    Linux下通过rsync与inotify(异步文件系统事件监控机制)实现文件实时同步原文:http://www.summerspacestation.com/linux%E4%B8%8B%E9%80 ...

  5. rsync+inotify 实现服务器之间目录文件实时同步(转)

    软件简介: 1.rsync 与传统的 cp. tar 备份方式相比,rsync 具有安全性高.备份迅速.支持增量备份等优点,通过 rsync 可 以解决对实时性要求不高的数据备份需求,例如定期的备份文 ...

  6. rsync+inotify-tools文件实时同步

    rsync+inotify-tools文件实时同步案例 全量备份 Linux下Rsync+sersync实现数据实时同步完成. 增量备份 纯粹的使用rsync做单向同步时,rsync的守护进程是运行在 ...

  7. inotify用法简介及结合rsync实现主机间的文件实时同步

    一.inotify简介 inotify是Linux内核2.6.13 (June 18, 2005)版本新增的一个子系统(API),它提供了一种监控文件系统(基于inode的)事件的机制,可以监控文件系 ...

  8. eclipse 远程文件实时同步,eclipse远程部署插件

    [转自] http://zhwj184.iteye.com/blog/1842730 eclipse 远程文件实时同步,eclipse远程部署插件 github地址:https://github.co ...

  9. Centos 6.5 rsync+inotify 两台服务器文件实时同步

    rsync和inotify是什么我这里就不在介绍了,有专门的文章介绍这两个工具. 1.两台服务器IP地址分别为: 源服务器:192.168.1.2 目标服务器:192.168.1.3 @todo:从源 ...

随机推荐

  1. caffe 中 plot accuracy和loss, 并画出网络结构图

    plot accuracy + loss 详情可见:http://www.2cto.com/kf/201612/575739.html 1. caffe保存训练输出到log 并绘制accuracy l ...

  2. 关于ueditor的使用心得

    http://blog.csdn.net/baronyang/article/details/45640181 1.取编辑器内的内容: <span style="font-size:1 ...

  3. Chrome谷歌浏览器拓展组件的2种快速安装方法(.crx)

    谷歌浏览器拓展有至少2种安装方法,现在简单的介绍下. 第一种.当然是进入谷歌官方的应用商店直接安装 这种方法简单快捷,而且官方支持度够高,唯一的缺点是大陆用户需要“FQ”. 谷歌拓展组件应用商店地址: ...

  4. 如何定义最佳 Cache-Control 策略

    定义最佳 Cache-Control 策略 按照以上决策树为您的应用使用的特定资源或一组资源确定最佳缓存策略.在理想的情况下,您的目标应该是在客户端上缓存尽可能多的响应,缓存尽可能长的时间,并且为每个 ...

  5. poj3349(hash table)

    做的第一道哈希表的题目.速度很慢,跑了3000+ms.采用六条边的和对一个大质数的余数作为哈希表的key,理论上质数取得越大,消耗的空间就越大,但是速度会加快,这里取了14997.地址冲突用链表解决. ...

  6. ONVIF开发实例

    <开发过过程中的经验总结> ➤工具的使用     (1)首先将文件soapClientLib.c 中"代码"的第二行和第三行注释掉,实际上该文件根本没有用,为了保险起见 ...

  7. mutiplemap 总结

    之前只是在C++ Primer里面看过关联容器,可能因为没有实际用过,只是看看,所以导致用的时候并不熟悉: 在这之前,map和set的特性应该要了解,map是关联数组,也就是由键值对组成的,而set只 ...

  8. Codeforces Round #295 (Div. 2)A - Pangram 水题

    A. Pangram time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  9. HDU 3161 Iterated Difference 暴力

    Iterated Difference Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  10. ASP.NET 构建高性能网站 第4篇

    部署优化 我们都知道,不同的部署方式对站点的性能是有影响的,可能有些朋友已经知道了这点,不管怎样,我们这里还是详细系统的讲述一下这个问题,熟悉的朋友权当回顾J. Release方式编译项目 如果我们的 ...