Bidirectional file sync in RHEL 8 (csync2 + lsyncd)
Posted wemux
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Bidirectional file sync in RHEL 8 (csync2 + lsyncd)相关的知识,希望对你有一定的参考价值。
Csync2 installation and setup
Add below to /etc/hosts
10.30.11.11 app1
10.30.11.12 app2
10.30.11.13 app3
Install Csync2 Repository
rpm -ivh http://repo.okay.com.mx/centos/8/x86_64/release/okay-release-1-5.el8.noarch.rpm
install required packages
yum install xinetd sqlite-devel csync2
create backup directory
mkdir -p /var/csync2/backup
create the authentication key on app1
csync2 -k /etc/csync2.key
add below content to the configuration file /etc/csync2_ebanking.cfg
nossl * *;
group ebanking_media
host app1 app2 pp3;
key /etc/csync2.key;
include /mnt/ebanking_media;
auto younger;
backup-directory /var/csync2/backup;
backup-generations 3;
Copy authentication key and configuration files to all servers
scp /etc/sync2.key,csync2_ebanking.cfg bda-cbs-ebprdapp2:/etc/
scp /etc/sync2.key,csync2_ebanking.cfg bda-cbs-ebprdapp3:/etc/
Lsyncd installation and setup
Install EPEL Repository
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
update the system
dnf update -y
Search for the lsyncd package
dnf --disablerepo="*" --enablerepo="epel" list available | grep lsyncd
Install lsyncd package
dnf install lsyncd
add below to /etc/lsyncd.conf with each servers
----
-- 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/
--
-- syncdefault.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"
settings
logident = "lsyncd",
logfacility = "user",
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/status.log",
statusInterval = 1
initSync =
delay = 1,
maxProcesses = 1,
action = function(inlet)
local config = inlet.getConfig()
local elist = inlet.getEvents(function(event)
return event.etype ~= "Init"
end)
local directory = string.sub(config.source, 1, -2)
local paths = elist.getPaths(function(etype, path)
return "\\t" .. config.syncid .. ":" .. directory .. path
end)
log("Normal", "Processing syncing list:\\n", table.concat(paths, "\\n"))
spawn(elist, "/usr/sbin/csync2", "-C", config.syncid, "-x")
end,
collect = function(agent, exitcode)
local config = agent.config
if not agent.isList and agent.etype == "Init" then
if exitcode == 0 then
log("Normal", "Startup of ", config.syncid, " instance finished.")
elseif config.exitcodes and config.exitcodes[exitcode] == "again" then
log("Normal", "Retrying startup of ", config.syncid, " instance.")
return "again"
else
log("Error", "Failure on startup of ", config.syncid, " instance.")
terminate(-1)
end
return
end
local rc = config.exitcodes and config.exitcodes[exitcode]
if rc == "die" then
return rc
end
if agent.isList then
if rc == "again" then
log("Normal", "Retrying events list on exitcode = ", exitcode)
else
log("Normal", "Finished events list = ", exitcode)
end
else
if rc == "again" then
log("Normal", "Retrying ", agent.etype, " on ", agent.sourcePath, " = ", exitcode)
else
log("Normal", "Finished ", agent.etype, " on ", agent.sourcePath, " = ", exitcode)
end
end
return rc
end,
init = function(event)
local inlet = event.inlet;
local config = inlet.getConfig();
log("Normal", "Recursive startup sync: ", config.syncid, ":", config.source)
spawn(event, "/usr/sbin/csync2", "-C", config.syncid, "-x")
end,
prepare = function(config)
if not config.syncid then
error("Missing syncid parameter.", 4)
end
local c = "csync2_" .. config.syncid .. ".cfg"
local f, err = io.open("/etc/" .. c, "r")
if not f then
error("Invalid syncid parameter: " .. err, 4)
end
f:close()
end
local sources =
["/mnt/ebanking_media"] = "ebanking"
for key, value in pairs(sources) do
sync initSync, source=key, syncid=value
end
Start and enable xinetd and lsyncd services
systemctl enable -- now xinetd
systemctl enable -- now lsyncd
以上是关于Bidirectional file sync in RHEL 8 (csync2 + lsyncd)的主要内容,如果未能解决你的问题,请参考以下文章
ADAPTIVE LOG FILE SYNC 引起的高Log File Sync警示
Introducing Microsoft Sync Framework: Sync Services for File Systems