• 基于rsync的lsyncd自动同步配置


    环境部署

    源机:192.168.31.140
    目标机:192.168.31.130

    源机配置

    基于rsync的lsyncd 自动同步,rsync的配置省略

    安装lsyncd

    rpm -ivh lsyncd-2.1.5-1.x86_64.rpm 
    
    配置文件:/usr/local/lsyncd/etc/lsyncd.conf
    日志文件:/usr/local/lsyncd/logs/lsyncd.log
    状态文件(由程序自动生成):/usr/local/lsyncd/logs/lsyncd.status

    配置lsyncd

    [root@baseos-1_192.168.31.140 ~]# vim /usr/local/lsyncd/etc/lsyncd.conf   
    settings  {
       logfile = "/usr/local/lsyncd/logs/lsyncd.log",
       statusFile = "/usr/local/lsyncd/logs/lsyncd.status",
       maxDelays = 100,
       delay = 5,
       exitcodes = {[0] = "ok", [1] = "again", [2] = "die"},
       maxProcesses = 5,
        statusInterval = 5
    
       }
    sync {
        default.rsync,
        source    = "/tmp/src_src",
        target    = "sync_user@192.168.31.130::sync_data",
        exclude   = { ".*", "*.tmp", "*.bak" },
        delete    = true,
        rsync     = {
            compress = false,
            archive  = true,
            verbose  = false,
            timeout  = 3600,
            password_file = "/usr/local/lsyncd/etc/rsync1.pass"
        }
    }
    sync {
        default.rsync,
        source = "/tmp/sync",
        target = "sync_user2@192.168.31.130::data_backup",
        exclude   = { ".*", "*.tmp", "*.bak" },
        delete    = true,
        rsync     = {
            compress = false,
            archive  = true,
            verbose  = false,
            timeout  = 3600,
            password_file = "/usr/local/lsyncd/etc/rsync2.pass"
        }
    }	
    
    # 配置认证密码,要求密码权限为400,否则rsync无法正常同步。
    [root@baseos-1_192.168.31.140 ~]# cat /usr/local/lsyncd/etc/rsync.pass 
    123456sync
    [root@baseos-1_192.168.31.140 ~]# cat /usr/local/lsyncd/etc/rsync2.pass
    654321sync
    

    目标机配置

    [root@baseos-2_192.168.31.130 ~]# vim /etc/rsyncd.conf 
    uid=root
    gid=root
    max connections=10
    log file=/var/log/rsyncd.log
    pid file=/var/run/rsyncd.pid
    lock file=/var/run/rsyncd.lock
    [sync_data]
    comment=backup data
    path=/tmp/src_dist
    read only=no
    exclude=test
    auth users=sync_user
    secrets file=/etc/rsyncd.passwd
    [data_backup]
    comment=backup data
    path=/tmp/sync
    read only=no
    auth users=sync_user2
    secrets file=/etc/rsyncd.passwd
    
    # 配置认证用户和密码                                                                                                                     
    [root@baseos-2_192.168.31.130 ~]# vim /etc/rsyncd.passwd 
    sync_user:123456sync
    sync_user2:654321sync
    

    启动lsyncd服务

    [root@baseos-1_192.168.31.140 ~]# /etc/init.d/lsyncd start
    Starting lsyncd:                                           [  OK  ]
    [root@baseos-1_192.168.31.140 ~]# cat /usr/local/lsyncd/logs/lsyncd.log 
    Tue Jun 27 14:09:09 2017 Normal: recursive startup rsync: /tmp/src_src/ -> sync_user@192.168.31.130::sync_data/ excluding
    .*
    *.tmp
    *.bak
    Tue Jun 27 14:09:09 2017 Normal: recursive startup rsync: /tmp/sync/ -> sync_user2@192.168.31.130::data_backup/ excluding
    .*
    *.tmp
    *.bak
    Tue Jun 27 14:09:09 2017 Normal: Startup of "/tmp/src_src/" finished.
    cannot delete non-empty directory: frontends/php/local
    cannot delete non-empty directory: frontends/php/local
    cannot delete non-empty directory: frontends/php/include
    cannot delete non-empty directory: frontends/php/include
    cannot delete non-empty directory: frontends/php/conf
    cannot delete non-empty directory: frontends/php/conf
    cannot delete non-empty directory: frontends/php/app
    cannot delete non-empty directory: frontends/php/app
    cannot delete non-empty directory: frontends/php
    cannot delete non-empty directory: frontends/php
    cannot delete non-empty directory: frontends
    Tue Jun 27 14:09:10 2017 Normal: Startup of "/tmp/sync/" finished.
    Tue Jun 27 14:10:19 2017 Normal: Calling rsync with filter-list of new/modified files/dirs
    /anaconda-ks.cfg
    /
    /install.log
    /install.log.syslog
    /ip_name_list.txt
    /mysql_login
    /name_list.txt
    /nginx_reload
    /nginx_start
    /php_reload
    /php_start
    /redis6000.login
    /redis6000.start
    /redis6000.stop
    /redis6001.login
    /redis6001.start
    /redis6001.stop
    Tue Jun 27 14:10:20 2017 Normal: Finished a list after exitcode: 0
    Tue Jun 27 14:20:09 2017 Normal: --- TERM signal, fading ---
    Tue Jun 27 14:22:45 2017 Normal: recursive startup rsync: /tmp/src_src/ -> sync_user@192.168.31.130::sync_data/ excluding
    .*
    *.tmp
    *.bak
    Tue Jun 27 14:22:45 2017 Normal: recursive startup rsync: /tmp/sync/ -> sync_user2@192.168.31.130::data_backup/ excluding
    .*
    *.tmp
    *.bak
    Tue Jun 27 14:22:46 2017 Normal: Startup of "/tmp/sync/" finished.
    Tue Jun 27 14:22:46 2017 Normal: Startup of "/tmp/src_src/" finished.
  • 相关阅读:
    Ubuntu 16.04安装Eclipse
    Ubuntu 16.04安装Maven
    Ubuntu 16.04安装Tomcat 8
    CentOS 7安装过程
    CentOS 6.9安装过程
    Linux磁盘分区方案(转)
    CentOS 6.9使用sudo时出现:“...不在 sudoers 文件中,此事将被报告”的问题解决
    VMware 12安装CentOS 6.9时出现:The centos disc was not found in any of your drives.Please insert the centos disc and press OK to retry
    Ubuntu源码下载方法
    汇编教程书籍收集
  • 原文地址:https://www.cnblogs.com/wshenjin/p/7084961.html
Copyright © 2020-2023  润新知