Install Lsyncd Freebsd 12

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.

This article will discuss how to configure lsyncd to mirror changes between directories on a single machine and how to mirror between remote hosts.

Lsyncd Require Rsync

Installation – Server

Install the Rsync server from the ports collection.

# cd /usr/ports/net/rsync # make install clean # rehash

or Pkg install rsync

Configuration – Server

Modify the /usr/local/etc/rsyncd.conf file to reflect the following:

uid = nobody gid = nobody use chroot = no max connections = 4 syslog facility = local5 pid file = /var/run/rsyncd.pid

Cek Rsync

Then I started the rsync daemon and verified it was running by doing this:
# rsync --daemon
# ps auwx | grep rsync
root 4026 0.0 0.1 12408 2920 - Is 11:24 0:00.00 /usr/local/bin/rsync --daemon --config /usr/local/etc/rsync/rsyncd.conf
And I found this in /var/log/messages:
rsyncd[30114]: rsyncd version 2.3.2 starting
Then I verified that I could connect to the daemon by doing this:
# telnet localhost 873
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
@RSYNCD: 21


Finally, set the rsyncd to start at system boot time and run it for the first time.

# echo "rsyncd_enable=YES" >> /etc/rc.conf
# /usr/local/etc/rc.d/rsyncd start

Installation – Client  ( Target Server )

Install rsync from the ports collection.

# cd /usr/ports/net/rsync # make install clean
or Pkg install rsync
Modify the /usr/local/etc/rsyncd.conf file to reflect the following:
uid = nobody gid = nobody use chroot = no max connections = 4 syslog facility = local5 pid file = /var/run/rsyncd.pid



NEXT Install Lsyncd
To install the port: cd /usr/ports/sysutils/lsyncd/ && make install clean
To add the package: pkg install lsyncd

Edit Configuration file , /usr/local/etc/lsyncd.conf

settings {
logfile = "/var/log/lsyncd.log",
statusFile = "/var/log/lsyncd.status",
statusInterval = 1,
insist = 1,
}
sync {
default.rsync,
source="/home/tes",
target = "IP_Address_Target:/home/tes",
excludeFrom="/etc/lsyncd-excludes.txt", ## pengecualian folder
rsync = {
binary = "/usr/local/bin/rsync", #<-cek Daemon directory in ps auwx | grep rsync
compress = true,
acls = true,
verbose = true,
owner = true,
group = true,
perms = true,
rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
}
}

Save and Exit
add rc.conf

lsyncd_enable="YES"
rsyncd_enable="YES"

Restart /usr/local/etc/rc.d/lsyncd restart
cek status /usr/local/etc/rc.d/lsyncd status

Next Bypass SSH

Generate the SSH public keys
ssh-keygen -t rsa

Once it has completed, you will have 2 new files in ~/.ssh/ id_rsa and id_rsa.pub

cat ~/root/.ssh/ id_rsa.pub

Then copy the text content into your slave server and paste it inside this file:

nano -w ~/root/.ssh/authorized_keys

Test SSH connectivity
From the master server, ssh into each slave server, it may ask you to accept the key, just say “yes” and it will allow you to ssh into each slave without asking for root password.


Posted on: March 19, 2019, by :