Unison+inotify-tools trigger bidirectional Auto-sync

Source: Internet
Author: User
Tags inotify ocaml

Bidirectional real-time data synchronization deployment

First add the server SSH trust, that is, the secret key login

web1:192.168.10.36

web2:192.168.10.37

Execute the following commands on Web1 and WEB2, respectively

mkdir ~/.ssh
chmod ~/.ssh
Generate RSA Key
SSH-KEYGEN-T RSA
(then three consecutive returns)

Add the encryption key to the authorization key file

Cd~/.ssh
SSH "-P" 192.168.10.36 cat/root/.ssh/id_rsa.pub >>authorized_keys #小写p
SSH "-P" 192.168.10.37 cat/root/.ssh/id_rsa.pub >>authorized_keys
Scp-p Authorized_keys 192.168.10.37:/root/.ssh/#大写P

Chmod600/root/.ssh/authorized_keys
Operating on server Server2
chmod 600/root/.ssh/authorized_keys

A list of software needs to be provided: (version must be consistent)

Inotify-tools-3.14.tar.gz

Ocaml-3.12.1.tar.gz

Unison-2.40.63.tar.gz

wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

wget http://caml.inria.fr/pub/distrib/ocaml-3.12/ocaml-3.12.1.tar.gz

Wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.40.63.tar.gz (not available)

Both servers have to execute the following command:

Yum Install Ctags-etags

Tar xzvf inotify-tools-3.14.tar.gz

CD inotify-tools-3.14

./configure

Make

Make install

TAR-ZXVF ocaml-3.12.1.tar.gz

CD ocaml-3.12.1

./configure

Make World opt

Make install

TAR-XZVF unison-2.40.63.tar.gz

CD unison-2.40.63

Make Uistyle=text

Make install

The following error is prompted when you execute make install:

mv/root/bin//unison/tmp/unison-24397

MV: Unable to get "/root/bin//unison" File Status (STAT): No file or directory

Make: [DoInstall] Error 1 (ignored)

CP unison/root/bin/

CP: Unable to create normal file "/root/bin/": is a directory

Make: * * [DoInstall] Error 1

Because the unison default is to copy the unison file to the/root/bin directory, but the Linux default does not have the directory, so we need to copy the resulting executable file unison to the system path directory.

So we need to manually execute the following command:

CP Unison/usr/local/bin

To test the synchronization situation:

unison-batch/home/web1/ssh://192.168.10.37//home/wen2/

Create a new script on the WEB1 device and run in the background:

Vi unison.sh

------------------------------------The following is the script content-------------------------------------------

#/bin/bash

Ip2= "192.168.10.36"

Src2= "/home/web1/"

Dst2= "/home/web2/"

/usr/local/bin/inotifywait-mrq-ecreate,delete,modify,move $SRC 2 | while read line; Do

/usr/local/bin/unison-batch $src 2ssh://$ip 2/$DST 2

Echo-n "$line" >>/var/log/inotify.log

Echo ' date | cut-d "-f1-4 ' >>/var/log/inotify.log

Done

------------------------------------above is the script content-------------------------------------------

Create a new script on the WEB2 device and run in the background

Vi unison.sh

------------------------------------The following is the script content-------------------------------------------

#/bin/bash

Ip2= "192.168.10.37"

Src2= "/home/web2/"

Dst2= "/home/web1/"

/usr/local/bin/inotifywait-mrq-ecreate,delete,modify,move $SRC 2 | while read line; Do

/usr/local/bin/unison-batch $src 2ssh://$ip 2/$DST 2

Echo-n "$line" >>/var/log/inotify.log

Echo ' date | cut-d "-f1-4 ' >>/var/log/inotify.log

Done

------------------------------------above is the script content-------------------------------------------

Run scripts on both devices to test for synchronization.

Unison+inotify-tools trigger bidirectional Auto-sync

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.