In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you how to achieve CentOS 5.4 rsync+inotify configuration triggered real-time file remote synchronization, the content is very detailed, interested friends can refer to, I hope to help you.
Software: rsync-2.6.8-3.1 (default installation for general systems), inotify-tools-3.14.tar.gz
Host: Linux-Master:10.10.50.217 (source host), Linux-Slave:10.10.50.151
1. Introduction
Inotify is a file system event monitoring mechanism that serves as an effective alternative to dnotify. Dnotify is a file monitoring mechanism supported by earlier kernels. Inotify is a powerful, fine-grained, asynchronous mechanism that meets a wide variety of file monitoring needs, not just security and performance.
File system events inotify can monitor include:
IN_ACCESS: file accessed
IN_MODIFY, file written
IN_ATTRIB, file attributes are modified, such as chmod, chown, touch, etc.
IN_CLOSE_WRITE, writable file is closed
IN_CLOSE_NOWRITE, non-writable files are closed
IN_OPEN, file is open
IN_MOVED_FROM, file removed, such as mv
IN_MOVED_TO, files are moved, such as mv, cp
IN_CREATE, creating a new file
IN_Deleted, file deleted, e.g. rm
IN_DELETE_SELF, self-delete, i.e. an executable file deletes itself when executed
IN_MOVE_SELF, self-moving, i.e. an executable file moves itself as it executes
IN_UNMOUNT, host file system is umount
IN_CLOSE, file is closed, equivalent to (IN_CLOSE_WRITE| IN_CLOSE_NOWRITE)
IN_MOVE, file moved, equivalent to (IN_MOVED_FROM| IN_MOVED_TO)
Note: The documents mentioned above also include directories.
=======================================================
2. Install software
Install inotify-tools-3.14.tar.gz in the source host
[root@Linux-Master src]# tar zxvf inotify-tools-3.14.tar.gz
[root@Linux-Master src]# cd inotify-tools-3.14
[root@Linux-Master inotify-tools-3.14]# ./ configure --prefix=/usr/local/inotify
[root@Linux-Master inotify-tools-3.14]# make && make install
=======================================================
3. Production SSH KEY
[root@Linux-Master ~]# ssh-keygen -t rsa
This command generates a key pair: id_rsa (private key file) and id_rsa.pub (public key file). By default, it is stored in the ~/.ssh/directory.
[root@Linux-Master ~]# scp ~/.ssh/id_rsa.pub root@10.10.50.151:~/.ssh/
[root@Linux-Slave src]# cat ~/.ssh/id_rsa.pub >> authorized_keys
[root@Linux-Slave src]#/etc/init.d/sshd restart
=======================================================
4. Writing scripts
The code is as follows:
#!/ bin/sh
srcdir="/usr/local/src/"
ip="10.10.50.151 10.10.50.141" #Multiple servers can add IP by themselves
dstdir="/usr/local/src/"
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y-%H:%M' --format '%T %w%f' -e modify,delete,create,attrib ${srcdir} \
| while read file
do
for i in $ip
do
rsync -aqztH --delete --progress ${srcdir} root@${i}:${dstdir}
done
done
To exclude synchronizing a directory, add the--exculde=PATTERN parameter to rsync, noting that the path is relative.
Finally, don't forget chmod +x.
5. rsync parameter description
-v, --verbose verbose mode output
-q, --quiet Reduced output mode
-c, --checksum Turns on the checksum switch to force verification of file transfers
-a, --archive archive mode, means to transfer files recursively and keep all file attributes, equal to-rlptgoD
-r, --recursive Subdirectories are processed recursively
-R, --relative Use relative path information
-b, --backup Creates a backup, that is, renames the old file to ~filename when the same file name already exists for the destination. You can use the--suffix option to specify different backup file prefixes.
--backup-dir Store backup files (such as ~filename) in the directory.
-suffix=SUFFIX Defines the backup file prefix
-u, --update updates only, i.e. skips all files that already exist in DST and are older than the files to be backed up. (Do not overwrite updated files)
-l, --links Keep soft links
-L, --copy-links Treat soft links like regular files
--copy-unsafe-links copies only links that point outside the SRC path directory tree
--safe-links Ignore links pointing outside the SRC path tree
-H, --hard-links Keep hard links
-p, --perms Keep file permissions
-o, --owner Keeps file ownership information
-g, --group Keep file group information
-D, --devices Keep device file information
-t, --times Keep file time information
-S, --sparse Special treatment of sparse files to save DST space
-n, --dry-run reality which files will be transferred
-W, --whole-file copies files without incremental detection
-x, --one-file-system Do not cross file system boundaries
-B, --block-size=SIZE The block size used by the verification algorithm, which defaults to 700 bytes
-e, --rsh=COMMAND Specify rsh, ssh for data synchronization
--rsync-path=PATH Specifies path information for rsync commands on remote servers
-C, --cvs-exclude automatically ignores files in the same way as CVS to exclude files that you don't want to transfer
--existing updates only those files that already exist in DST and does not back up newly created files
--delete Delete files that are not in SRC in DST
--delete-excluded Also deletes files on the receiving end that are excluded by this option
--delete-after transfer ends
--ignore-errors IO errors occur in a timely manner also delete
--max-delete=NUM Delete up to NUM files
--partial retains files that were not completely transferred for some reason, in order to expedite subsequent transfers
--force Force to delete directories, even if they are not empty
--numeric-ids does not match numeric user and group IDs to user and group names
--timeout=TIME IP timeout in seconds
-I, --ignore-times Do not skip files of the same time and length
--size-only When deciding whether to back up a file, look only at the file size, regardless of the file age
--modify-window=NUM Timestamp window used to determine if files are the same time, default is 0
-T --temp-dir=DIR Create temporary files in DIR
--compare-dest=DIR also compares files in DIR to determine if a backup is needed
-P equals--partial
--progress Shows the backup process
-z, --compress the backup file during transmission
--exclude=PATTERN Specifies to exclude file patterns that do not need to be transferred
--include=PATTERN Specifies file patterns that need to be transferred without exclusion
--exclude-from=FILE Excludes files of the specified pattern in FILE
--include-from=FILE does not exclude FILE specified pattern matching files
--version Print version information
--address Bind to a specific address
--config=FILE Specify a different configuration file than the default rsyncd.conf file
--port=PORT Specify another rsync service port
--blocking-io Use blocking IO on remote shells
-stats Gives the transfer status of certain files
--progress Realistic transmission process during transmission
--log-format=formAT Specifies the log file format
--password-file=FILE Get password from FILE
--bwlimit=KBPS Limit I/O bandwidth, KBytes per second
-h, --help Show help information
About how to achieve CentOS 5.4 rsync+inotify configuration triggered real-time file remote synchronization is shared here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
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.