分布式场景下会遇到文件共享的问题,便捷的解决方案是选用第三方的文件服务,如果遇到国内外同步需要自己搭建系统,unison 和 intify 组合可以快速实现 小文件的时时共享
节点A HK
节点B NA
两个节点均为ubuntu 系统
- 配置两个节点ssh 免密码登录
- 两个节点分别安装
-
sudo apt-get install unison
-
apt-get install inotify-tools
- 测试unison
- 编写同步脚本
-
UNISON=`ps -ef |grep -v grep|grep -c inotifywait` if [ ${UNISON} -lt 1 ] then ip_na="***.****.***.***" src_hk="/deploy/a/image" dst_na="/deploy/a/image/" /usr/bin/inotifywait -mrq -e create,delete,modify,move $src_hk | while read line do #/usr/local/bin/unison -batch $src2 ssh://$ip2/$dst2 /usr/bin/unison -batch $src_hk ssh://$ip_na/$dst_na echo -n "$line" >> /tmp/inotify/inotify$(date +%u).log echo date +"%F-%T-%H-%M" >> /tmp/inotify/inotify$(date +%u).log done fi
- 使用守护进程运行同步脚本