In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to configure inotify to achieve real-time synchronization, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Synchronize the / var/www/html directory on the xinsz03.cn server to the / web-back directory on the xinsz04.cn host in real time.
Inotify Overview:
The Linux kernel has provided inotify notification interface since version 2.6.13, which is used to monitor various changes in the file system, such as file access, deletion, movement, etc. Using this mechanism, it is very convenient to realize file abnormal alarm, incremental backup, and respond in time to the change of directory or file.
With the combination of rsync tool and inotify mechanism, trigger backup (real-time synchronization) can be realized. As soon as the document in the original location changes, the incremental backup operation will be started immediately, otherwise it will be in a static wait-and-wait state, so as to avoid the problems of delay and over-density of backup according to a fixed cycle.
Inotify-tools-3.13.tar
Download address: http://sourceforge.net/projects/inotify-tools/
Check to see if inotify is supported and officially incorporate it into the kernel starting with kernel2.6.13.
[root@xinsz03.cn ~] # uname-r
2.6.32-220.el6.x86_64
Install inotify-tools-3.13.tar:
Upload
[root@xinsz03 ~] # rpm-ivh / mnt/Packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm
Rz upload
Sz download
Install inotify-tools-3.13.tar:
[root@xinsz03 ~] # tar-zxvfinotify-tools-3.13.tar.gz
[root@xinsz03 ~] # cdinotify-tools-3.13
[root@xinsz03inotify-tools-3.13] #. / configure check the installation environment
[root@xinsz03inotify-tools-3.13] # make-j 4 # make compile the source code into a binary, executable file
#-j 4 compiles with four processes simultaneously. Come on!
[root@xinsz03inotify-tools-3.13] # make install # installation
Test:
1. Use the inotifywait command to monitor changes to the website directory / var/www/html.
2. Add files to / var/www/html directory in another terminal, move files, and view the screen output results.
[root@xxinsz03] # inotifywait-h
Common parameters:
-e is used to specify which events to monitor.
These events include: create creation, move move, delete deletion, modify modification of file content, attrib property change.
-m means continuous monitoring
-r indicates recursion of the entire directory
-Q represents simplified output information.
[root@xinsz03] # inotifywait-mrq-e create,move,delete,modify / var/www/html/
Log in to another terminal, do relevant operations in the / var/www/html directory, and then go back to the original terminal to monitor the changes.
[root@xinsz03 ~] # echoaaa > / var/www/html/a.html
[root@xinsz03 ~] # mkdir/var/www/html/test
[root@xinsz03 ~] # cp/etc/passwd / var/www/html/test/
[root@xinsz03 ~] # rm-rf/var/www/html/test/passwd
View the changes:
[root@xinsz03] # inotifywait-mrq-e create,move,delete,modify / var/www/html/
/ var/www/html/ CREATEa.html
/ var/www/html/ MODIFYa.html
/ var/www/html/CREATE,ISDIR test
/ var/www/html/test/CREATE passwd
/ var/www/html/test/MODIFY passwd
/ var/www/html/test/DELETE passwd
Note: the monitoring results output using inotifywait include directories, events and files in turn in each row of records. Based on this, the changes can be identified.
Write trigger synchronization scripts
Idea: as long as you use inotifywait to detect an event, automatically execute rsync to synchronize.
[root@xinsz03] # inotifywait-mrq-e create,move,delete,modify / var/www/html/
/ var/www/html/ CREATE a.html
[root@xinsz03~] # cat a.sh
#! / bin/bash
Inotifywait-mrq-e create,move,delete,modify / var/www/html/ | while read a b c
Do
Rsync-azP--delete / var/www/html/ root@192.168.1.64:/web-back
Done
[root@xuegod63 ~] # chmod+x a.sh
Check to see if it is synchronized
[root@xinsz03 html] # pwd
/ var/www/html
[root@xinsz03 html] # touchmk.hmtl
View
[root@xuegod64 web-back] # ls
Grub mk2.hmtl mk.hmtl test
Test:
[root@xuegod63 ~] #. / a.sh
The data has been synchronized in real time.
View:
[root@xuegod64 web-back] # pwd
/ web-back
[root@xuegod64 web-back] # ls
Grub
Create a mk.html under / var/www/html of xinsz03, and then immediately go to xinsz04 to see if the file changes a lot, you can have a rsync synchronize and then perform a synchronization. Prevents simultaneous execution of multiple synchronization commands.
The above is all the contents of the article "how to configure inotify to achieve real-time synchronization". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.