将本地文件夹/home/wt/remote_dirs/codes_in_vr
的内容实时同步到远程的/home/wt/codes
文件夹。
Lsyncd:负载均衡之后,服务器的文件双向同步
本地安装lsyncd
sudo apt install lsyncd
sudo mkdir /etc/lsyncd
cd /etc/lsyncd
sudo vim lsyncd.conf
写入下面的代码,--是Lua语言的注释符号
sync {
default.rsyncssh,
source = "/home/wt/remote_dirs/codes_in_vr",
host = "远程服务器ip",
targetdir = "/home/wt/codes",
--excludeFrom = "/etc/rsyncd.d/rsync_exclude.lst",
-- maxDelays = 5,
delay = 0,
-- init = false,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true,
_extra = {"--bwlimit=2000"},
},
ssh = {
port = 22
}
}
lsyncd.conf可以有多个sync,各自的source,各自的target,各自的模式,互不影响。
配置本地ssh无密码访问远程服务器,
加载lsyncd配置:
lsyncd -log Exec /etc/lsyncd/lsyncd.conf
重启lsyncd服务:
sudo systemctl restart lsyncd
网友评论