[linux] lsyncd同步工具详解程序员
2023-06-13 09:20:02 时间
1.源主机root用户运行同步程序,backup用户验证目标主机;如果不想配密钥验证,同样支持密码验证,在运行时(nodaemon)提示输入或者在配置文件定义password_file参数。
生成密钥对(略),目标主机添加公钥,注意.ssh和密钥的属主权限 [[email protected] ~]# echo "yyy" /home/backup/.ssh/authorized_keys 源主机添加私钥 [[email protected] ~]# echo "xxx" /root/.ssh/backup_rsa [[email protected] ~]# chmod 600 /root/.ssh/backup_rsa 验证登录 [[email protected] ~]# ssh -i /root/.ssh/backup_rsa [email protected]
2.源主机安装lsyncd,修改配置文件
安装lsyncd之前先安装epel-release [[email protected] ~]# yum install -y lsyncd [[email protected] ~]# rpm -qa | grep lsyncd lsyncd-2.2.2-1.el7.x86_64 [[email protected] ~]# 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 = "[email protected]", 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 = "[email protected]:/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.源主机启动服务,看日志,目标主机检查文件同步
[[email protected] ~]# systemctl start lsyncd
单源多目标需求可参考
How to install and configure Lsyncd
1.单目录同步到多机器:
源主机目录/data/web/sh.your.com同步到多机器 172.16.2.104:/data/web/sh.your.com 172.16.2.105:/data/web/sh.your.com
2.多目录同步到相同机器:
源主机多目录 /data/web/resource.your.com /data/web/www.your.com 同步到相同机器 172.16.2.99:/data/backup/web/resource.your.com 172.16.2.99:/data/backup/web/www.your.com
[[email protected] ~]# 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", servers = { "[email protected]", "[email protected]", for _, server in ipairs(servers) do sync { default.rsyncssh, source = "/data/web/sh.your.com", host = server, targetdir = "/data/web/sh.your.com", delay = 5, rsync = { archive = true, compress = true, verbose = true, rsh = "ssh -o StrictHostKeyChecking=no -i /root/.ssh/backup_rsa", sites = { "resource.your.com", "www.your.com", for _, site in ipairs(sites) do sync { default.rsyncssh, source = "/data/web/" .. site, host = "[email protected]", targetdir = "/data/backup/web/" .. site, delay = 300, rsync = { archive = true, compress = true, verbose = true, rsh = "ssh -o StrictHostKeyChecking=no -i /root/.ssh/backup_rsa",
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/2412.html
服务器部署程序员系统优化网站设置运维相关文章
- Linux根目录下的重要文件(linux根目录文件)
- 系统Linux下如何挂载文件系统(linux挂载文件)
- Linux下网络抓包利器:Wireshark。(linux网络抓包工具)
- 命令在PHP中执行Linux命令的方法(php执行linux)
- 技术探索Linux系统内核的调试精髓(linux系统内核的调试)
- Linux下使用Yum本地源配置(linux配置本地yum源)
- 浅析Linux中的矢量绘图工具(linux画图工具)
- 映射Linux虚拟机端口映射:一种快速实现远程访问的方法(linux虚拟机端口)
- 系统DOS系统与Linux系统:彼此异同对比(dos系统与linux)
- :挑战Linux:拥抱未来的技术世界(学linux系统)
- Linux硬件检测:值得拥有的工具(linux硬件检测工具)
- 工具利用Linux图形化调试工具实现可靠软件调试(linux图形化调试)
- Linux时间同步:两台Linux服务器(两台linux的时间同步)
- Linux在多终端系统上的发展(linux多终端)
- Linux学习之路:自主成长(linux能自学吗)
- 深入探究Linux同步锁的机制与应用(linux同步锁)
- 深入了解Linux内核同步机制,掌握系统稳定技巧(linux内核同步机制)
- 开启Linux之旅:学习字符设备文件(linux 字符设备文件)
- Linux局域网时间同步,优化系统性能(linux局域网时间同步)
- Linux系统快速安装Get工具(linux 下载get)