Sersync 配置和使用

参照文档: https://github.com/wsgzao/sersync

简介

sersync + inotify-tools + rsync 可以实现服务器文件实时同步。

环境

服务器A(SourA):主服务器/源文件服务器,该服务器的文件变动,会实时同步到B服务器。

  • 安装: rsync(daemon)

服务器B(DestB):备份服务器/目的文件服务器

  • 安装: rsync inotify-tools sersync

备份服务器B配置

安装 Rsync
# 使用 yum 或者 源码编译 安装,省略
配置 rsync,以 daemon 方式运行
# 具体参数和配置可以参照 《rsync的配置和使用》
[root@DestB rsync]# ls /etc/rsync
rsyncd.conf  rsyncd.secrets

[root@DestB rsync]# cat /etc/rsync/rsyncd.conf 
use chroot = no
hosts allow = SourA_ip
hosts deny = *
max connections = 4
pid file = /var/run/rsyncd.pid
log format = %t %a %m %f %b
log file = /var/log/rsync.log
exclude = ^settings/*     # 排除 settings 目录
transfer logging = yes
timeout = 900

[lfbak4nfs]
uid = www
gid = www
read only = no
path = /mydata/nfs/   # 要备份的目录
list = no
ignore errors = yes
auth users = satebak
secrets file = /etc/rsync/rsyncd.secrets

[root@DestB rsync]# cat /etc/rsync/rsyncd.secrets 
satebak:passwd@2017

[root@DestB rsync]# chmod 600 /etc/rsync/rsyncd.secrets 
启动
[root@DestB rsync]# rsync --daemon --config=/etc/rsync/rsyncd.conf

主服务器A配置

安装 Rsync
# 使用 yum 或者 源码编译 安装,省略
安装 inotify-tools
# 下载,编译安装
[root@SourA rsync]# cd /opt/
[root@SourA opt]# wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
[root@SourA opt]# tar xvf inotify-tools-3.14.tar.gz
[root@SourA opt]# cd inotify-tools-3.14
[root@SourA inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify
[root@SourA inotify-tools-3.14]# make -j2 && make install

# 添加环境变量
[root@SourA inotify-tools-3.14]# cat /etc/profile.d/inotify.sh
export PATH=/usr/local/inotify/bin:$PATH
[root@SourA inotify-tools-3.14]# source /etc/profile
安装 sersync
# 下载
[root@SourA rsync]# cd /opt/
[root@SourA opt]# wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@SourA opt]# tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@SourA opt]# mv GNU-Linux-x86/ /usr/local/sersync/
配置 sersync

修改配置文件 /usr/local/sersync/confxml.xml



    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
       
          
        
        
    
    
         
          
        
        
        
    
    
    
        
        
        
        
    
    
    

    
      
    
        
        
    
    

    
    
        
    
    
    
    
        
        
        
    
    

添加密码文件

[root@SourA sersync]# echo 'passwd@2017' > /usr/local/sersync/user.pass
[root@SourA sersync]# chmod 600 /usr/local/sersync/user.pass
运行
[root@SourA sersync]# nohup /usr/local/sersync/sersync2 -r -d -o /usr/local/sersync/confxml.xml > /usr/local/sersync/rsync.log 2>&1 &

-d:启用守护进程模式
-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
-n:指定开启守护线程的数量,默认为10个
-o:指定配置文件,默认使用confxml.xml文件

你可能感兴趣的:(Sersync 配置和使用)