A(192.168.5.11)服务器/data
实时同步到
B(192.168.5.12)服务器/data
A、B环境准备
安装
yum -y install lua lua-devel rsync lsyncd
连接数配置,编辑/etc/sysctl.cong
fs.inotify.max_user_watches=99999999
fs.inotify.max_queued_events=1638400
重载
sysctl -p
创建用户
useradd data
echo "gHYjhGHhjBhjy@533ds7HJ"|passwd --stdin data
创建目录,授权,关闭防火墙,关闭selinux
mkdir /data
chown data:data /data
systemctl stop firewalld.service
setenforce 0
A服务器配置,/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/lsyncd.log",statusFile ="/var/log/lsyncd/lsyncd.status",inotifyMode="CloseWrite",maxProcesses=8,}
sync {
default.rsync,
source = "/data",
target = "data@192.168.5.12::data",
-- delete = "running",
delete = true,
delay = 20,
-- init = true,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true,
password_file = "/etc/rsyncd.pwd",
}
}
密码文件,/etc/rsyncd.pwd
gHYjhGHhjBhjy@533ds7HJ
启动命令
systemctl restart lsyncd.service
B服务器配置,/etc/rsyncd.conf
uid = root
gid = root
use chroot = yes
#若为 true,则 rsync 在传输文件之前首先 chroot 到 path 参数所指定的目录下。这样做的原因是实现额外的安全防护
read only = no
# 设定白名单,可以指定IP段(10.197.44.1/255.255.255.0),各个Ip段用空格分开
# hosts allow = 10.197.44.12,10.197.44.13
#hosts allow = 61.144.25.125,61.144.25.118,219.137.24.213
hosts allow = *
hosts deny = *
max connections = 10
pid file = /var/run/rsyncd.pid
transfer logging = yes
# 日志文件格式
log format = %t %a %m %f %b
# 指定日志文件
log file = /var/log/rsync.log
# 剔除某些文件或目录,不同步
exclude = lost+found/
# 设置超时时间
timeout = 600
ignore nonreadable = yes
# 设置不需要压缩的文件
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
[data]
# 模块的根目录,同步目录,要注意权限
path = /data
list = no
ignore errors
comment = data web
auth users = data
secrets file = /etc/rsyncd.secrets
exclude = lost+found/ conf/ man/
账密文件,/etc/rsyncd.secrets
data:gHYjhGHhjBhjy@533ds7HJ
启动命令
systemctl restart rsyncd.service