实时同步 Lsyncd

2020年6月19日

Ubuntu
#

sudo apt-get update
sudo apt-get install lsyncd

CentOS
#

yum -y update
yum -y install lsyncd

Running these commands will install Lsyncd as well as include some examples within the following directory /usr/share/doc/lsyncd/examples. These examples can be used to help get a better idea of the configuration possibles when using this synchronization method.
Setting up lsyncd over SSH with KeyCDN
#

Before getting started, you must first ensure that you have uploaded your public SSH key to the KeyCDN dashboard and added your private key on your system using ssh-add /path/to/your/private.key. If you do not yet have an SSH key pair, see our article on How to: Create SSH Key.

Once you have properly set up your SSH keys you can begin configuring your environment. To do this you must create lsyncd.log and lsyncd-status.log files in these respective directories

/var/log/lsyncd/lsyncd.log

and

/var/log/lsyncd/lsyncd-status.log

Once this is complete, you can then begin to set up your configuration file. There is no default configuration file, however you can create one in your /etc/lsyncd/lsyncd.conf.lua directory on your local machine and add the following information.

vim  /etc/lsyncd/lsyncd.conf.lua

settings {

   -- 日志文件存放位置
    logfile = "/var/log/lsyncd/lsyncd.log",
   -- 监控目录状态文件的存放位置
    statusFile = "/var/log/lsyncd/lsyncd-status.log",
    -- 指定要监控的事件,如,CloseWrite,Modify,CloseWrite or Modify
    inotifyMode = "CloseWrite or Modify",
   -- 指定同步时进程的最大个数
    maxProcesses = 10,
    -- 隔多少秒记录一次被监控目录的状态
    statusInterval = 10
    -- false=启用守护模式
    nodaemon = false,
   -- 当事件被命中累计多少次后才进行一次同步(即使间隔低于statusInterval)
    -- maxDelays = 20
}

-- 将 本地/home/temp/ 推送到 47.91.228.160:/var/log/nginx/  目录
sync {
    -- lsyncd运行模式
    -- default.direct=本地目录间同步
    -- default.rsync=使用rsync
    -- default.rsyncssh=使用rsync的ssh模式
    default.rsync,
    -- 同步的源目录
    source="/home/temp/",
    -- 同步的目标目录
    target="[email protected]:/var/log/nginx/",
    -- 是否同步删除 true=同步删除 false=增量备份
    delete = false,
    -- 忽略文件路径规则,可用table也可用外部配置文件
    -- excludeFrom = "/etc/lsyncd_exclude.lst",
    exclude = {
        ".*",
        ".svn",
        ".git",
    },
    -- 排除同步文件
    exclude = { ".*" },
    -- 等待rsync同步延时时间(秒)
    delay = 5,
    -- init=false则只同步lsyncd启动后变更,不设置则lsyncd启动后进行全量的同步
    --init = True,

    rsync = {
        archive = false,
        acls = false,
        chmod = "D2755,F644",
        compress = true,
        links = false,
        owner = false,
        perms = false,
        verbose = true,
        rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
    }
}

通过 Rsync 配置的范本
    rsync  = {
        -- 单位kb
        bwlimit=1000,
        binary = "/usr/bin/rsync",
        archive = true,
        compress = true,
        verbose = true,
           perms = true,
           -- rsync的用户密码,不是Linux系统的用户密码
        password_file = "/etc/lsyncd/rsync.passwd"
    }


重启服务

service  lsyncd  restart

 


原文链接:
https://www.keycdn.com/support/how-to-setup-lsyncd-over-ssh
https://www.cnblogs.com/imcati/p/10774194.html

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注