双向同步使用unison

1、实现两台服务器的/web目录数据同步(任何一台数据修改两台服务器数据时时保持一致)

#双向同步使用unison

 安装unison软件程序

yum install -y ocaml ctags-etags.x86_64 glibc-static glib* inotify-tools

#从官网下载unison

wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/unison-2.48.3/unison-2.48.3.tar.gz

  tar zxvf unison-2.48.3.tar.gz    #解压

进入解压后目录

  make UISTYPLE=text THREADS=true STATIC=true  #安装

make install

mkdir /root/bin/

make install

cp unison /usr/local/bin

  cp unison /usr/local/bin/          #将命令移动到bin下

nohup unison &

ssh-keygen  #创建信任密钥

ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.148 #将公钥给目的主机

mkdir .unison #注意这个目录在用户家目录下root用户为/root/.unison

注意在这个目录下的密钥,,有一个不能删除 本实验是这个ar20f9204b3d63f01e69e918c98c4f6a1b,,删除则不能同步。。。

在vi default.prf中写

 # Unison preferences file

root = /web

root = ssh://root@192.168.1.148//web

batch = true

sshargs = -C

fastcheck=true

repeat=1

  • owner=true

group=true

perms=-1

logfile = /root/.unison/unison.log

unison default.prf  #执行

执行后会一直占用终端。。。解决可以用nohup或者screen。。

原文地址:https://www.cnblogs.com/han1094/p/6351810.html