手机版
你好,游客 登录 注册
背景:
阅读新闻

使用sersync同步Linux服务器上文件

[日期:2012-08-17] 来源:Linux社区  作者:chenkui [字体: ]

Linux下resync同步文件

  1. 01、实际工作中,我们有大量的数据要进行同步及备份,手动手帕灰常慢,那么在Linx下我们可以
  2. 使用sersync进行同步,非常快也非常可靠,下面我们来做一个简单的测试:
  3.  
  4. 02、实验环境
  5. 1)服务器端:CentOS 5.5_X64 IP:192.168.10.36
  6. 2)客户端: CentOS 5.5_X64  IP:192.168.10.38
  7.  
  8. 03、准备工作
  9. 下载 sersync2.5.4_64bit_binary_stable_final.tar.gz包
  10. 下载地址:http://code.google.com/p/sersync/downloads/list 
  11.  
  12. 04、服务器端配置:
  13. [root@test ~]# tar zxvf /opt/sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/bin/
  14. [root@test ~]# cd /usr/bin/GNU-Linux-x86/
    [root@test GNU-Linux-x86]# ll
    total 1776
    -rwxr-xr-x 1 root root    2217 Aug 17 18:31 confxml.xml
    -rwxr-xr-x 1 root root 1810128 Oct 26  2011 sersync2
  15. [root@test GNU-Linux-x86]# vi confxml.xml

  16. <?xml version="1.0" encoding="ISO-8859-1"?>
    <head version="2.5">
        <host hostip="localhost" port="8008"></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>
  17. ##################以上部分保持默认即可####下面红色即为修改配置地方####################
  18.     <sersync>
            <localpath watch="/opt/tongbu">
                <remote ip="192.168.10.38" name="tongbu"/>
                <!--<remote ip="192.168.8.39" name="tongbu"/>-->
                <!--<remote ip="192.168.8.40" name="tongbu"/>-->
            </localpath>
            <rsync>
                <commonParams params="-artuz"/>
                <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
                <userDefinedPort start="false" port="874"/><!-- 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>
  19.     <plugin name="command">
            <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->
            <filter start="false">
  20. 退出保存
  21. 配置好yum,安装rsync以便让sersync进行调用
  22. [root@test GNU-Linux-x86]# yum install rsync
  23.  
  24. 05、客户端配置
  25. 1)安装rsync软件包
  26. [root@mail ~]# yum install rsync
  27.  
  28. 创建配置文件
  29. [root@mail ~]# vi /etc/rsyncd.conf
  30. uid=root    //设置运行权限为root
    gid=root
    max connections=100
    use chroot=no
    log file=/var/log/rsyncd.log
    pid file=/var/run/rsyncd.pid
    lock file=/var/run/rsyncd.lock
    [tongbu]
    path=/opt/tongbu
    comment = tongbu//与上面[tongbu]模块名称相同
    ignore errors = yes
    read only = no  //设置客户端可以上传文件,yes为只读,不能上传
  31. write only = no //设置客户端可以下载文件,yes为不能下载
    hosts allow = 192.168.10.36 192.168.10.38//表示只允许这两台主机可以进行同步
  32. hosts deny = * //拒绝其他一切机器同步
  33. 创建同步目录
  34. [root@mail ~]# mkdir /opt/tongbu
  35. 启动rsync服务
  36. [root@mail ~]# rsync --daemon
  37. [root@mail ~]# lsof -i:873 //检查服务是否启动
  38. [root@mail ~]# lsof -i:873
    COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
    rsync   4236 root    4u  IPv6  14709       TCP *:rsync (LISTEN)
    rsync   4236 root    5u  IPv4  14710       TCP *:rsync (LISTEN)
    [root@mail ~]#
  39. 如果有iptables防火墙,请允许TCP的873端口开放
  40.  
  41. 下面来进行同步测试
  42. 在服务器端的/opt/tongbu/下面建立一个文件
  43. [root@test GNU-Linux-x86]# mkdir /opt/tongbu/
  44. [root@test GNU-Linux-x86]# touch /opt/tongbu/file.txt
  45. [root@test GNU-Linux-x86]# ll /opt/tongbu/
    total 0
    -rw-r--r-- 1 root root 0 Aug 17 18:45 file.txt
  46. 启动sersync
  47. [root@test GNU-Linux-x86]# ./sersync2 -r -d
  48. 查看客户端是不是同步过去了
  49. [root@mail ~]# ll /opt/tongbu/
    total 0
    -rw-r--r-- 1 root root 0 Aug 17  2012 file.txt  //同步成功
    [root@mail ~]#
  50. sersync 选项说明
  51. -h 查看帮助文件
    -r 在同步程序开启前,将整个路径跟远程服务器同步一遍
    -d 开启守护进程模式在后台运行
    -o 指定配置文件,如果不是默认的confxml.xml的情况下
    -n 指定同步守护线程数量,默认为10个,适用于现在的4核服务器。如果需增加或减少使用 '-n 数量'
linux
相关资讯       Sersync 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款