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
|
# cat /etc/rsyncd.conf
#Rsync server
#created by oldboy 15:01 2009-6-5
##rsyncd.conf start##
root
root
no
2000
600
pid
lock
log
errors
false
false
24
32
rsync_backup
password
#####################################
]
13
/
#####################################
]
13
/
#####################################
|
二、开始安装
在安装inotify-tools前请先确认你的linux内核是否达到了2.6.13,并且在编译时开启CONFIG_INOTIFY选项,
1) 查看当前系统是否支持inotify
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# uname -r
308.el5
# ls -l /proc/sys/fs/inotify/
0
max_queued_events
max_user_instances
max_user_watches
|
#显示这三个文件则证明支持
2)下载inotify源码包
|
1
2
3
4
5
|
# mkdir /home/Mr.Xing/tools/ -p
# cd /home/Mr.Xing/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
|
# ls
3.14.tar.gz
# tar zxf inotify-tools-3.14.tar.gz
# cd inotify-tools-3.14
# ./configure --prefix=/usr/local/inotify-tools-3.14
# make
# make install
# cd ..
# ln -s /usr/local/inotify-tools-3.14/ /usr/local/inotfiy
# ls -l /usr/local/|grep inotify
/
3.14
|
参数:
--prefix=PATH 指定编译安装的路径
提示:更多的编译参数可以使用./configure –h 查看,编译成功后会生成4个目录,
小软件一般规范安装到同一个目录,一般为/usr/local中
建立一个软链接
进入安装inotify的目录
|
1
2
3
4
5
6
7
8
9
10
11
|
# ls -l /usr/local/inotify-tools-3.14/
16
#inotfiy执行命令(二进制)
#inotfiy程序所需用的头文件
#动态链接的库文件
#帮助文件
|
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
|
# mkdir /server/scripts/ -p
# cd /server/scripts/
# vi data_ inotify.sh
# cat data_inotify.sh
#!/bin/bash
#para
192.168.1.111
data
data
rsync_backup
password
/
#judge
\
\
\
;
then
9
fi
\
file
do
# rsync -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null 2>&1
1
done
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
|
# vi www_ inotify.sh
# cat www_inotify.sh
#!/bin/bash
#para
192.168.1.111
www
www
rsync_backup
password
/
#judge
\
\
\
;
then
9
fi
\
file
do
# rsync -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null 2>&1
1
done
0
|
一般添加了脚本后要格式化一次脚本
|
1
2
3
4
5
6
7
8
9
|
# dos2unix www_inotify.sh
.
# dos2unix data_inotify.sh
.
|
分别运行两个脚本:
|
1
2
3
4
5
6
7
|
# sh www_inotify.sh &
3114
# sh data_inotify.sh &
3118
|
测试:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# touch /data/aa
# ls /data
aa
# touch /data0/www/aa
# ls /data0/www/
www
# ls /data/
aa
# ls /data0/www/
www
|