[linux] lsyncd同步工具


 環境說明:

192.168.56.101 同步源
192.168.56.102 同步目標
操作系統centos 7
lsyncd項目地址:https://github.com/axkibe/lsyncd

  1.源主機root用戶運行同步程序,backup用戶驗證目標主機;如果不想配密鑰驗證,同樣支持密碼驗證,在運行時(nodaemon)提示輸入或者在配置文件定義password_file參數。

生成密鑰對(略),目標主機添加公鑰,注意.ssh和密鑰的屬主權限
[root@192.168.56.102 ~]# echo "yyy" > /home/backup/.ssh/authorized_keys

源主機添加私鑰
[root@192.168.56.101 ~]# echo "xxx" > /root/.ssh/backup_rsa
[root@192.168.56.101 ~]# chmod 600 /root/.ssh/backup_rsa
驗證登錄
[root@192.168.56.101 ~]# ssh -i /root/.ssh/backup_rsa backup@192.168.56.102

 

  2.源主機安裝lsyncd,修改配置文件

安裝lsyncd之前先安裝epel-release
[root@192.168.56.101 ~]# yum install -y lsyncd
[root@192.168.56.101 ~]# rpm -qa | grep lsyncd
lsyncd-2.2.2-1.el7.x86_64
[root@192.168.56.101 ~]# cat /etc/lsyncd.conf 
----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
-- 
settings {
  logfile    = "/var/log/lsyncd.log",
  statusFile = "/var/log/lsyncd.status",
}

sync {
  default.rsyncssh,
  source     = "/data/web/web1",
  host       = "backup@192.168.56.102",
  targetdir  = "/data/backup/web/web1",
  -- 10秒同步一次,默認15秒
  delay      = 10,
  rsync = {
    archive  = true,
    compress = true,
    verbose  = true,
    rsh      = "ssh -o StrictHostKeyChecking=no -i /root/.ssh/backup_rsa",
  }
}

sync {
  default.rsync,
  source     = "/data/web/web2",
  target     = "backup@192.168.56.102:/data/backup/web/web2",
  rsync = {
    archive  = true,
    compress = true,
    verbose  = true,
    rsh      = "ssh -o StrictHostKeyChecking=no -i /root/.ssh/backup_rsa",
    --_extra   = {"-e","ssh -o StrictHostKeyChecking=no","-e ssh -i /root/.ssh/backup_rsa"}
  }
}

  3.源主機啟動服務,看日志,目標主機檢查文件同步

[root@192.168.56.101 ~]# systemctl start lsyncd

 

單源多目標需求可參考

https://www.stephenrlang.com/2015/12/how-to-install-and-configure-lsyncd/


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com