About UNISON
Unison is a file-synchronization tool for
Unix and Windows. It allows two replicas of a collection of files and
directories to be stored on different hosts (or different disks on the same
host), modified separately, and then brought up to date by propagating the
changes in each replica to the other.
For this implementation I use unison227-2.27.57-13.el6.x86_64.rpm on RHEL6.
The setup work under following scenarios:
1) Replication is for two hosts (node1 & node2)
2) The synced folder is user's home directory - /home/rsftp
3) The file transfer is done using passwordless ssh protocol
4) The synchronization is done in 1 minute interval using cron scheduler
Step 1: Install unison rpm and add user
On both nodes, install the package
rpm -ivh
unison227-2.27.57-13.el6.x86_64.rpm
useradd rsftp
echo rsftp!@# |
passwd --stdin rsftp
above says "set rsftp!@# as password for rsftp user.
Step 2: Create ssh public key and exchange to both nodes
As rsftp user,
On node1:
[rsftp@node1 ~] $ ssh-keygen -t dsa
[rsftp@node1 ~] $ ssh-copy-id
-i /home/rsftp/.ssh/id_dsa.pub node2
On node2:
[rsftp@node2 ~] $ ssh-keygen -t dsa
[rsftp@node2 ~] $ ssh-copy-id -i /home/rsftp/.ssh/id_dsa.pub node1
Once done, next is try ssh in to the partner, expected result is passwordless login.
Step 3: Modify unison configuration file
The configuration file is /home/rsftp/.unison/default.prf
On node1, put these lines
root = /home/rsftp
root = ssh://node2//home/rsftp
auto = true
batch = true
do the same on node2,
root = /home/rsftp
root = ssh://node1//home/rsftp
auto = true
batch = true
Step 4: Create a cronjob on both nodes
As rsftp user
crontab -e
put this line
*/1 * * * * /usr/bin/unison &> /dev/null
Step 5: Create a sample file using dd command to create a file with 10MB size
On node1,
[rsftp@node1 ~] $ cd ~
[rsftp@node1 ~] $ dd if=/dev/zero of=file1.dat count=1 bs=10M
After 1 minute pass, on node2 list file in rsftp home directory,
On node2,
[rsftp@node2 ~] $ cd ~
[rsftp@node2 ~] $ ls -lah
You should see file1.dat with
10MB size.Repeat above steps, create a
file2.dat in node2 and list it in node1. Also try other operation such deleting and modifying a file.
No comments:
Post a Comment