Linux (centos5.0+) Unison+inotify-tools trigger bidirectional auto-sync

Source: Internet
Author: User
Tags inotify ocaml

192.168.1.11 is server1,192.168.1.22 is server2. "1" Installation inotify-tools   major Linux distributions have inotify-tools software package, recommended by Yum installation:   [[email protected]  ~] #yum  install inotify-tools  [[email protected] ~] #yum  install  inotify-tools****** description start *********************************   depressed is! The company server unexpectedly did not find inotify-tools this package!    so can only search the package online, compiled and installed:   [[email protected] ~]# wget http://github.com/ downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz  [[email protected] ~]#  tar xzvf inotify-tools-3.14.tar.gz  [[email protected] ~]# cd  inotify-tools-3.14  [[email protected] ~]# ./configure  [[email  protected] ~]# make  [[email protected] ~]# make install    [[email protected] ~]# wget http://github.com/downloads/rvoicilas/inotify-tools/ Inotify-tools-3.14.tar.gz  [[email protected] ~]# tar xzvf  inotify-tools-3.14.tar.gz  [[email protected] ~]# cd inotify-tools-3.14   [[email protected] ~]# ./configure  [[email protected] ~]# make   [[email protected] ~]# make install  ****** Description End ********************* "2" installation unison through the source package compiled installation unison, need objective caml compiler. 1) Install OCaml to/USR/LOCAL/SRC (recommended version 3.0 above, installation path can be defined by itself)   [[email protected] ~]# cd /usr/ local/src    [[email protected] src]# wget http://caml.inria.fr/pub/ distrib/ocaml-3.12/ocaml-3.12.1.tar.gz  [[email protected] src]# tar -zxvf  Ocaml-3.12.1.tar.gz  [[email protected] src]# cd ocaml-3.12.1  [[email  protected] ocaml-3.12.0]# ./configure  [[email protected] ocaml-3.12.0]# make world opt  [[email protected]  OCAML-3.12.0]# MAKE INSTALL2) Compile and install unison (Unison version can be downloaded by yourself)   [[email protected]  src]# wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/ unison-2.40.63.tar.gz  [[email protected] src]# tar -xzvf  unison-2.40.63.tar.gz  [[email protected] src]# cd unison-2.40.63  [[ Email protected] unison-2.40.63]# make uistyle=text  [[email protected]  unison-2.40.63]# make install****** description Start *********************************   execute make During the  install process, you may receive the following error message:  mv: cannot stat  '/root/bin//unison ':  no such  file or directory  make: [doinstall] Error 1  (ignored)    cp unison /root/bin/  cp: cannot create regular file  '/root/bin/':  is a directory  make: ***  [doinstall] Error 1   Baidu Online translation for a bit, the general meaning is:/root/bin directory is not found.    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 generated executable unison to the system path directory.   [[email protected] unison-2.40.63]# whereis  $PATH   //View System PATH Directory    bin: /usr/local/bin  [[email protected] unison-2.40.63]# cp  unison /usr/local/bin  ****** Description End *********************************3) Upload the executable file unison to the Server2 host   [[email protected] unison-2.40.63]# scp unison [ email protected]:/root/****** description Start *********************************   remote connection may appear:   Are  you sure you want to continue connecting  (yes/no)?    Don't hesitate, knock a  yes , then appear:   [email protected] ' s password:   don't sendStay, enter the Server2 password, and then appear:  unison                100% 1473KB   36k/s   00:40   Note that Unison has been successfully uploaded to Server2.    dual machine Not configured to trust key, you need to enter the remote connection password drops! Description End *********************************4) login Server2 host, copy unison to path directory   [[email protected]  ~]# cp unison /usr/local/bin "3" Configure Dual-machine Trust (Ssh key)   1) Server1 Create key   [[email protected] ~]# ssh-keygen -t rsa****** Instructions start *********************************     is not the appearance of a lot of English sentences, can not understand you, I do not understand, haha!    Baidu Online translation, the general meaning is: what public key, key storage location, whether the need for a private key password or the like.    don't bother, just hit enter! After that, a pair of keys will be generated, Id_rsa (private key file) and Id_rsa.pub (public key file), saved in the/root/.ssh/directory. Description end *********************************2) Add Server1 's public key to Server2 Authorized_keys file   -- Upload the key file to the Server2 host   [[email protected] ~]# scp ~/.ssh/id_rsa.pub [email  protected]:/root***Description start *********************************   remote connection may appear:   are you sure you  want to continue connecting  (yes/no)?    don't hesitate, knock a  yes , and then appear:   [email protected] ' s password:   don't be in a daze, enter the Server2 password, and then appear:   id_rsa.pub                  100%   394     0.4KB/s    explained that the public key has been successfully uploaded to Server2.    Dual machine does not configure the trust key before the remote connection needs to enter the password drops! Description End *********************************  --Login Server2, add the public key to the Authorized_keys file   [[email  protected] ~]# mkdir .ssh  [[email protected] ~]# chmod 700  .ssh  [[email protected] ~]# mv ~/id_rsa.pub ~/.ssh/authorized_keys   [[EMAIL PROTECTED] ~]# CHMOD 600 ~/.SSH/AUTHORIZED_KEYS3) Server2 Create key  &nbsP [[email protected] ~]# ssh-keygen -t rsa****** Here for instructions see above **************************4] Add the Server2 public key to the Server1 Authorized_keys file   --upload the key file to the Server1 host   [[email protected] ~ ]# scp ~/.ssh/id_rsa.pub [email protected]:/root ****** here for instructions see server1*****************    --login Server1, add the public key to the Authorized_keys file   [[email protected] ~]#  mv ~/id_rsa.pub ~/.ssh/authorized_keys****** Description Start *********************************   There is no need to create a new. SSH folder here without chmod permissions?   server1 when the key was created, the. SSH folder already exists! Description End *********************************5) Restart the Server1,server2 SSH service   [[email protected] ~ ]# /etc/init.d/sshd restart  [[email protected] ~]# /etc/init.d/sshd  Restart "4" test is configured successfully     [[email protected] ~]# ssh [email protected ]  date  [[email protected] ~]# ssh [email protected]  date   without prompting for a password to get each other's time, it proves that the configuration was successful. "5" Instructions for use    execute the unison command on any server machine:   [[email protected] ~]# unison -bath  /home/server1image/ ssh://192.168.1.22//home/server2image/"6" create. Sh script to perform synchronization 1) Server1 create script on unison2.sh:# /bin/baship2= "192.168.1.22" src2= "/home/server1image/" dst2= "/home/server2image/"  /usr/bin/inotifywait  -mrq -e create,delete,modify,move  $src 2 | while read line; do/ usr/bin/unison -batch  $src 2 ssh://$ip 2/$dst 2echo -n  "$line  "  >>  /var/log/inotify.logecho  ' date | cut -d  '   '  -f1-4 '  >> /var/ LOG/INOTIFY.LOGDONE2) server2 Create script unison1.sh:#/bin/bash ip1= "192.168.1.11" src1= "/home/server2image/" dst1= " /home/server1image/" /usr/bin/inotifywait -mrq -e create,delete,modify,move  $src 1  | while read line; do/usr/bin/unison -batch  $src 1 ssh://$ip 1/$dst 1echo -n  "$line  "  >> /var/log/inotify.logecho  ' date | cut -d  '   '  -f1-4 '  >> /var/log/inotify.logdone "7" executes. SH script   server1,server2 each executes. Sh.

Linux (centos5.0+) unison+inotify-tools triggered 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.