CentOS 7 部署inotify实时监控(NFS服务器上部署,rsync服务器测试)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7 部署inotify实时监控(NFS服务器上部署,rsync服务器测试)相关的知识,希望对你有一定的参考价值。
1.简介
1.1inotify
一个 Linux 内核特性,它监控文件系统,并且及时向专门的应用程序发出相关的事件警告,比如删除、读、写和卸载操作等。
2.环境准备
[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[[email protected] ~]# uname -r
3.10.0-327.el7.x86_64
[[email protected] ~]# getenforce
Disabled
[[email protected] ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
[[email protected] ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.31 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fe7a:66a4 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:7a:66:a4 txqueuelen 1000 (Ethernet)
RX packets 1195 bytes 283633 (276.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 198 bytes 24332 (23.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.1.31 netmask 255.255.255.0 broadcast 172.16.1.255
inet6 fe80::20c:29ff:fe7a:66ae prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:7a:66:ae txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 744 (744.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3.NFS服务器部署inotify服务
3.1安装inotify
[[email protected] ~]# yum install -y inotify-tools
3.2编写实时同步脚本
[[email protected] ~]# cat /server/scripts/inotify.sh
#!bin/bash
inotifywait -mrq --format "%w%f" -e create,close_write,delete,moved_to /data/|\
while read zy
do
rsync -az /data/ --delete [email protected]::backup --password-file=/etc/rsync.password
done
4.测试
4.1运行脚本
[[email protected] ~]# sh /server/scripts/inotify.sh
4.2在NFS服务器的/data目录创建测试文档
[[email protected] data]# touch test.txt
[[email protected] data]# ls
test.txt
4.3rsync服务器的/backup目录查看
[[email protected] ~]# ls /backup/
test.txt
以上是关于CentOS 7 部署inotify实时监控(NFS服务器上部署,rsync服务器测试)的主要内容,如果未能解决你的问题,请参考以下文章