实时同步rsync+inotify
实时同步rsync+inotify
原创博文http://www.cnblogs.com/elvi/p/7658071.html
#linux同步
#实时同步rsync+inotify,双向同步inotify+unison
#centos6 #关闭selinux、防火墙
chkconfig iptables off
chkconfig ip6tables off
/etc/init.d/iptables stop
/etc/init.d/ip6tables stop
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i '/^SELINUX=/ s/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config #查看
setenforce # 使配置立即生效
vim /etc/hosts #添加hostname名称
reboot #最好重启
#更换阿里源
yum -y install wget vim
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
#安装epel包
yum -y install http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum makecache #生成缓存 ##安装
yum install -y rsync #server1 IP 172.16.11.31
mkdir -p /bak/sys1
cd /bak/sys1
echo test >$(date +%Y-%m-%d-%H%M%S).txt
#server2 IP 172.16.11.32
mkdir -p /bak/sys2
cd /bak/sys2 #ssh同步源
rsync -avz root@172.16.11.31:/bak/sys1/* /bak/sys2
#rsync -avz /bak/sys2 root@172.16.11.31:/bak/sys1/* #rsync同步源配置
vim /etc/rsyncd.conf
#
uid = nobody
gid = nobody
user chroot = no
max connections = 200
timeout = 600
port = 873
pid file = /var/run/rsyncd.pid
#lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[sys1]
comment= sys1 test
path=/bak/sys1
ignore errors
read only = no
list = no
#hosts allow = 192.168.0.0/24
auth users = test
secrets file = /etc/rsyncd.db
echo test:test>/etc/rsyncd.db
chown root:root /etc/rsyncd.db
chmod 600 /etc/rsyncd.db yum -y install xinetd
vim /etc/xinetd.d/rsync
# disable = yes 改成 disable = no
service xinetd restart #启动独立进程运行
pkill rsync
/usr/bin/rsync --daemon
#client
/usr/bin/rsync -avz test@172.16.11.31::sys1 /bak/sys2
#若需要写入权限,需要设置目录
setfacl -m u:nobody:rwx /bak/sys1/ ###免密码验证
#ssh秘钥
ssh-keygen -t rsa -P ''
ssh-copy-id root@172.16.11.31
ssh 172.16.11.31
rsync -avz root@172.16.11.31:/bak/sys1/* /bak/sys2
#rsync的同步源,设置变量export RSUNC_PASSWORD=test
#设置密码文件
echo test> /etc/rsyncd.password
chmod 600 /etc/rsyncd.password
/usr/bin/rsync -avz test@172.16.11.31::sys1 /bak/sys2 --password-file=/etc/rsyncd.password ###实时同步
#安装inotify-tools
yum install make gcc gcc-c++ #安装编译工具
cd /usr/local/src
wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar zxvf inotify-tools-3.14.tar.gz #解压
cd inotify-tools-3.14 #进入解压目录
./configure && make && make install #编译 #安装
#目录测试
inotifywait -mrq -e create,delete /bak/sys1/ #修改inotify默认参数
sysctl -w fs.inotify.max_queued_events="99999999"
sysctl -w fs.inotify.max_user_watches="99999999"
sysctl -w fs.inotify.max_user_instances="65535"
vim /etc/sysctl.conf #添加以下代码
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535 #创建实时监控脚本
vim /bak/inotify_rsync.sh
#!/bin/sh
SRC=/bak/sys1/
DST=root@172.16.11.32:/bak/sys2/
#/bin/su - rsync
/usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib ${SRC} | while read D E F
do
/usr/bin/rsync -ahqzt --delete $SRC $DST
done
#
chmod +x /bak/inotify_rsync.sh
/bak/inotify_rsync.sh &
#echo "/bak/inotify_rsync.sh &" >> /etc/rc.local #开机自启动 #双向同步inotify+unison
yum install ocaml ocaml-camlp4-devel ctags ctags-etags -y
wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.48.4.tar.gz
tar -zxvf unison*
cd src
make UISTYLE=text THREADS=true STATIC=true
make install
cp unison /usr/local/bin
#cp unison /usr/bin
#创建实时监控脚本
vim /bak/unison.sh
#!/bin/sh
SRC=/bak/sys1/
DST=ssh://172.16.11.32//bak/sys2/
/usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib ${SRC} | while read D E F
do
/usr/local/bin/unison -batch $SRC $DST
done
#
chmod +x /bak/unison.sh
/bak/unison.sh &
#nohup /bak/unison.sh &
#server2也配置运行
vim /bak/unison.sh
#!/bin/sh
SRC=/bak/sys2/
DST=ssh://172.16.11.31//bak/sys1/
/usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib ${SRC} | while read D E F
do
/usr/local/bin/unison -batch $SRC $DST
done
#
mkdir /bak/log
nohup /bak/unison.sh &>>/bak/log/unison.log &
#开机自启动(vim /etc/rc.local无效)
crontab -e
* * * * * /bak/unison.sh >>/bak/log/unison.log 2>&1 &
#这样会造成很多进程
##
echo "nohup /bak/unison.sh >>/bak/log/unison.log 2>&1 &" >> /etc/rc.local
#vim /etc/rc.local 测试无效
chmod +x /etc/rc.d/rc.local
echo $(date) >>11.txt #关闭进程
pkill unison.sh
pkill inotifywait
实时同步rsync+inotify的更多相关文章
- 项目cobbler+lamp+vsftp+nfs+数据实时同步(inotify+rsync)
先配置好epel源 [root@node3 ~]#yum install epel-release -y 关闭防火墙和selinux [root@node3 ~]#iptables -F [root@ ...
- 数据文件实时同步(rsync + sersync2)
因近期项目需求,需要同步云端服务器的数据给**方做大数据分析. 思路: 起初只要数据同步,准备开放数据采集接口.但实时性较差,会有延迟. 故而寻觅各种解决方案,最终确定使用 rsync 进行文件同步, ...
- 文件触发式实时同步 Rsync+Sersync Rsync+Inotify-tools
一.概述 1.Rsync+Sersync 是什么? 1)Sersync使用c++编写基于inotify开发的触发机制: 2)Sersync可以监控所监听的目录发生的变化(包括新建.修改.删除),具体到 ...
- rsync+inotify实时同步环境部署记录
随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐渐暴露出了很多不足.首先,rsync在同步数据时,需要扫描所有文件后进行比对,进行差量传输.如果文件 ...
- rsync+inotify实时同步方案
rsync+inotify实时同步,inotify可以实时监控本地文件或目录变化,当检测到本地文件变化,执行rsync同步命令,将变化的文件同步到其他服务器节点. 1.配置环境 3.在服务节点1.服务 ...
- rsync简介与rsync+inotify配置实时同步数据
rsync简介 rsync是linux系统下的数据镜像备份工具.使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH.rsync主机同步. rsync特性 rsync ...
- (转)Linux下通过rsync与inotify(异步文件系统事件监控机制)实现文件实时同步
Linux下通过rsync与inotify(异步文件系统事件监控机制)实现文件实时同步原文:http://www.summerspacestation.com/linux%E4%B8%8B%E9%80 ...
- inotify与rsync实现实时同步记录文档
目录 安装 配置 参考链接 安装 安装rsync yum -y install rsync 安装inotify-tools 这是一个实时监听文件变换的工具 wget -O /etc/yum.repos ...
- Rsync+inotify自动同步数据
一.简介 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐渐暴露出了很多不足. 首先,rsync在同步数据时,需要扫描所有文件后进行比对,进行差量传 ...
随机推荐
- CentOS6编译LAMP基于FPM模式的应用wordpress
CentOS6编译LAMP基于FPM模式的应用wordpress 引言:其实我们可以直接使用yum安装LAMP(Linux+Apache[httpd]+Mysql+PHP),比手动编译安装LAMP要简 ...
- java多线程开发容易犯的错误
昨天在社区上看到有人讨论多线程使用,多线程遇到一些问题以及一些使用技巧记录一下.为什么要使用多线程, 不能是为了用而用,和设计模式一样用的合理,会让程序更易于理解,用的不合理反而会让程序变得更难理解. ...
- linux dig 命令
dig 命令主要用来从 DNS 域名服务器查询主机地址信息. 查询单个域名的 DNS 信息 dig 命令最典型的用法就是查询单个主机的信息. $ dig baidu.com dig 命令默认的输出信息 ...
- window.onload,document.ready
执行时间 window.onload必须等到页面内包括图片的所有元素加载完毕后才能执行. $(document).ready()是DOM结构绘制完毕后就执行,不必等到加载完毕. 编写个数不同 wind ...
- 无JavaScript实现选项卡轮转切换效果
CSS: .box{width:200px; height:100px; border:1px solid #ddd; overflow:hidden;}.list{width:200px; he ...
- Celery 源码解析四: 定时任务的实现
在系列中的第二篇我们已经看过了 Celery 中的执行引擎是如何执行任务的,并且在第三篇中也介绍了任务的对象,但是,目前我们看到的都是被动的任务执行,也就是说目前执行的任务都是第三方调用发送过来的.可 ...
- 《天书夜读:从汇编语言到windows内核编程》三 练习反汇编C语言程序
1) Debug版本算法反汇编,现有如下3×3矩阵相乘的程序: #define SIZE 3 int MyFunction(int a[SIZE][SIZE],int b[SIZE][SIZE],in ...
- Espresso浅析和使用
欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ Espresso是一个Google官方提供的Android应用UI自动化测试框架.Google希望,当Android的开发者利用Espress ...
- .net core2 发送电子邮件封装
在.net core2 如何发送电子邮件呢,我们选择使用自带的System.Net.Mail,下面我们将如何使用封装成一个函数,供大家参考. /// <summary> /// 发送电子邮 ...
- [转载] Spark:大数据的“电光石火”
转载自http://www.csdn.net/article/2013-07-08/2816149 Spark已正式申请加入Apache孵化器,从灵机一闪的实验室“电火花”成长为大数据技术平台中异军突 ...