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/02 Report--
Compared with traditional cp and tar backup methods, rsync has the advantages of high security, rapid backup and supporting incremental backup. Rsync can solve the data backup requirements that are not high in real-time, such as regularly backing up file server data to remote servers, regularly mirroring the local disk and so on.
192.168.0.1 Source server has directory / opt/test/
192.168.0.2 Target server has directory / opt/bak/test/
The purpose of the implementation is to keep a file directory of the two servers synchronized in real time.
Implementation method: through rsync+inotify-tools combination to achieve
Preparatory work:
The first step is to add a trust relationship to the two machines, which has been introduced in the previous article.
For more information, please see linux add trust relationship and login without password.
Software needs to be installed:
1. Rsync synchronization software
Installation is required on both the source and target servers
Source server: is a rsync client and does not need to be configured
Target server: rsync server side, need to configure the content in / etc/rsyncd.conf
2. Inotify-tools tool
This tool is a file real-time monitoring tool, which requires kernel support of linux operating system, and kernel support should be at least 2.6.13.
Check if the operating system supports it, as follows:
Uname-r View version
Return:
2.6.32-358.6.1.el6.x86_64
If version 2.6.32 is greater than 2.6.13, it is supported.
Execute:
Ll / proc/sys/fs/inotify total 0-rw-r--r-- 1 root root 0 Oct 18 12:18 max_queued_events-rw-r--r-- 1 root root 0 Oct 18 12:18 max_user_instances-rw-r--r-- 1 root root 0 Oct 18 12:18 max_user_watches
If there are three outputs, it means that inotify is supported by default and the inotify-tools tool can be installed.
If not, a new version of the linux operating system is required
If the version meets the requirements, you can install it.
After installing inotify-tools, the following two files are generated in the relevant installation directory:
Ll / usr/local/bin/ total 88-rwxr-xr-x 1 root root 44327 Oct 10 15:32 inotifywait-rwxr-xr-x 1 root root 41417 Oct 10 15:32 inotifywatch
Indicates that the installation was successful.
Note: installation is required on the source server, but not on the target server.
3. Related scripts:
Create a new script on the source server:
Inotify_bak.sh
#! / bin/bash src=/opt/test/ / usr/local/bin/inotifywait-mrq-- timefmt'% d/%m/%y% HV% M'-- format'% T% w% f% e'- e close_write,delete,create Attrib $src | while read file do / usr/bin/rsync-arzuq $src 192.168.0.1::www/ echo "${file} was rsynced" > > / opt/soft/log/rsync.log 2 > & 1 done
Give execution permission: chmod + x inotify_bak.sh
Then execute: nohup inotify_bak.sh & put it into the background to execute
4. About startup
Target server: start rsync backend service first: / usr/bin/rsync-- daemon
Source server: execute inotify_bak.sh &
5. Test:
Create a new directory and file in the source server directory, which will be detected by the inotify_bak.sh script and synchronized to the relevant directory of the target server
You can view the log file: / opt/soft/log/rsync.log command: observe the real-time synchronization.
Tail-f / opt/soft/log/rsync.log error resolution: / usr/local/bin/inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object file: No such file or directory
This is because the library file can not be found. Just make a soft connection.
Ln-s / usr/local/lib/libinotifytools.so.0 / usr/lib64/libinotifytools.so.0
The original text is from: https://www.linuxprobe.com/rsync-scp.html
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.