linux文件雙向同步(unison)

Linux文件雙向同步

1、        下載unison,跟ocaml編譯器,下載地址:

http://caml.inria.fr/pub/distrib/ocaml-3.10/;http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/

2、安裝ocaml:

tar -xzvf ocaml-3.10.0.tar.gz

cd ocaml-3.09.3
./configure
makeworld opt
makeinstall

檢查ocaml是否安裝成功:

Ocaml -version

3、安裝unison

tar -xzvf unison-2.40.63.tar.gz

cd unison-2.40.63

make UISTYLE=text

mkdir /root/bin/

cp unison /root/bin/

make install

cp ./unison /usr/bin/

查看unison是否安裝成功:

Unison –version

4、配置default.prf文件(/root/.unison/):

# Unison preferences file

root = /opt/unison/test/

root = ssh://[email protected]//opt/unison/test/

#force =

#ignore =

batch = true

#repeat = 1

#retry = 3

owner = true

group = true

perms = -1

fastcheck = false

rsync = false

sshargs = -C

xferbycopying = true

log = true

logfile = /opt/unison/unison.log

5、配置雙機信任(登錄對方,不用密碼)

/root/增加目錄.ssh:

Mkdir .ssh

Chmod 700 .ssh

ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

17:e4:7c:79:8d:a0:00:3b:d9:f7:7a:56:f3:ac:54:4d oracle@gsgatzhapp1

在提示保存私鑰(key)和公鑰(public key)的位置時,使用默認值。

如果需要私鑰密碼(passphrase),則輸入一個私鑰密碼(如果使用私鑰密碼,使用 ssh 執行遠程命令時需要輸入私鑰密碼,因此,本案例中未使用私鑰密碼),因此,直接回車即可。

cd ~/.ssh

ssh 10.178.1.132 cat /root/.ssh/id_rsa.pub >> authorized_keys

6、安裝inotify(http://inotify-tools.sourceforge.net
tar xvf inotify-tools-3.14.tar.gz

cdinotify-tools-3.14

./configure

Make

make install

7、(運行腳本inotify.sh)inotify腳本:

#/bin/bash

UNISON=`ps -ef |grep -v grep|grep -c inotifywait`

if [ ${UNISON} -lt 1 ]

then

/usr/bin/inotifywait -mrq -e create,delete,modify,move $src2 |while read line

do

/usr/bin/unison -batch

echo -n "$line " >> /var/log/inotify/inotify$(date+%u).log

echo ` date +%F\ %T " " -f1-4` >>/var/log/inotify/inotify$(date +%u).log

done

fi

6、另外一臺linux安裝同樣的步驟安裝。

 

 

發佈了110 篇原創文章 · 獲贊 6 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章