您的位置:首页 > 运维架构 > Linux

linux文件双向同步(unison)

2015-01-17 13:00 316 查看
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://root@10.108.74.234//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安装同样的步骤安装。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: