INTRODUCTION
What is lsyncd?
When managing a web server or an application, there are many situations that require synchronization between directories. While a number of tools can help you accomplish this, lsyncd is a strong candidate.
For this guide, we will be using Centos 7 VPS, but any modern distribution should function in a similar way.
Step 1:Destination Server Setup
Install and configure rsync server on destination
yum -y install rsync xinetd
Step 2:Enable rsync in xinetd
Edit rsync config ,change like below:
vi /etc/xinetd.d/rsync
service rsync
{
disable= no
flags= IPv6
socket_type= stream
wait= no
user= root
server= /usr/bin/rsync
server_args= –daemon
log_on_failure+= USERID
}
Step 3:Start xinetd service
service xinetd start chkconfig xinetd on
Step 4:Add rsync module in /etc/rsyncd.conf
vi /etc/rsyncd.conf
[linuxcriptshub_w]
path = /var/www/html/
hosts allow = 123.456.78.90 ##>>Source server ip
hosts deny = *
list = true
uid = root
gid = root
read only = false
Step 5:Source Server Setup
Install lsyncd from EPEL
yum --enablerepo=epel -y install lsyncd
Step 6:Uncomment line #4 in /etc/sysconfig/lsyncd
vi /etc/sysconfig/lsyncd
# Keep the space there for systemd. Don’t nest variables without
# changing the systemd service file to use: /usr/bin/sh -c ‘eval XXXX’
#
LSYNCD_OPTIONS=”-pidfile /var/run/lsyncd.pid /etc/lsyncd.conf”
#LSYNCD_OPTIONS=” ”
#LSYNCD_USER=””
Step 7:Add this into lsyncd main config file
vi /etc/lsyncd.conf
settings{
logfile = “/var/log/lsyncd/lsyncd.log”,
statusFile = “/tmp/lsyncd.stat”,
statusInterval = 1,
}
sync{
default.rsync,
source=”/home/web/html/”, ##>>path you needed to sync
target=“123.456.789.91::linuxscriptshub_w/”, ##>>Destination Server ip
}
Step 8:Configure log rotation
vi /etc/logrotate.d/lsyncd
/var/log/lsyncd/*log {
missingok
notifempty
sharedscripts
postrotate
if [ -f /var/lock/lsyncd ]; then
/sbin/service lsyncd restart > /dev/null 2>/dev/null || true
fi
endscript
}
Final Step:Start the lsyncd service and enable the lsyncd service to start on boot
service lsyncd start chkconfig lsyncd on
Leave a Reply
Want to join the discussion?Feel free to contribute!