working instruction instalation sinkronisasi direktori lsyncd
DESCRIPTION
sinkronisasi direktory menggunakan lsyncdTRANSCRIPT
Febi Gelar Ramadhan.boksi-learning.co.id 2014
Page 1
SINKRONISASI DIREKTORI DENGAN LSYNCD
PENDAHULUAN
Lsyncd adalah salah satu tool untuk sionkronisasi direktori antar host dimana sesama host
bisa mempunyai direktori yang sama, master akan langsung menyalin file atau isi-isi apa
saja yang di atur supaya nampak pada direktory host pada slave sesuai direktori yang
diarahkan.
LANGKAH KERJA
1. pertama buat ssh-keygen, berfungsi untuk saling mengenalkan sesama host dan
menjadikan sesama hsot bisa saling remote atau ssh tanpa menggunakan
authentication atau password
[root@web1 ~]#ssh-keygen –t rsa
2. Tekan “enter” sampai selesai. Dan tunggu sampai ssh-keygen terbuat. (file default :
/root/.sshd/id_rsa.pub).
3. Sesudah file ssh-keygen terbuat, salin filenya ke client untuk menghilangkan
authentikasi (ssh)
[root@web1 ~]#scp /root/.ssh/id_rsa.pub (username_client)@(ip_client):/root/.ssh/
4. Jika file ssh-keygen sudah ada pada client, kita masuk pada host client dan
tampilkan/pindahkan menjadi “authorized_keys”
[root@web2 ~]#cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys
[root@web2 ~]#chmod 700 ~/.ssh/
[root@web2 ~]#chmod 600 ~/.ssh/*
5. Jika sudah pastikan dan cek dari host (web1) bisa remote ke host (web2) tanpa
authentikasi atau tanpa memasukan password, jika sudah bisa ssh-keygen sudah
berhasil.
6. Setelah host (web2) bisa di remote tanpa authentikasi, kita installkan packet-packet
yang dibutuhkan lsyncd.
Febi Gelar Ramadhan.boksi-learning.co.id 2014
Page 2
[root@web1 ~]#yum install lua lua-devel pkgconfig gcc rsync wget
7. Setelah itu kita download packet instalasi lsyncd dengan perintah “wget”.
[root@web1 ~]#wget https://lsyncd.googlecode.com/files/lsyncd-2.1.5.tar.gz
8. Ekstrak dan Compile file lsyncd yang sudah kita download tersebut
[root@web1 ~]#tar zxvf lsyncd-2.1.5.tar.gz
[root@web1 ~]#cd lsyncd-2.1.5
[root@web1 ~]#./configure && make && make install
9. Buat file baru untuk script lsyncd daemon
[root@web1 ~]#vi /etc/init.d/lysncd
10. Dan masukan script settingan daemon lsyncd berikut
#!/bin/bash
#
# lsyncd: Starts the lsync Daemon
#
# chkconfig: 345 99 90
# description: Lsyncd uses rsync to synchronize local directories with a remote
# machine running rsyncd. Lsyncd watches multiple directories
# trees through inotify. The first step after adding the watches
# is to, rsync all directories with the remote host, and then sync
# single file buy collecting the inotify events.
# processname: lsyncd
. /etc/rc.d/init.d/functions
config="/etc/lsyncd.lua"
lsyncd="/usr/local/bin/lsyncd"
lockfile="/var/lock/subsys/lsyncd"
prog="lsyncd"
RETVAL=0
start() {
if [ -f $lockfile ]; then
echo -n $"$prog is already running: "
Febi Gelar Ramadhan.boksi-learning.co.id 2014
Page 3
echo
else
echo -n $"Starting $prog: "
daemon $lsyncd $config
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $lockfile
return $RETVAL
fi
}
stop() {
echo -n $"Stopping $prog: "
killproc $lsyncd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $lockfile
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $lsyncd
;;
*)
echo "Usage: lsyncd {start|stop|restart|status}"
Febi Gelar Ramadhan.boksi-learning.co.id 2014
Page 4
exit 1
esac
exit $?
11. Setelah script daemon lsyncd sudah dimasukan kita masuk pada pengaturan
permissionnya.
[root@web1 ~]# chmod 775 /etc/init.d/lsyncd
[root@web1 ~]# chown root:root /etc/init.d/lsyncd
12. Sesuai script yang sudah kita masukan, kita buat file konfigurasi “lsyncd.lua” dan
masukan script seperti berikut :
[root@web1 ~]#vi /etc/lsyncd.lua
Dan masukan scripnya (contoh) :
settings {
logfile = "/tmp/lsyncd.log",
statusFile = "/tmp/lsyncd.status",
init = false,
}
sync{
default.rsyncssh,
source="/opt/",
host="172.17.17.9",
targetdir="/opt/",
}
13. Dan terakhir nyalakan service “lsyncd”
[root@web1 ~]#/etc/init.d/lsyncd start
[root@web1 ~]#chkconfig lsyncd on
14. Pengaturan sudah selesai, bisa disimpulkan settingannya berfungsin untuk setiap
apa yang ada di direktory “/opt/” nya master (web1) akan ada pula di “/opt” nya
slave (web2) dan memerlukan waktu beberapa detik untuk supaya file tersalin pada
client (web2).