somepeople

linux服务器同步策略(sersync、lsync)

sersync:

  先安装rsync(server和节点都要安装,但只启用节点服务即可):yum install rsync

   修改节点配置(server配置可以不改,服务不用启用):

    vim /etc/rsyncd.conf

uid = root
gid = root
use chroot = yes
max connections = 30000
max connections = 0
port = 16874
log file = /tmp/rsyncd.log
motd file = /tmp/rsyncd.motd
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
secrets file = /etc/rsyncd.pswd
auth users = rsync

[tongbu1]
path =  /data/tongbu
ignore errors = yes
read only = no

  按照配置创建密钥文件:

  [root@node-2 tongbu]# touch /etc/rsyncd.pswd

  [root@node-2 tongbu]# cat /etc/rsyncd.pswd
  rsync:rsync

  修改权限为600

 

  [root@node-2 tongbu]# chmod 600 /etc/rsyncd.pswd

  重启rsync服务

  [root@node-2 tongbu]# systemctl restart rsyncd

  在server上安装sersync:

  wget https://codeload.github.com/wsgzao/sersync/zip/master

  下载后解压,将二进制文件和配置文件可自定义分目录存放:

  

  [root@node-1 tongbu]# tree -l /usr/local/sersync
  /usr/local/sersync
  ├── bin
  │   └── sersync2
  └── conf
  └── confxml.xml

  修改配置文件:

  

<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="false"/>
    <fileSystem xfs="true"/>      #根据系统选择是否启用
    <filter start="false">           #过滤,如果开启则-r递归同步效果失效
    <exclude expression="(.*)\.svn"></exclude>
    <exclude expression="(.*)\.gz"></exclude>
    <exclude expression="^info/*"></exclude>
    <exclude expression="^static/*"></exclude>
    </filter>
    <inotify>
    <delete start="false"/>      #如果启用,则被同步服务器上的资源会和同步服务器对比,如果同步服务器上没有的资源会被删除掉,建议不启用
    <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="/opt/tongbu">  #同步服务器本地需同步文件目录
        <remote ip="192.168.159.130" name="tongbu1"/>    #被同步服务器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="rsync" passwordfile="/etc/rsync.pas"/>   #是否启用认证,以及认证用户、密码配置文件(格式为明文密码)
        <userDefinedPort start="true" port="16874"/><!-- port=874 -->       #是否启用自定义端口,默认端口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>

    <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="xxxx"/>
        <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>

  创建密钥文件:

  [root@node-1 tongbu]# touch /etc/rsync.pas
  [root@node-1 tongbu]# chmod 600 /etc/rsync.pas

  启动服务:/usr/local/sersync/bin/sersync2 -d -r -o /usr/local/sersync/conf/confxml.xml

lsync:

  rsync安装步骤同上

  在同步服务器上安装lsyncd

  [root@node-1 yum.repos.d]# yum install lsyncd

  修改配置

settings {
    nodaemon = false,
    logfile = "/var/log/lsyncd/lsyncd.log",
    statusFile = "/var/log/lsyncd/lsyncd.status",
    inotifyMode = "CloseWrite",
    statusInterval = 20,
    insist =true;
    maxProcesses = 5,
    maxDelays = 10
}

 --37                #注释
 sync {
     default.rsync,
     delete="false",
     source = "/data/",
     target = "rsync@*.*.*.*::tongbu",
     exclude = { ".*", ".tmp","*.bak","m3u8/**" },
     rsync = {
        archive = true,
        compress = false,
        verbose = false,
        password_file="/etc/rsync.pas",
        _extra    = {"--port=16874"}
     }
    }

  确认配置无误后启用lsyncd

  

posted on 2021-02-22 16:37  Hello_Thanos  阅读(362)  评论(0编辑  收藏  举报

导航