• 实时同步lsyncd


    要求rsync >= 3.1

    rsync --version
    systemctl status rsyncd
    
    1.安装lsyncd
    yum install -y lsyncd
    lsyncd --version
    2.创建日志文件
    mkdir /var/log/lsyncd
    touch /var/log/lsyncd/lsyncd.{log,status}
    3.创建配置文件
    mkdir -p /etc/lsyncd
    vim /etc/lsyncd.conf
    4.配置文件写入以下内容:
    settings {
            logfile = "/var/log/lsyncd/lsyncd.log",
            statusFile = "/var/log/lsyncd/lsyncd.status",
    		pidfile = "/var/run/lsyncd.pid",
    		statusInterval = 1,
    		nodaemon = false,
    		maxProcesses = 1,
    		maxDelays = 1,		
    }
    #本地同步 
    sync {
            default.rsync,
            source = "/data/source",
            target = "/data/target",
        }
    #rsync+ssh远程目录同步,需要免key登录
    sync {
       default.rsyncssh,
       source="/data/source",
       delete = true,
       host="root@192.168.15.6",
       targetdir="/data/target",
       -- 忽略文件路径规则,可用table也可用外部配置文件
       -- excludeFrom = "/etc/lsyncd_exclude.lst",
       exclude={
            ".txt"            --需排除的文件
        },
       rsync = {
           binary = "/usr/bin/rsync", --需先安装好rsync
           archive = true,            --归档
           compress = false,          --压缩
           owner = true,              --属主
           perms = true,              --权限
           whole_file = false
           },
       ssh = {
           port = 22
       }
    }
    #rsync-daemon模式,需要配置好rsync的服务端
    sync {
        default.rsync,
        source = "/data/source",
        target = "rsync_user@192.168.15.6::backup",
        exclude = { ".bak*" },
    	delete = true,
        delay = 30,
        init = true,
        rsync = {
            binary = "/usr/bin/rsync",
            archive = true,
            compress = true,
            verbose = true,
            perms = true,
            password_file = "/etc/rsync.password", 
            _extra = {"--bwlimit=200"}    --bwlimit 限速,单位kb/s,
        }
    }
    5.启动lsyncd服务
    lsyncd -nodaemon /etc/lsyncd.conf
    systemctl restart lsyncd
    systemctl enable lsyncd
    6.rsync-daemon模式
    #lsyncd端配置
    vim /etc/rsync.password
    echo "1234567" > /etc/rsync.password
    chmod 600 /etc/rsync.password
    #rsync服务端配置
    安装rsync
    vim /etc/rsyncd.conf
    uid = root
    gid = root
    use chroot = no
    strict modes = no
    max connections = 100
    charset=utf8
    log file = /var/log/rsyncd.log
    pid file = /var/run/rsyncd.pid
    hosts allow = 192.168.15.20
    hosts deny = *
    [backup]
    path = /data/target/
    read only = no
    write only = no
    list = no
    exclude = .svn/
    dont compress = *.gz *.tgz *.zip *.z *.bz2 *.tbz
    auth users = rsync_user
    secrets file = /etc/rsync/rsync.pass
    
    echo 'rsync_user:123456'>/etc/rsync/rsync.pass
    chmod 600 /etc/rsync/rsync.pass
    
    #rsync用法
    rsync -auv --password-file=/etc/rsync.password --delete /data/source/ rsync_user@192.168.15.6::backup
    #lsyncd delete -- 用法如下
    https://axkibe.github.io/lsyncd/manual/config/layer4/
    
  • 相关阅读:
    $_SERVER
    下面介绍mysql中模糊查询的四种用法:
    qq第三方登录
    远程连接数据库出错
    lnmp中的tp的pathinfo模式
    TP5配置所谓的url_moudel
    tp3.2.3中的xss攻击基本防护
    tp中的Csv文件读取(原创)
    mysql语句整理
    SVN的详细使用
  • 原文地址:https://www.cnblogs.com/kylingx/p/12013228.html
Copyright © 2020-2023  润新知