rsync和serrsync做文件同步

来源:互联网 发布:企信通软件 编辑:程序博客网 时间:2024/06/01 09:43

参考文章:

转载自 http://blog.csdn.net/orangleliu/article/details/46699147

serrsync2 安装

  1. 下载sersync

    wget https://raw.githubusercontent.com/orangle/sersync/master/release/sersync2.5.4_64bit_binary_stable_final.tar.gz

  2. 创建目录

    mkdir /usr/local/sersync /usr/local/sersync/conf /usr/local/sersync/bin/usr/local/sersync/log

  3. 解压文件

    tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
    cd GNU-Linux-x86/
    confxml.xml /usr/local/sersync/conf
    cp sersync2 /usr/local/sersync/bin

  4. 修改 confxml.xml

    vim /usr/local/sersync/conf

  5. 创建密码文件并把权限改成600 [注意这里的格式]

    echo “123456” > /etc/rsync/rsync.pas
    chmod 600 /etc/rsync/rsync.pas

  6. 创建同步目录

    mkdir /home/data

  7. 添加设置环境变量:

    echo “export PATH=$PATH:/usr/local/sersync/bin/” >> /etc/profile
    source /etc/profile

  8. 启动服务

    sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml
    # 重启操作如下:
    # pkill sersync2 && sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml

confxml.xml说明

<?xml version="1.0" encoding="ISO-8859-1"?><head version="2.5">   # 设置本地IP和端口   <host hostip="localhost" port="8008"></host>   # 开启DUBUG模式     <debug start="false"/>   # 开启xfs文件系统   <fileSystem xfs="false"/>   # 同步时忽略推送的文件(正则表达式),默认关闭   # 一般都会把这个改成true, 然后过滤一些不需要的东西   <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="/home/data">   # 远程IP和rsync模块名    # 这个就是要同步的主机ip,建议内网ip优先           <remote ip="127.0.0.1" name="tongbu"/>             <!--<remote ip="192.168.8.39" name="tongbu"/>-->           <!--<remote ip="192.168.8.40" name="tongbu"/>-->       </localpath>       <rsync>   # rsync指令参数           <commonParams params="-auvzP"/>   # rsync同步认证   # 默认是false, 一般都会改成true,这样同步的时候会校验密码,如果错误就不会同步           <auth start="true" users="xxxx" passwordfile="/etc/rsync/serrsync.pas"/>   # 设置rsync远程服务端口,远程非默认端口则需打开自定义           <userDefinedPort start="false" port="873"/><!-- port=874 -->   # 设置超时时间           <timeout start="true" time="100"/><!-- timeout=100 -->   # 设置rsync+ssh加密传输模式,默认关闭,开启需设置SSH加密证书           <ssh start="false"/>       </rsync>    # sersync传输失败日志脚本路径,每隔60会重新执行该脚本,执行完毕会自动清空。       <failLog path="/usr/local/sersync/log/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->    # 设置rsync+crontab定时传输,默认关闭       <crontab start="false" schedule="600"><!--600mins-->           <crontabfilter start="false">               <exclude expression="*.php"></exclude>               <exclude expression="info/*"></exclude>           </crontabfilter>       </crontab>   # 设置sersync传输后调用name指定的插件脚本,默认关闭       <plugin start="false" name="command"/>   </sersync>   # 插件脚本范例   <plugin name="command">       <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->       <filter start="false">           <include expression="(.*)\.php"/>           <include expression="(.*)\.sh"/>       </filter>   </plugin>   # 插件脚本范例   <plugin name="socket">       <localpath watch="/opt/tongbu">           <deshost ip="192.168.138.20" port="8009"/>       </localpath>   </plugin>   <plugin name="refreshCDN">       <localpath watch="/data0/htdocs/cms.xoyo.com/site/">           <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxx"/>           <sendurl base="http://pic.xoyo.com/cms"/>           <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>       </localpath>   </plugin></head>

rsync安装

  1. 增加一个用户

    useradd xxxx

  2. 安装rsync

    yum install rsync

  3. 配置rsnc [注意密码文件,密码和服务器的是一样的, 但是前面是带用户名的]

    mkdir /etc/rsync
    echo "xxxx:123456" > /etc/rsync/rsync.pas
    chmod 600 /etc/rsync/rsync.pas
    vim /etc/rsync/rsyncd.conf

  4. 启动

    rsync --daemon --config=/etc/rsync/rsyncd.conf
    # 重启操作如下:
    # pkill rsync && rsync --daemon --config=/etc/rsync/rsyncd.conf

rsyncd.conf参考

uid = rootgid = rootmax connections=200use chroot =nolist = nolog file = /var/log/rsyncd.loglog format =  %t %a %m %f %bpid file= /var/run/rsyncd.pidlock file= /var/run/rsyncd.lock timeout=600 #超时时间[tongbu]path =/app/xasxa #文件保存路径list = yescomment = 123456798ignore errors = yesread only = nohosts allow = 127.0.0.1 #允许的ipauth users = xxxx #验证用户secrets file = /etc/rsync/rsync.pas #密码文件
原创粉丝点击