ubuntu18.04 nginx负载均衡 Lsyncd上传文件同步

1.两台服务器,配置互相免密码登录ssh
ssh-keygen -t rsa ##生成密钥
ssh-copy-id [email protected] #把秘钥拷贝到远程服务器,提示输入用户密码
Ctrl+D退出后,ssh [email protected],就可以不输密码登录了
2.安装Lsyncd
apt install lsyncd
首先,创建日志文件,用于跟踪。
mkdir /var/log/lsyncd
touch /var/log/lsyncd/lsyncd.{log,status}
然后,创建配置文件。
mkdir /etc/lsyncd
vim /etc/lsyncd/lsyncd.conf.lua
配置内容
settings{
logfile = “/var/log/lsyncd/lsyncd.log”,
statusFile = “/var/log/lsyncd/lsyncd.status”,
inotifyMode = “CloseWrite”,
maxProcesses = 10,
nodaemon = false,
maxDelays = 7
}
sync{
default.rsync,
source = “/var/www/html/public/ueditor”, ##源目录,当前配置文件所在的服务器
target = "[email protected]:/var/www/html/academy/public/ueditor",##目标目录
init = false,
delete = true,
delay = 3,
rsync = {
binary = “/usr/bin/rsync”,
compress = true,
archive = true,
verbose = true
}
}
sync{
default.rsync,
source = “/var/www/html/public/upload”,
target = "[email protected]:/var/www/html/academy/public/upload",
init = false,
delete = true,
delay = 3,
rsync = {
binary = “/usr/bin/rsync”,
compress = true,
archive = true,
verbose = true
}
}

3.重启
systemctl restart lsyncd
开机启动项
systemctl enable lsyncd.service
4.另一台服务器重复以上操作

参考:https://wzfou.com/lsyncd/

你可能感兴趣的:(ubuntu18.04 nginx负载均衡 Lsyncd上传文件同步)