实现多台服务器服务器之间的文件同步
安装步骤
yum install epel-release -y
yum install lsyncd -y
2台服务器之间做免密操作
ssh-keygen -t rsa -b 2048
ssh-copy-id username@remote_host
配置lsyncd /etc/lsyncd.conf
A服务器配置:
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/run/lsyncd/lsyncd.status",
statusInterval = 20,
}
sync {
default.rsyncssh,
source = "/root/a/",
host = "root@192.168.249.33",
targetdir = "/root/b/",
ssh = {
port = 22,
},
rsync = {
archive = true,
compress = true,
verbose = true,
},
delay = 5,
}
B服务器配置:
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/run/lsyncd/lsyncd.status",
statusInterval = 20,
}
sync {
default.rsyncssh,
source = "/root/b/",
host = "root@192.168.249.34",
targetdir = "/root/a/",
ssh = {
port = 22,
},
rsync = {
archive = true,
compress = true,
verbose = true,
},
delay = 5,
}
启动服务
systemctl restart lsyncd
效果展示


单台服务器目录同步
settings { logfile = "/var/log/lsyncd/lsyncd.log", statusFile = "/tmp/lsyncd.status", inotifyMode = "CloseWrite or Modify", } sync { default.direct, source = "/root/A/", target = "/root/B" }
浙公网安备 33010602011771号