• rsync+sersync自动同步


    参考:http://www.cnblogs.com/itech/archive/2009/08/10/1542945.html

    yum -y install rsync

    配置文件

    vim /etc/rsyncd.conf

    # /etc/rsyncd: configuration file for rsync daemon mode
    
    # See rsyncd.conf man page for more options.
    
    # configuration example:
    
     uid = nobody
     gid = nobody
     use chroot = no
     max connections = 4
     pid file = /var/run/rsyncd.pid
    # exclude = lost+found/
    # transfer logging = yes
     timeout = 900
    # ignore nonreadable = yes
    # dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
    
    # [ftp]
    #        path = /home/ftp
    #        comment = ftp export area
    [csmh]
    path = /home/wwwroot/csmh
    auth users = zhong
    ignore errors
    secrets file = /etc/rsyncd.secrets
    #exclude = cache/
    [gjml]
    path = /home/wwwroot/gjml
    auth users = zhong
    ignore errors
    secrets file = /etc/rsyncd.secrets
    #exclude = cache/
    [xian]
    path = /home/wwwroot/xian
    auth users = zhong
    ignore errors
    secrets file = /etc/rsyncd.secrets
    

     密码文件

     vim /etc/rsyncd.secrets

    zhong:123456
    

     客户端同步

    从服务端拉取

    rsync -avzP zhong@47.93.123.70::csmh rr --delete --password-file=/etc/rsyncd.secrets

    /etc/rsyncd.secrets 文件内容为密码

    123456

    往服务端推送

    rsync -avzP /home/tt.txt zhong@47.93.123.70::csmh --delete --password-file=/etc/rsyncd.secrets

    +++sersync 实现自动同步++++

    从本地向服务端指定目录推送文件

    #!/bin/bash
    # 大明宫测试往线上同步
    # 在file内写上需要同步的文件的相对于/home/wwwroot/dmg/的路径,一行一个
    file=(
    /phpcms/templates/default/member/register.html
    /phpcms/templates/default/member/wap_register.html
    )
    for f in ${file[@]};
    do
       if [ ! -f  /home/wwwroot/dmg$f  ];then
         echo $f not exist
       fi
       rsync  -aSz /home/wwwroot/dmg$f rsync://zhong@10.30.55.153/dmg$f  --password-file=/etc/rsyncd.secrets
    done
    rsync -avzP   root@10.30.55.153:/home/1.txt /home/  拉取
    rsync -avzP   /home/1.txt  root@10.30.55.153:/home/ 推送

    解压sersync之后又两个文件

    1 confxml.xml(配置文件)  2   sersync2(启动文件)

    配置文件

    文件同步条件

    <inotify>
    <delete start="true"/>
    <createFolder start="true"/>
    <createFile start="false"/>
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="false"/>
    <modify start="true"/>
    </inotify>

    <sersync>
    <localpath watch="/home/tb">  本地的同步目录
    <remote ip="192.168.10.150" name="rsync"/>   rsync服务端IP 和同步模块
    <!--<remote ip="192.168.8.39" name="tongbu"/>-->
    <!--<remote ip="192.168.8.40" name="tongbu"/>-->
    </localpath>
    <rsync>
    <commonParams params="-artuz"/>
    <auth start="true" users="test" passwordfile="/etc/rsync.pas"/> 用户名和密码文件
    <userDefinedPort start="false" port="873"/><!-- port=874 -->
    <timeout start="false" time="100"/><!-- timeout=100 -->
    <ssh start="false"/>
    </rsync>
    <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> 同步失败日志
    <crontab start="false" schedule="600"><!--600mins-->
    <crontabfilter start="false">
    <exclude expression="*.php"></exclude>
    <exclude expression="info/*"></exclude>
    </crontabfilter>
    </crontab>
    <plugin start="false" name="command"/>
    </sersync>

    2 启动

    ./sersync2  -d -o config.xml

    -r  的意思是 先执行一次 完整同步

    -d 后台执行 

  • 相关阅读:
    第四章 源代码的下载和编译 读书笔记
    第三章 Git使用入门 读书笔记
    第二章 搭建Android开发环境 读书笔记
    第一章Android系统移植与驱动开发概述 读书笔记
    读书笔记第九章
    读书笔记第八章
    读书笔记第十章
    读书笔记第七章
    读书笔记第五章
    读书笔记第六章
  • 原文地址:https://www.cnblogs.com/jkklearn/p/6676100.html
Copyright © 2020-2023  润新知