Centos7 unison+inotify数据目录双向同步

版权声明:开源,欢迎大家转载! https://blog.csdn.net/Rain_xiaolong/article/details/83900966

unison+inotify

#安装Objective Caml compiler
cd /tmp
wget http://caml.inria.fr/pub/distrib/ocaml-4.03/ocaml-4.03.0.tar.gz
tar -zxvf ocaml-4.03.0.tar.gz
cd ocaml-4.03.0
./configure
make world opt
make install

#安装unison
yum -y install ctags-etags
cd /tmp
wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.48.4.tar.gz
mkdir unison-2.48.4 && cd unison-2.48.4
tar -zxvf /tmp/unison-2.48.4.tar.gz
cd src
make UISTYLE=text THREADS=true
cp unison /usr/local/bin/
unison -version # 有版本信息出现,则安装成功


6. 安装inotify
inotify官方地址:https://en.wikipedia.org/wiki/Inotify
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install inotify-tools

#配置双机ssh信任

unison的使用
unison的用法非常灵活和简单,可以通过如下三种方式调用unison。 
第一种方式:”unison profile_name [options]” 
unison默认会读取~/.unison目录下的配置文件”profile_name.prf”。

注意,在这种方式下,命令行中并没有指出要进行同步的两个地址,所以,此种调用unison的方式必须在配置文件profile_name.prf中通过相关的root指令设置同步的路径和同步的参数,如:

#Unison preferences file 
root = /tmp/test 
root = ssh://[email protected]//tmp/test/ 
#force = 
#ignore = 
batch = true


第二种方式:”unison profile root1 root2 [options]” 
root1、root2分别表示要执行同步的两个路径。这两个路径可以是本地目录路径,也可以是远程服务器的路径,如ssh://username@//tmp/test 。由于同步的路径已经在命令行指定了,所以这里无需在profile.prf配置文件中进行root指令的相关设置。

第三种方式:”unison root1 root2 [options]” 
这种方式相当于执行”unison default root1 root2”命令,即unison默认读取default.prf的配置。

扫描二维码关注公众号,回复: 4182853 查看本文章

9. 配置双机web目录同步
[root@show160 src]# mkdir -p /root/.unison/
[root@show160 src]# vim /root/.unison/default.prf

#Unison preferences file 
root = /data/
root = ssh://[email protected]//data/
#force = 
#ignore = 
batch = true
maxthreads = 300
#repeat = 1 
#retry = 3 
owner = true
group = true
perms = -1
fastcheck = false
rsync = false
sshargs = -C
xferbycopying = true
log = true
logfile = /root/.unison/unison.log


[root@show161 tmp]# mkdir -p /root/.unison/
[root@show161 tmp]# vim /root/.unison/default.prf

#Unison preferences file 
root = /data/
root = ssh://[email protected]//data/
#force = 
#ignore = 
batch = true
maxthreads = 300
#repeat = 1 
#retry = 3 
owner = true
group = true
perms = -1
fastcheck = false
rsync = false
sshargs = -C
xferbycopying = true
log = true
logfile = /root/.unison/unison.log

在两台机器都添加如下脚本,并使用nohup方式运行。有需要则将脚本添加到/etc/rc.local中。

#/bin/bash 
src="/data/"
/usr/bin/inotifywait -mrq -e create,delete,modify,move $src | while read line; do
/usr/local/bin/unison 
echo -n "$(date +%F-%T) $line" >> /var/log/inotify.log
done

猜你喜欢

转载自blog.csdn.net/Rain_xiaolong/article/details/83900966
今日推荐