rsync+inotify实时数据同步多目录实战
rsync+inotify实时数据同步多目录实战
inotify配置是建立在rsync服务基础上的配置过程
操作系统
主机名 | 网卡eth0 | 默认网关 | 用途 |
root@58server1 | 192.168.1.111 | 192.168.1.1 | Rsync服务端 |
root@58client | 192.168.1.121 | 192.168.1.1 | Rsync 节点 |
子网掩码均为255.255.255.0
具体需求:
要求在58server1上以rsync守护进程的方式部署rsync服务,使得root@58client的 rsync节点客户端主机把/data/数据目录和/data0/www目录中的数据同步到58server1 rsync服务端中
一、在配置inotify前己经把root@58server1 Rsync服务端的rsync服务部置好
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
[root@58server1 ~]# cat /etc/rsyncd.conf
#Rsync server
#created by oldboy 15:01 2009-6-5
##rsyncd.conf start##
uid = root
gid = root
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.1.1/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
#####################################
[www]
comment = www by old0boy 14:18 2012-1-13
path = /data0/www/
#####################################
[data]
comment = bbs by old0boy 14:18 2012-1-13
path = /data/
#####################################
|
二、开始安装
在安装inotify-tools前请先确认你的linux内核是否达到了2.6.13,并且在编译时开启CONFIG_INOTIFY选项,
1) 查看当前系统是否支持inotify
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@58client ~]# uname -r
2.6.18-308.el5
[root@58client ~]# ls -l /proc/sys/fs/inotify/
total 0
-rw-r--r-- 1 root root 0 May 4 22:33 max_queued_events
-rw-r--r-- 1 root root 0 May 4 22:33 max_user_instances
-rw-r--r-- 1 root root 0 May 4 22:33 max_user_watches
|
#显示这三个文件则证明支持
2)下载inotify源码包
1
2
3
4
5
|
[root@58client ~]# mkdir /home/Mr.Xing/tools/ -p
[root@58client ~]# cd /home/Mr.Xing/tools/
[root@58client tools]# wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
|
3)编译安装inotfiy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@58client tools]# ls
inotify-tools-3.14.tar.gz
[root@58client tools]# tar zxf inotify-tools-3.14.tar.gz
[root@58client tools]# cd inotify-tools-3.14
[root@58client inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify-tools-3.14
[root@58client inotify-tools-3.14]# make
[root@58client inotify-tools-3.14]# make install
[root@58client inotify-tools-3.14]# cd ..
[root@58client tools]# ln -s /usr/local/inotify-tools-3.14/ /usr/local/inotfiy
[root@58client tools]# ls -l /usr/local/|grep inotify
lrwxrwxrwx 1 root root 30 May 4 22:42 inotfiy -> /usr/local/inotify-tools-3.14/
drwxr-xr-x 6 root root 4096 May 4 22:41 inotify-tools-3.14
|
参数:
--prefix=PATH 指定编译安装的路径
提示:更多的编译参数可以使用./configure –h 查看,编译成功后会生成4个目录,
小软件一般规范安装到同一个目录,一般为/usr/local中
建立一个软链接
进入安装inotify的目录
1
2
3
4
5
6
7
8
9
10
11
|
[root@58client tools]# ls -l /usr/local/inotify-tools-3.14/
total 16
drwxr-xr-x 2 root root 4096 May 4 22:41 bin #inotfiy执行命令(二进制)
drwxr-xr-x 3 root root 4096 May 4 22:41 include #inotfiy程序所需用的头文件
drwxr-xr-x 2 root root 4096 May 4 22:41 lib #动态链接的库文件
drwxr-xr-x 4 root root 4096 May 4 22:41 share #帮助文件
|
4) 编写inotify实时监控脚本 编写两个脚本,分别对应所共享的两个目录
如本例子,我们编写两个脚本分别为 data_inotify.sh 和www_inotify.sh
开始编写inotify脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
[root@58client inotify]# mkdir /server/scripts/ -p
[root@58client inotify]# cd /server/scripts/
[root@58client scripts]# vi data_ inotify.sh
[root@58client scripts]# cat data_inotify.sh
#!/bin/bash
#para
host01=192.168.1.111
src=/data
dst=data
user=rsync_backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify-tools-3.14/
#judge
if [ ! -e "$src" ] \
|| [ ! -e "${rsync_passfile}" ] \
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \
|| [ ! -e "/usr/bin/rsync" ];
then
echo "Check File and Folder"
exit 9
fi
${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \
| while read file
do
# rsync -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null 2>&1
cd $src && rsync -aruz -R --delete ./ --timeout=100 $user@$host01::$dst --password-file=${rsync_passfile} >/dev/null 2>&1
done
exit 0
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
[root@58client scripts]# vi www_ inotify.sh
[root@58client scripts]# cat www_inotify.sh
#!/bin/bash
#para
host01=192.168.1.111
src= /data0/www
dst=www
user=rsync_backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify-tools-3.14/
#judge
if [ ! -e "$src" ] \
|| [ ! -e "${rsync_passfile}" ] \
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \
|| [ ! -e "/usr/bin/rsync" ];
then
echo "Check File and Folder"
exit 9
fi
${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \
| while read file
do
# rsync -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null 2>&1
cd $src && rsync -aruz -R --delete ./ --timeout=100 $user@$host01::$dst --password-file=${rsync_passfile} >/dev/null 2>&1
done
exit 0
|
一般添加了脚本后要格式化一次脚本
1
2
3
4
5
6
7
8
9
|
[root@58client scripts]# dos2unix www_inotify.sh
dos2unix: converting file www_inotify.sh to UNIX format ...
[root@58client scripts]# dos2unix data_inotify.sh
dos2unix: converting file data_inotify.sh to UNIX format ..
|
分别运行两个脚本:
1
2
3
4
5
6
7
|
[root@58client scripts]# sh www_inotify.sh &
[1] 3114
[root@58client scripts]# sh data_inotify.sh &
[2] 3118
|
测试:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@58client ~]# touch /data/aa
[root@58client ~]# ls /data
aa
[root@58client ~]# touch /data0/www/aa
[root@58client ~]# ls /data0/www/
aa bbs blog www
[root@58server1 data]# ls /data/
aa
[root@58server1 data]# ls /data0/www/
aa bbs blog www
|
rsync+inotify实时数据同步多目录实战的更多相关文章
- rsync+inotify实时数据同步单目录实战
rsync+inotify实时数据同步单目录实战 rsync+inotify实时数据同步单目录实战 inotify是一个强大的.细粒度的.异步的文件系统事件监控机制,linux内核从2.6.13起 ...
- Rsync+inotify 实时数据同步 inotify master 端的配置
强大的,细致的,异步的文件系统事件监控机制.Linux 内科从 2.6.13 起支持 inotify Inotify 实现的几款软件:Inotify,sersync,lsyncd ※Inotify 实 ...
- Linux学习系列之Inotify+Rsync实现实时数据同步
Inotify简介 inotify介绍 inotify是一种强大的.异步的文件系统监控机制,linux内核从2.6.13起,加入了inotify的支持,通过inotify可以监控文件系统中添加.删除. ...
- Inotify+rsync实现实时数据同步
使用rsync可以实现数据同步,但是即使使用crontab定时任务最小执行间隔为1分钟,在数据实时性要求比较高场合需使用inotify+rsync实现实时同步 下载inotify wget https ...
- centos7部署inotify与rsync实现实时数据同步
实验环境:CentOS Linux release 7.6.1810 node1:192.168.216.130 客户端(向服务端发起数据同步) node2:192.168.216.132 服务端(接 ...
- rsync+inotify实时数据同步
没有实际的用过,先mark一下,后面实践. https://www.osyunwei.com/archives/7447.html 一.为什么要用Rsync+sersync架构? 1.sersync是 ...
- rsync+inotify 实时双向同步
前言 在遇到需要 nginx 负载均衡,承受较高并发的情况,同时会有双机相同目录内容须保持一致的需求 rsync+inotify 是一个不错的解决方案,相较于 rsync+sersync 在处理大量文 ...
- 我的一次rsync+inotify本地数据同步示例
环境: web工作目录:/var/www/mydafuhao git仓库目录: /var/www/mydafuhao.git/mydafuhao 需求:inotify监控git仓库目录,发现有版本更新 ...
- Centos rsync+inotify 实现数据同步备份
最近公司做了一
随机推荐
- 阶段3 3.SpringMVC·_01.SpringMVC概述及入门案例_08.RequestMapping注解的作用
用于建立请求URL和处理请求方法之间的对应关系. 增加一个testResuqestMapping方法来测试 把注解放在类上 服务器重新部署 再次重新部署 这次就可以请求到数据 了 注解放在类上:用来表 ...
- fixture详细介绍-作为参数传入,error和failed区别
前言 fixture是pytest的核心功能,也是亮点功能,熟练掌握fixture的使用方法,pytest用起来才会得心应手! fixture简介 fixture的目的是提供一个固定基线,在该基线上测 ...
- Centos下使用subversion
Centos下使用subversion 1.安装 yum install subversion 2.创建版本库 a.mkdir -p /var/svn/repositories(创建版本库目录) b. ...
- django 数据库操作详解
Django配置使用mysql数据库 修改 settings.py 中的 DATABASES 注意:django框架不会自动帮我们生成mysql数据库,所以我们需要自己去创建. DATABASES ...
- centos7 忘记root密码,如何进入单用户模式。
init方法 1.centos7的grub2界面会有两个入口,正常系统入口和救援模式: 2.修改grub2引导 在正常系统入口上按下"e",会进入edit模式,搜寻ro那一行,以l ...
- select去掉默认样式
今天遇到的问题,并在这里做一下记录和总结 去除select下拉框默认样式 select { /*Chrome和Firefox里面的边框是不一样的,所以复写了一下*/ border: solid 1px ...
- docker 运行mysql最新版本用navicat连接报错:1251
主要是:新版的mysql的加密方式发生了变化,解决方法如下: 1:进入docker容器: docker exec -it mysql(启动mysql时候起的别名) /bin/bash 2:登陆my ...
- 关于多线程efcore dbcontext 的解决方案。
首先我们大部分的efcore框架用的DbContext(或者封装的repo)都是底层注入的上下文容器实体. 然后Dbcontext不是线程安全的,也就是说,你在当前线程中,只能创建一个 DbConte ...
- 小记------mongodb数据库如何进行模糊查询
// 模糊匹配createTime 是以 2019-07-23 开头 db.getCollection('driver_online_record').find({"createTime ...
- 手撕ES6--Promise
手撕ES6--Promise:https://www.jianshu.com/p/0925eae38d2c 手写一个Promise,附源码分析:https://blog.csdn.net/weixin ...