Cara Membuat File Syncronizer pada dua Raspberry Pi menggunakan Unison

Cara Membuat File Syncronizer  pada dua Raspberry Pi menggunakan Unison

Cara Membuat File Syncronizer  pada dua Raspberry Pi menggunakan Unison
File Syncronizer On Raspberry Pi
Assalamu'alaikum wr wb

Projects Raspberry pada kali ini kita akan membahas bagaimana caranya membuat File Syncronizer  pada dua Raspberry Pi menggunakan Unison. Cara ini sering dipakai oleh Instansi-instansi untuk menyelamatkan data pada server, dengan cara auto syncron. jadi apabila terjadi musibah pada server pertama, masih ada backup pada server kedua. sangat menarik membahas alat embedded system ini, yang mana dengan komputer mini yang disebut dengan raspi, kita dapat melakukan hal apa saja yang kita inginkan, tetapi alat ini juga ada batasannya sih, semuanya tergantung kita mau digunakan untuk apa. berikut adalah alat yang dibutuhkan untuk membuat File Syncronizer  pada dua Raspberry Pi menggunakan Unison.

  • 2 buah Raspberry Pi
  • Kabel Ethernet
  • Wifi Adapter
  • SD Card Min 4 gb
  • 2 buah Power Suply & Micro Usb Cable
Baiklah langkah yang pertama, pastikan anda sudah menginstall Raspbian, untuk penginstallan Raspbian anda bisa lihat di mari : cara install Raspbian pada Raspberry Pi.

Langsung saja kita akan memulai langkah-langkah untuk membuat File Syncronizer  pada dua Raspberry Pi menggunakan Unison.

Langkah 1 : Catatan Awal
sebelum kita memulai instalasi Unison, kita harus memastikan hal-hal berikut :

IP Server01 : 192.168.1.1 --> Raspberry Pi pertama
IP Server02 : 192.168.1.2 --> Raspberry Pi kedua

kita akan membuat File Syncronizer antara dua server didalam folder /usr/share/nginx/www. Kita akan menjalankan Unison sebagai user root di tutorial ini sehingga Unison memiliki izin yang memadai untuk melakukan File Syncronizer pengguna dan grup perizinan.

Langkah 2 : Menginstall Web Server (Nginx

sebelum kita menginstall Unison, terlebih dahulu kita harus menginstall Web Server (Nginx). berikut langkah - langkahnya :
#apt-get install nginx
 selanjutnya, kita restart Web Server :
#service nginx restart
 lakukan perintah tersebut pada server01 dan server02.

Langkah 3 : Menginstall Unison

selanjutnya, kita menginstall Unison pada server01 dan server02. berikut perintahnya :
#apt-get install unison 
Langkah 4 : Membuat Public Key Pair pada Server01

lakukan perintah ini pada server01. berikut perintahnya :
#ssh-keygen -t dsa
root@server01:~# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
 <-- ENTER
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
 <-- ENTER
Enter same passphrase again: <-- ENTER
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
ba:82:e1:a1:42:9b:d4:c8:99:c8:bd:8b:7d:4d:d4:66 root@server01
The key's randomart image is:
+---[DSA 1024]----+
| |
| |
| . |
| . E |
|+ * . S |
|.Ooo o |
|ooo+. + |
|oo=... o |
|.. oo.. |
+-----------------+
root@server01:~#

sekarang kita copy public key ke server02. berikut perintahnya :
#ssh-copy-id -i $HOME/.ssh/id_dsa.pub root@192.168.1.2
The authenticity of host '192.168.1.102 (192.168.1.102)' can't be established.
ECDSA key fingerprint is 51:7f:b4:ed:bd:e3:fc:16:2f:55:5c:e1:2c:d7:3d:a9.
Are you sure you want to continue connecting (yes/no)? <-- yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.1.2's password: <-- server02 root password
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.1.2'"
and check to make sure that only the key(s) you wanted were added.
selanjutnya, kita akan melihat file yang sudah di copy pada server02. berikut perintahnya :
#cat $HOME/.ssh/authorized_keys

 Langkah 5 : Menjalankan Unison

sekarang kita akan menjalankan Unison untuk File Syncronizer dalam folder /usr/share/nginx/www. perintah ini dilakukan pada server01. berikut perintahnya :

#unison /usr/share/nginx/www ssh://192.168.1.2//usr/share/nginx/www
root@server01:/usr/share/nginx/www# unison /usr/share/nginx/www ssh://192.168.1.2//usr/share/nginx/www
Contacting server...
Connected [//server01//var/www -> //server02//var/www]
Looking for changes
Warning: No archive files were found for these roots, whose canonical names are:
/usr/share/nginx/www
//server02//usr/share/nginx/www
This can happen either
because this is the first time you have synchronized these roots,
or because you have upgraded Unison to a new version with a different
archive format.
Update detection may take a while on this run if the replicas are
large.
Unison will assume that the 'last synchronized state' of both replicas
was completely empty. This means that any files that are different
will be reported as conflicts, and any files that exist only on one
replica will be judged as new and propagated to the other replica.
If the two replicas are identical, then no changes will be reported.
If you see this message repeatedly, it may be because one of your machines
is getting its address from DHCP, which is causing its host name to change
between synchronizations. See the documentation for the UNISONLOCALHOSTNAME
environment variable for advice on how to correct this.
Donations to the Unison project are gratefully accepted:
http://www.cis.upenn.edu/~bcpierce/unison
Press return to continue.[<spc>] <-- Tekan Enter
Waiting for changes from server
Reconciling changes
local server02
dir ----> example.com [f] <-- Tekan Enter
dir ----> example.de [f] <-- Tekan  Enter
Proceed with propagating updates? [] <-- Enter "y"
Propagating updates

UNISON 2.40.102 started propagating changes at 10:18:18.94 on 25 Sep 2015
[BGN] Copying example.com from /usr/share/nginx/www to //server02//usr/share/nginx/www
[BGN] Copying example.de from /usr/share/nginx/www to //server02//usr/share/nginx/www
Shortcut: copied /usr/share/nginx/www/example.de/web/index.html from local file/usr/share/nginx/www /.unison.example.com.d3783bddaaf59b9ba4d2ed0433f9db63.unison.tmp/web/index.html
[END] Copying example.de
[END] Copying example.com
UNISON 2.40.102 finished propagating changes at 10:17:17.94 on 25 Sep 2015

Saving synchronizer state
Synchronization complete at 10:17:17 (2 items transferred, 0 skipped, 0 failed)
selanjutnya kita akan mengubah file yang terdapat didalam /root/.unison/default.prf. berikut perintahnya :

#nano /root/.unison/default.prf
berikut adalah isi file yang harus ditambah :
# Roots of the synchronization
root = /usr/share/nginx/www
root = ssh://192.168.1.2//usr/share/nginx/www

# Paths to synchronize
#path = current
#path = common
#path = .netscape/bookmarks.html

# Some regexps specifying names and paths to ignore
#ignore = Path stats    ## ignores /var/www/stats
#ignore = Path stats/*  ## ignores /var/www/stats/*
#ignore = Path */stats  ## ignores /var/www/somedir/stats, but not /var/www/a/b/c/stats
#ignore = Name *stats   ## ignores all files/directories that end with "stats"
#ignore = Name stats*   ## ignores all files/directories that begin with "stats"
#ignore = Name *.tmp    ## ignores all files with the extension .tmp

#          When set to true, this flag causes the user interface to skip
#          asking for confirmations on non-conflicting changes. (More
#          precisely, when the user interface is done setting the
#          propagation direction for one entry and is about to move to the
#          next, it will skip over all non-conflicting entries and go
#          directly to the next conflict.)
auto=true

#          When this is set to true, the user interface will ask no
#          questions at all. Non-conflicting changes will be propagated;
#          conflicts will be skipped.
batch=true

#          !When this is set to true, Unison will request an extra
#          confirmation if it appears that the entire replica has been
#          deleted, before propagating the change. If the batch flag is
#          also set, synchronization will be aborted. When the path
#          preference is used, the same confirmation will be requested for
#          top-level paths. (At the moment, this flag only affects the
#          text user interface.) See also the mountpoint preference.
confirmbigdel=true

#          When this preference is set to true, Unison will use the
#          modification time and length of a file as a `pseudo inode
#          number' when scanning replicas for updates, instead of reading
#          the full contents of every file. Under Windows, this may cause
#          Unison to miss propagating an update if the modification time
#          and length of the file are both unchanged by the update.
#          However, Unison will never overwrite such an update with a
#          change from the other replica, since it always does a safe
#          check for updates just before propagating a change. Thus, it is
#          reasonable to use this switch under Windows most of the time
#          and occasionally run Unison once with fastcheck set to false,
#          if you are worried that Unison may have overlooked an update.
#          The default value of the preference is auto, which causes
#          Unison to use fast checking on Unix replicas (where it is safe)
#          and slow checking on Windows replicas. For backward
#          compatibility, yes, no, and default can be used in place of
#          true, false, and auto. See the section "Fast Checking" for more
#          information.
fastcheck=true

#          When this flag is set to true, the group attributes of the
#          files are synchronized. Whether the group names or the group
#          identifiers are synchronizeddepends on the preference numerids.
group=true

#          When this flag is set to true, the owner attributes of the
#          files are synchronized. Whether the owner names or the owner
#          identifiers are synchronizeddepends on the preference
#          extttnumerids.
owner=true

#          Including the preference -prefer root causes Unison always to
#          resolve conflicts in favor of root, rather than asking for
#          guidance from the user. (The syntax of root is the same as for
#          the root preference, plus the special values newer and older.)
#          This preference is overridden by the preferpartial preference.
#          This preference should be used only if you are sure you know
#          what you are doing!
prefer=newer

#          When this preference is set to true, the textual user interface
#          will print nothing at all, except in the case of errors.
#          Setting silent to true automatically sets the batch preference
#          to true.
silent=true

#          When this flag is set to true, file modification times (but not
#          directory modtimes) are propagated.
times=true
 selanjutnya masukkan perintah berikut :
#unison
Langkah 6 : Membuat Cron Job untuk Unison

berikut adalah perintah untuk konfigurasi Cron Job :
#crontab -e
masukan file berikut pada baris paling bawah :
 */5 * * * * /usr/bin/unison &> /dev/null
Langkah 7 : Tes Unison

selanjutnya kita akan mengetes unison dimana langkah ini adalah langkah terakhir dari project File Syncronizer  pada dua Raspberry Pi menggunakan Unison ini. yang pertama, kita akan membuat file pada server01 didalam folder /usr/share/nginx/www. berikut adalah perintahnya :

#echo "Jobs Team Project" > /usr/share/nginx/www/jobs.txt
selanjutnya, lakukan perintah berikut pada server02 untuk melihat apakah di server02 sudah ada file jobs.txt yang terdapat dalam folder /usr/share/nginx/www. berikut adalah perintahnya :

#cd /usr/share/nginx/www
#ls
index.html  jobs.txt
selanjutnya kita akan melihat isi file dari jobs.txt pada server02. berikut perintahnya :
#cat jobs.txt
Jobs Team Project
kita akan melanjutkan untuk merubah isi dari file jobs.txt pada server02. berikut perintahnya :
#nano /usr/share/nginx/www/jobs.txt
Jobs Team Project

ubah menjadi :
Jobs Team Project Berhasil
kemudian tekan tombol Ctrl+x, lalu tekan y, dan kemudian Enter. sekarang kita akan melihat file jobs.txt yang telah diubah pada server01. berikut perintahnya :
#cd /usr/share/nginx/www
#ls
index.html jobs.txt
selanjutnya kita akan melihat isi file dari jobs.txt pada server01. berikut perintahnya :
#cat jobs.txt
Jobs Team Project Berhasil
oke, sekian tutorial dari kami untuk membuat File Syncronizer  pada dua Raspberry Pi menggunakan Unison. terima kasih

0 Response to "Cara Membuat File Syncronizer pada dua Raspberry Pi menggunakan Unison"