lsyncd 同步 Coredns 配置

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# /etc/lsyncd.conf
settings {
logfile ="/var/log/lsyncd/lsyncd.log",
statusFile ="/var/log/lsyncd/lsyncd.status",
inotifyMode = "CloseWrite",
maxProcesses = 8,
-- nodaemon = false,
}

-- 远程目录同步,rsync模式 + ssh shell

sync {
default.rsync,
-- 同步源目录(本机某个目录,必须保证该文件或目录在源服务器上存在,不然启动会报错)
source = "/etc/coredns/",
-- 同步目标地址和目标目录,注意target如果是普通需要有写权限,以上是将源服务器上/oafiles/目录下的所有文件同步到目标服务器的/hdd/test目录下
target = "root@10.113.75.19:/etc/coredns",
-- excludeFrom = "/etc/rsyncd.d/rsync_exclude.lst",
maxDelays = 1,
delay = 15,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
}
-- 在文件同步完成后执行的命令
postcmd = "/usr/bin/systemctl restart coredns" # 重启从服务器上的 CoreDNS 服务
}

启动

1
2
3
4
5
6
7
8
9
10
11
12
# /usr/lib/systemd/system/lsyncd.service
[Unit]
Description=Live Syncing (Mirror) Daemon
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/lsyncd
ExecStart=/usr/bin/lsyncd -nodaemon $LSYNCD_OPTIONS

[Install]
WantedBy=multi-user.target