unison+inotify
hostnamectl --static set-hostname tCentos
1.下载文件到/usr/local/src
ocaml
unison
inotify-tools
2.安装inotify-tools
cd /usr/local/src
tar zvxf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure --prefix=/usr/local/inotify
make && make install
cd /usr/local/inotify/
echo "PATH=/usr/local/inotify/bin:$PATH" >/etc/profile.d/inotify.sh
source /etc/profile.d/inotify.sh
echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf
ldconfig -v | grep inotify
ln -sv /usr/local/inotify/include/ /usr/include/inotify
3.安装ocaml
cd /usr/local/src
tar zvxf ocaml-4.02.3.tar.gz
cd ocaml-4.02.3
./configure
make world opt && make install
4.安装unison
yum install ctags-etags -y
cd /usr/local/src
tar zvxf unison-2.48.3.tar.gz
cd unison-2.48.3
make UISTYLE=text #THREADS=true STATIC=true 表示使用命令行方式,加入线程支持以静态模式编译
make install
cp unison /usr/local/bin (make install会提示错误,cp unison /usr/local/bin,复制即可)
5.服务器A生成的公钥传到服务器B上
ssh-keygen -t rsa #生成ssh的密钥对
scp ~/.ssh/id_rsa.pub 192.168.1.41:/root/.ssh/img_rsa.pub
#生成的密钥在家目录的ssh文件中,ssh文件为隐藏文件,通过scp复制到服务器B上
cat img_rsa.pub >> authorized_keys
#在服务器A上把服务器B传来的公钥文件改名并存放到ssh目录下
chmod 600 authorized_keys #给公钥文件改权限为600
systemctl restart sshd
#重启sshd服务
6.服务器B生成的公钥传到服务器A上
ssh-keygen -t rsa #生成ssh的密钥对
scp ~/.ssh/id_rsa.pub 192.168.1.40:/root/.ssh/img01_rsa.pub
#生成的密钥在家目录的ssh文件中,ssh文件为隐藏文件,通过scp复制到服务器B上
cat img01_rsa.pub >> authorized_keys
#在服务器A上把服务器B传来的公钥文件改名并存放到ssh目录下
chmod 600 authorized_keys #给公钥文件改权限为600
systemctl restart sshd
#重启sshd服务
7.服务器A的同步脚本
mkdir -p /web/htdocs
#/bin/bash
ipB="192.168.1.41"
srcA="/web/htdocs"
dstB="/website"
/usr/local/inotify/bin/inotifywait -mrq -e create,delete,modify,move $srcA | while read line;do
/usr/local/bin/unison -batch $srcA ssh://$ipB/$dstB
echo -n "$line ">> /var/log/inotify.log 2>&1
echo `date|cut -d " " -f 1-4` >> /var/log/inotify.log 2>&1
done
赋予执行权限
chmod +x /data/sera.sh
监控形式启动,可以查看文件变更状态
sh -x /data/sera.sh
执行脚本并做开机启动:
chmod +x /etc/rc.d/rc.local
echo "sh /data/sera.sh &" >> /etc/rc.d/rc.local
8.服务器B的同步脚本
mkdir -p /website
#/bin/bash
ipA="192.168.1.40"
srcB="/website"
dstA="/web/htdocs"
/usr/local/inotify/bin/inotifywait -mrq -e create,delete,modify,move $srcB | while read line;do
/usr/local/bin/unison -batch $srcB ssh://$ipA/$dstA
echo -n "$line ">> /var/log/inotify.log
echo `date| cut -d " " -f 1-4` >> /var/log/inotify.log
done
赋予执行权限
chmod +x /data/serB.sh
监控形式启动,可以查看文件变更状态
sh -x /data/serB.sh
执行脚本并做开机启动:
chmod +x /etc/rc.d/rc.local
echo "sh /data/serB.sh &" >> /etc/rc.d/rc.local
#/bin/bash
UNISON=`ps -ef |grep -v grep|grep -c inotifywait`
if [ ${UNISON} -lt 1 ]
then
ip2="unison@192.168.1.6:2222"
src2="/var/web2/"
dst2="/var/web1/"
/usr/local/bin/inotifywait -mrq -e create,delete,modify,move $src2 | while read line
do
/usr/local/bin/unison -batch -sshargs "-i /home/unison/.ssh/id_rsa" $src2 ssh://$ip2
/$dst2
echo -n "$line " >> /var/umelook-log/inotify/inotify$(date +%u).log
echo ` date +%F\ %T` >> /var/umelook-log/inotify/inotify$(date +%u).log
done
fi
ps -ef |grep -v grep|grep -c inotifywait
另外,原来官方的rc-local.service有点问题,把命令写入/etc/rc.local,然后启动rc-local.service会出问题,根本启动不了。后来偶在上面提供的网页里找到了解决办法。如下:修改/etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
新建/etc/rc.local文件
如果是简单的自定义命令,可写入/etc/rc.local,用上面的方法来处理。
#/bin/bash
srcB=/website/
dstA=/web/htdocs/
ipA=192.168.1.40
/usr/local/bin/inotifywait -mrq -e create,delete,modify,move $srcB | while read line;do
/usr/local/bin/unison -batch $srcB ssh://$ipA/$dstA
echo -n "$line ">> /var/log/inotify.log
echo `date| cut -d " " -f 1-4` >> /var/log/inotify.log
done
echo ` date +%F\ %T` >> /var/umelook-log/inotify/inotify$(date +%u).log
unison+inotify的更多相关文章
- linux web服务器静态资源的处理 unison+inotify双向同步
linux web服务器静态资源的处理 unison+inotify双向同步 http://monkeyzhu.blog.51cto.com/5764358/1324391 简介 unison可以使两 ...
- unison + inotify 实现文件实时双向同步部署步骤
unison + inotify 实现文件实时双向同步部署步骤 一. Unison简介 Unison是Windows.Linux以及其他Unix平台下都可以使用的文件同步工具,它能使两个文件夹(本地或 ...
- rsync unison+inotify双向实时同步
rsync多线程同步 A:文件服务器 ip:10.10.1.10 B:备份服务器 ip:10.10.1.11 1.在B服务器上安装rsync软件 tar xzvf rsync-3.1.0.tar.gz ...
- unison+inotify的Web目录同步方案
1.在Linux下做WEB目录文件同步 一般有如下几种方式: ----------------------------------------------- 1) nfs实现web数据共享 ...
- unison+inotify 同步web代码并排除指定目录不同步
unison + inotify 实现web 数据双向同步 unison 是一款跨平台的文件同步对象,不仅支撑本地对本地同步,也支持通过SSH,RSH和Socket 等网络协议进行同步.unis ...
- unison+inotify实现文件双向自动同步
nfs适合存小图片和小文件,有一个致命的缺点,就是其中一台web服务挂掉之后,会直接导致web页面无法访问,动态的那种数据, 而且数据量很大的数据不适合nfs Unison是一款跨平台(window, ...
- unison+inotify实现数据双向同步
unison是一款跨windows/linux/MAC OS平台的文件同步工具,不仅支持本地对本地同步,也支持通过SSH.RSH和Socket等网络协议进行同步.更棒的是,unison支持双向同步操作 ...
- 两台linux主机使用unison + inotify实现web文件夹同步
两台服务器同步数据 unison 是一款跨平台的文件同步对象,不仅支撑本地对本地同步,也支持通过SSH,RSH和Socket 等网络协议进行同步. unison 支持双向同步,你可以同A同步到B ,也 ...
- 实现web数据同步的四种方式
http://www.admin10000.com/document/6067.html 实现web数据同步的四种方式 1.nfs实现web数据共享 2.rsync +inotify实现web数据同步 ...
随机推荐
- strsep和strtok_r替代strtok
char *strtok(char *str, const char *delim) 会修改数据源.外部加锁才线程安全(strtok执行结束再解锁执行另一个strtok循环知道工作完成) 主要是以互斥 ...
- Redis安装及实现session共享
一.Redis介绍 1.redis是key-value的存储系统,属于非关系型数据库 2.特点:支持数据持久化,可以让数据在内存中保存到磁盘里(memcached:数据存在内存里,如果服务重启,数据会 ...
- 【纯css】左图右文列表,左图外框宽度占一定百分比的正方形,右上下固定,右中自动响应高度。支持不规则图片。
查看演示 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- 远方的塔--Pylons
转自:https://en.wikipedia.org/wiki/Pylons_project#Pylons_Framework Pylons
- C and SQL data types for ODBC and CLI
C and SQL data types for ODBC and CLI This topic lists the C and SQL data types for ODBC and CLI a ...
- LeetCode之263. Ugly Number
------------------------------------------------------------- 如果一个数的质因子只包括2,3,5,那么这个数n可以表示为:n=2x+3y+ ...
- EF多对多更新报错(TableNoTracking引发的bug)
实体映射关系如下,SISTUser和SISTUserRoles存在多对多的关系,生成中间表 public partial class SISTUserMap: EntityTypeConfigurat ...
- .NET轻量级任务任务管理类
概述 最近做项目总是遇到服务跑批等需求,一直想写个任务管理的DLL,现在整理了一下思路,编写了一个DLL类库,使用方便.只要调用的子类继承服务基类便可以实现任务的整体调度.先看看页面效果: 使用方式 ...
- Google之Chromium浏览器源码学习——base公共通用库(一)
Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...
- 基于.NET平台常用的框架整理
自从学习.NET以来,优雅的编程风格,极度简单的可扩展性,足够强大开发工具,极小的学习曲线,让我对这个平台产生了浓厚的兴趣,在工作和学习中也积累了一些开源的组件,就目前想到的先整理于此,如果再想到,就 ...