Skip to content

Commit e9efe03

Browse files
rootroot
authored andcommitted
penambahan artikel baru by hamim
1 parent b622629 commit e9efe03

5 files changed

Lines changed: 201 additions & 0 deletions

File tree

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
---
2+
layout: post
3+
title: "Lsyncd Untuk Sinkronisasi File dan Direktori Pada Server CentOS 7"
4+
date: 2019-10-08 00:00:00
5+
author: Nur Hamim
6+
categories: blog
7+
tags: lsyncd rsync linux centos
8+
---
9+
10+
### PENDAHULUAN
11+
12+
Lsyncd singkatan dari "Live Syncing Daemon", sebuah service yang digunakan untuk menyinkronkan atau mereplikasi file dan direktori secara lokal dan jarak jauh setelah interval waktu tertentu menggunakan rsync dan ssh di backend untuk authentication.
13+
14+
Apa bedanya dengan rsync?
15+
16+
Apabila Anda menggunakan rsync Anda perlu "job" sebagai perintah untuk sinkronisasi, dengan lsyncd Anda tidak perlu membuat "cron job" untuk menjalankan sinkronisasi.
17+
18+
Lsyncd bekerja pada arsitektur Master dan Slave di mana ia memantau direktori pada server master, jika ada perubahan atau modifikasi yang dilakukan maka lsyncd akan mereplikasi yang sama pada server slave-nya setelah interval waktu tertentu.
19+
20+
Berikut topologi yang akan digunakan pada panduan ini:
21+
22+
![Topologi](/assets/images/topologi-lsyncd.jpg)
23+
24+
**Kebutuhan:**
25+
26+
- OS: CentOS 7
27+
- Srv-prod - IP: 10.10.1.11
28+
- Srv-Backup - IP: 10.10.1.7
29+
- Direktori yang akan di sinkronasi "/var/www/html"
30+
31+
**LANGKAH KERJA**
32+
33+
**Langkah 1**
34+
35+
Silakan login pada "srv-prod" dan setup ssh key authentication
36+
37+
```
38+
[root@srv-prod ~]# ssh-keygen -t rsa
39+
```
40+
41+
Copy publik key ke server tujuan "srv-backup"
42+
43+
```
44+
[root@srv-prod ~]# ssh-keygen -t rsa
45+
```
46+
Untuk memastikan silakan akses ssh dari "srv-prod" ke "srv-backup"
47+
48+
```
49+
[root@srv-prod ~]# ssh root@10.10.1.7
50+
```
51+
52+
**Langkah 2**
53+
54+
Instalasi lsyncd pada CentOS 7 menggunakan perintah berikut
55+
56+
```
57+
[root@srv-prod ~]# yum install epel-release
58+
[root@srv-prod ~]# yum install lsyncd -y
59+
```
60+
Buka file **/etc/lsyncd.conf** untuk melakukan konfigurasi
61+
62+
```
63+
----
64+
-- User configuration file for lsyncd.
65+
--
66+
-- Simple example for default rsync, but executing moves through on the target.
67+
--
68+
-- For more examples, see /usr/share/doc/lsyncd*/examples/
69+
--
70+
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}
71+
72+
settings {
73+
logfile = "/var/log/lsyncd/lsyncd.log",
74+
statusFile = "/tmp/lsyncd.stat",
75+
statusInterval = 1,
76+
}
77+
78+
sync {
79+
default.rsync,
80+
source = "/var/www/html",
81+
target = "10.10.1.7:/var/www/html",
82+
}
83+
84+
rsync = {
85+
update = true,
86+
perms = true,
87+
owner = true,
88+
group = true,
89+
rsh = "/usr/bin/ssh -l root -i /root/.ssh/id_rsa"
90+
}
91+
```
92+
93+
Silakan sesuaikan "source" yang akan di backup dan "target" server backup nya. Untuk konfigurasi di atas dapat Anda sesuaikan dengan kebutuhan dan Anda dapat explore nya melalui link berikut: [**The Configuration File**](https://axkibe.github.io/lsyncd/manual/config/file/)
94+
95+
Selanjutnya silakan start dan enable service lsyncd, pastikan statusnya running sebagai berikut:
96+
97+
```
98+
[root@srv-prod ~]#
99+
[root@srv-prod ~]# systemctl enable lsyncd
100+
[root@srv-prod ~]# systemctl start lsyncd
101+
[root@srv-prod ~]# systemctl status lsyncd
102+
● lsyncd.service - Live Syncing (Mirror) Daemon
103+
Loaded: loaded (/usr/lib/systemd/system/lsyncd.service; enabled; vendor preset: disabled)
104+
Active: active (running) since Sat 2019-10-26 16:37:47 UTC; 26s ago
105+
Main PID: 9457 (lsyncd)
106+
CGroup: /system.slice/lsyncd.service
107+
└─9457 /usr/bin/lsyncd -nodaemon /etc/lsyncd.conf
108+
109+
Oct 26 16:37:47 srv-prod systemd[1]: Started Live Syncing (Mirror) Daemon.
110+
[root@srv-prod ~]#
111+
```
112+
**Langkah 3**
113+
114+
Memastikan lsyncd telah berjalan dengan sempurna, silakan membuat file atau direktori pada "/var/www/html" dan pastikan di sisi server target "srv-backup" telah ada file tersebut di direktori "/var/www/html"
115+
116+
```
117+
[root@srv-prod ~]#
118+
[root@srv-prod ~]# cd /var/www/html/
119+
[root@srv-prod html]#
120+
[root@srv-prod html]# touch klim.txt
121+
[root@srv-prod html]# mkdir klim-mantap
122+
[root@srv-prod html]# dd if=/dev/zero of=piye-rek.html count=1024 bs=1024
123+
1024+0 records in
124+
1024+0 records out
125+
1048576 bytes (1.0 MB) copied, 0.00219632 s, 477 MB/s
126+
[root@srv-prod html]#
127+
[root@srv-prod html]# ls
128+
klim-mantap klim.txt piye-rek.html
129+
[root@srv-prod html]#
130+
```
131+
![Create File](/assets/images/srv-prod.png)
132+
133+
Akses server backup dan pastikan file telah ada seperti berikut
134+
135+
```
136+
[root@srv-backup ~]#
137+
[root@srv-backup ~]# cd /var/www/html/
138+
[root@srv-backup html]# ls
139+
klim-mantap klim.txt piye-rek.html
140+
[root@srv-backup html]#
141+
```
142+
![Hasil Backup File](/assets/images/srv-backup.png)
143+
144+
Memberikan permission pada file "piye-rek.html" menjadi 755
145+
146+
```
147+
[root@srv-prod html]#
148+
[root@srv-prod html]# chmod 755 piye-rek.html
149+
[root@srv-prod html]# ls -lah
150+
total 1.0M
151+
drwxr-xr-x. 3 root root 62 Oct 26 16:41 .
152+
drwxr-xr-x. 4 root root 33 Oct 26 09:49 ..
153+
drwxr-xr-x 2 root root 6 Oct 26 16:41 klim-mantap
154+
-rw-r--r-- 1 root root 0 Oct 26 16:41 klim.txt
155+
-rwxr-xr-x 1 root root 1.0M Oct 26 16:41 piye-rek.html
156+
[root@srv-prod html]#
157+
```
158+
159+
![Set Permission File](/assets/images/srv-prod-set.png)
160+
161+
Pastikan di server backup juga berubah menyesuaikan server prod seperti berikut hasilnya
162+
163+
[root@srv-backup html]#
164+
[root@srv-backup html]# ls -lah
165+
total 0
166+
drwxr-xr-x. 3 root root 62 Oct 26 16:51 .
167+
drwxr-xr-x. 4 root root 33 Oct 26 10:10 ..
168+
drwxr-xr-x 2 root root 6 Oct 26 16:41 klim-mantap
169+
-rw-r--r-- 1 root root 0 Oct 26 16:41 klim.txt
170+
-rwxr-xr-x 1 root root 0 Oct 26 16:51 piye-rek.html
171+
[root@srv-backup html]#
172+
173+
![Hasil Perubahan File](/assets/images/srv-backup-set.png)
174+
175+
Selanjtunya melihat log pengiriman atau perubahan yang telah di lakukan di sisi srv-prod sebagai berikut
176+
177+
```
178+
[root@srv-prod html]#
179+
[root@srv-prod html]# tail -f 10 /var/log/lsyncd/lsyncd.log
180+
tail: cannot open '10' for reading: No such file or directory
181+
==> /var/log/lsyncd/lsyncd.log <==
182+
/klim-mantap/
183+
Sat Oct 26 16:54:51 2019 Normal: Finished a list after exitcode: 0
184+
Sat Oct 26 16:55:14 2019 Normal: Calling rsync with filter-list of new/modified files/dirs
185+
/piye-rek.html
186+
/
187+
Sat Oct 26 16:55:14 2019 Normal: Finished a list after exitcode: 0
188+
Sat Oct 26 16:55:45 2019 Normal: Calling rsync with filter-list of new/modified files/dirs
189+
/piye-rek.html
190+
/
191+
Sat Oct 26 16:55:45 2019 Normal: Finished a list after exitcode: 0
192+
```
193+
Saat ini lsyncd telah berjalan dengan normal.
194+
195+
Sekian panduan terkait sinkronisasi file dan direktori pada server CentOS 7.
196+
197+
---
198+
199+
**Referensi:**
200+
201+
- [**Lsyncd - Live Syncing (Mirror) Daemon**](https://axkibe.github.io/lsyncd/)

assets/images/srv-backup-set.png

8.04 KB
Loading

assets/images/srv-backup.png

8.52 KB
Loading

assets/images/srv-prod-set.png

9.08 KB
Loading

assets/images/srv-prod.png

16.4 KB
Loading

0 commit comments

Comments
 (0)