博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
unison+inotify实现文件实时双向同步部署步骤
阅读量:4261 次
发布时间:2019-05-26

本文共 3103 字,大约阅读时间需要 10 分钟。

unison+inotify实现文件实时双向同步部署步骤
一.编译安装unison
unison各版本下载地址 http://www.seas.upenn.edu/~bcpierce/unison//download.html
unison编译器下载地址 http://caml.inria.fr/pub/distrib (版本至少3.0.7)
1.环境说明 (在其他地方部署时修改下IP与同步目录即可)
host1    192.168.42.241    同步目录 /root/test
host2    192.168.42.243    同步目录 /root/test
2. 安装Objective Caml compiler(若安装的unison的是二进制程序,则不用安装。因二进制程序版本都太老,这里选择编译安装)
[root@241 ~]# cd /usr/src/
[root@241 src]# wget http://caml.inria.fr/pub/distrib/ocaml-3.12/ocaml-3.12.0.tar.gz
[root@241 src]# tar xf ocaml-3.12.1+rc1.tar.gz
[root@241 src]# tar xf ocaml-3.12.0.tar.gz
[root@241 src]# cd ocaml-3.12.0
[root@241 ocaml-3.12.0]# ./configure
[root@241 ocaml-3.12.0]#  make world opt
[root@241 ocaml-3.12.0]#  make install
3.编译安装Unison
[root@241 ~]# wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.40.102.tar.gz
[root@241 src]# tar xf unison-2.40.102.tar.gz
[root@241 src]# cd unison-2.40.102
[root@241 unison-2.40.102]# make UISTYLE=text THREADS=true STATIC=true
[root@241 unison-2.40.102]# cp unison /usr/local/bin/            #将生成的二进制程序复杂到系统的PATH路径里
[root@241 unison-2.40.102]# scp unison root@192.168.42.243:/usr/local/bin/unison        #将unison二进制程序复制到host2
二.配置双机ssh信任
[root@241 ~]# ssh-keygen
[root@243 ~]# ssh-keygen
[root@243 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.42.241
[root@241 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.42.243
三.unison配置
1.编辑unison配置文件
[root@241 ~]# vim .unison/default.prf
# Unison preferences file
#root = /root/test                            #两个root表示要同步的文件夹(下面的同步脚本定义了同步目录,所以这里注释掉,否则会冲突)
#root = ssh://192.168.42.243//root/test        
#path = /root/test                            #两个path表示只同步指定的子目录及文件,而非整个目录
#path = /root/test
#ingnore = PATH test/txt                    #ingnore = Path 表示忽略/root/test 下面的test/txt
batch = true                                #表示全自动模式,接受默认动作
#maxthreads = 300
#repeat = 1
#retry = 3
owner = true                                #owner group perms表示保持原来的属主 属组 权限
group = true                                
perms = -1
fastcheck = true                            #true表示同步时通过文件的创建时间来比较两地文件 false表示比较两地文件的内容
rsync = false
#debug = verbose
sshargs = -C                                #表示使用ssh的压缩方式传输
xferbycopying = true                        
confirmbigdel = false                        #true表示当需要同步的两个目录一个为空时,unison将停止 false表示同步的某个目录为空时不会停止运转
log = true
logfile = /root/.unison/unison.log
#host2 配置文件一样
四.安装inotify
1.查看系统是否支持inotify
[root@241 ~]# ls -l /proc/sys/fs/inotify
total 0
-rw-r--r-- 1 root root 0 Nov 11 11:25 max_queued_events
-rw-r--r-- 1 root root 0 Nov 11 11:25 max_user_instances
-rw-r--r-- 1 root root 0 Nov 11 11:25 max_user_watches
2.安装inotify
[root@241 src]# tar xf inotify-tools-3.14.tar.gz
[root@241 src]# cd inotify-tools-3.14
[root@241 inotify-tools-3.14]# ./configure
[root@241 inotify-tools-3.14]# make && make install
echo 30000000 > /proc/sys/fs/inotify/max_user_watches  (注意:重启机器后此设置会消失,如果监控的文件数目不是特别多,可以不设置)
3.编写inotify实时监控脚本
[root@241 ~]# vim unison.sh
#!/bin/bash
DESTHOST=192.168.42.243
DESTHOSTDIR=/root/test
SRCDIR=/root/test
/usr/local/bin/inotifywait -mrq  --timefmt '%d/%m/%y %H:%M' --format '%T %w %f'  -e create,delete,modify,move $SRCDIR | while read line; do
/usr/local/bin/unison $SRCDIR ssh://$DESTHOST/$DESTHOSTDIR
done
chmod +x unison.sh
4.按同样方法在host2安装inotify和编写同步脚本
5.分别在host1 host2 让脚本运行于后台
[root@241 ~]# nohup ./unison.sh &
[root@243 ~]# nohup ./unison.sh &

转载地址:http://hgxei.baihongyu.com/

你可能感兴趣的文章
【Ubuntu】ping: unknown host www.baidu.com
查看>>
【Qt】qss样式表之:QCalendarWidget,日历窗口样式表设置
查看>>
【Qt】qss样式表之:自定义属性实现动态切换样式
查看>>
【GStreamer】基本概念及安装
查看>>
【GStreamer】gstreamer工具详解之:gst-launch-1.0
查看>>
【GStreamer】gstreamer工具详解之:gst-inspect-1.0
查看>>
【GStreamer】gstreamer工具详解之:ges-launch-1.0
查看>>
【GStreamer】gstreamer工具详解之:gst-discoverer-1.0
查看>>
【Ubuntu】安装中文输入法
查看>>
【Cmake】执行cmake命令时报错:No XSLT processor found
查看>>
【数据库】sqlite中PRAGMA命令说明
查看>>
【Qt】Qt容器总结
查看>>
【C++】C++11 STL算法(一):非修改序列操作(Non-modifying sequence operations)
查看>>
【C++】C++11 STL算法(二):修改序列的操作(Modifying sequence operations)
查看>>
【C++】C++11 STL算法(三):分隔操作(Partitioning operations)、排序操作(Sorting operations)
查看>>
【C++】C++11 STL算法(四):二分查找法(Binary search operations)、合并操作
查看>>
【C++】C++11 STL算法(五):设置操作(Set operations)、堆操作(Heap operations)
查看>>
【C++】C++11 STL算法(六):最小/最大操作(Minimum/maximum operations)、比较运算(Comparison operations)
查看>>
【C++】C++11 STL算法(七):排列操作(Permutation operations)、数值操作(Numeric operations)
查看>>
【C++】C++11 STL算法(八):对未初始化内存的操作(Operations on uninitialized memory)、C库(C library)
查看>>