


Share rsync+inotify real-time synchronization example tutorial
1.rsync
Compared with the traditional cp, tar backup methods, rsync has the advantages of high security, fast backup, and supports incremental backup. rsync can solve data backup needs that do not require high real-time performance, such as Regularly back up file server data to remote servers, regularly perform data mirroring on local disks, etc.
As the scale of application systems continues to expand, higher requirements are put forward for data security and reliability, rsync is also gradually exposed in high-end businesses There are many shortcomings. First of all, during rsync real-time synchronization, all files need to be scanned for comparison and differential transmission. If the number of files reaches millions or even tens of millions, scanning all files is very time-consuming, and only a small part of them are changing, which is a very inefficient way. Secondly, rsync cannot monitor and synchronize data in real time. Although it can perform start synchronization through the linux daemon, there will be a time difference between the two start actions, which will lead to inconsistencies between the server and the client, making it impossible to completely recover data in the event of an application failure. . Based on the above reasons, rsync+inotify appeared!
2.inotify (monitoring)
inotify is a powerful, fine-grained, asynchronous file System event monitoring mechanism. Through inotify, you can monitor various subtle events such as addition, deletion, modification, and movement in the file system. Using this kernel interface, third-party software can monitor various events under the file system. The situation changes, and inotify-tools is such a third-party software.
1. Server configuration (only need to install rsync)
Share to /tmp/:
1.Add virtual useruseradd rsync -s /sbin/nologin
chown -R rsync.rsync /tmp/
2.Configurationrsyncd.confConfiguration file
vim rsyncd.conf
#rsync_config_config_start
#rsyncd.conf start
##uid = rsync(user)
gid = rsync(user)
use chroot = no (to prevent security issues)
max connections = 200 (how many clients can connect to my backup server)
timeout = 300 (timeout, disconnect the connection after no action for a long time)
pid file = /var/run/rsyncd.pid (process number, Put the process number in this file)
lock file = /var/run/rsync.lock (equivalent to the concept of "lock", the concept of locking the door in the toilet)
log file = /var/log/rsyncd.log (an error occurred, you can view the log file)
[tmp](module)
path = /tmp/(path)
ignore errors
read only = false (read-only means false, readable and writable)
list = false (not allowed list)
hosts allow = 10.0.0.0/24 (allowed hosts)
hosts deny = 0.0.0.0/32 (denied hosts)
auth users = rsync_backup (support virtual users)
secrets file = /etc/rsync.password (user’s corresponding password file)
#rsync_config_config_______________end
3. Create a password file
echo “rsync_backup:123456” >/etc/rsync.password
All password files600Permissionschmod 600 /etc/rsync.password
4 .rsync --daemon daemonmode startup
5.Addrsync --daemon/etc/rc.local
echo “/ usr/bin/rsync --daemom” >>/etc/rc.local
2. Client configuration
Installationrsyncandinotify
1.Installation rsync(yumJust install it)
2. Create a password authentication file
echo “123456” >/etc/rsync.password Only password required
Set permissions600 chmod 600 /etc/rsync.password
3.Installationinotify:
cd /home/cai/tools/
wget
54 tar xf inotify-tools-3.14.tar.gz
55 ls
56 cd inotify-tools-3.14
57 ./configure --prefix=/usr/local/inotify-tools-3.14
58 make && make install
59 yum install -y gcc
60 ./configure --prefix=/usr/local/inotify-tools-3.14
61 make && make install
62 cd /usr/local/inotify-tools-3.14/
63 ls
64 ln -s /usr/local/inotify-tools-3.14/ /usr/local/inotify
4.
Scripts are placed under/server/scripts
vim /server/scripts /rsync.sh
#!/bin/sh
host=192.168.76.129
src=/tmp/
des=tmp
user=rsync_backup
/usr /local/inotify/bin/inotifywait -mrq --timefmt '%d%m%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | \
while read files
do
/usr/bin/rsync -avz --delete $src $user@$host::$des --password-file=/etc/rsync.password
echo "${files} was rsynced" >> ;/var/log/rsyncd.log 2>&1
done
exit o
~
and give
764 permission
Test script:sh -x /server/scripts/rsync.sh
Run the script:sh /server/scripts/rsync.sh &
Put thersync.sh script into the boot entry: echo “/tmp/rsync.sh” >>/ etc/rc.local
The above is the detailed content of Share rsync+inotify real-time synchronization example tutorial. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Generally speaking, we only need to use one of the headphones or speakers at the same time. However, some friends have reported that in the win11 system, they encountered the problem of headphones and speakers sounding at the same time. In fact, we can turn it off in the realtek panel and it will be fine. , let’s take a look below. What should I do if my headphones and speakers sound together in win11? 1. First find and open the "Control Panel" on the desktop. 2. Enter the control panel, find and open "Hardware and Sound" 3. Then find the "Realtek High Definition" with a speaker icon. Audio Manager" 4. Select "Speakers" and click "Rear Panel" to enter the speaker settings. 5. After opening, we can see the device type. If you want to turn off the headphones, uncheck "Headphones".

When you find that one or more items in your sync folder do not match the error message in Outlook, it may be because you updated or canceled meeting items. In this case, you will see an error message saying that your local version of the data conflicts with the remote copy. This situation usually happens in Outlook desktop application. One or more items in the folder you synced do not match. To resolve the conflict, open the projects and try the operation again. Fix One or more items in synced folders do not match Outlook error In Outlook desktop version, you may encounter issues when local calendar items conflict with the server copy. Fortunately, though, there are some simple ways to help

With the continuous development of Internet technology, real-time video streaming has become an important application in the Internet field. To achieve real-time video streaming, the key technologies include WebSocket and Java. This article will introduce how to use WebSocket and Java to implement real-time video streaming playback, and provide relevant code examples. 1. What is WebSocket? WebSocket is a protocol for full-duplex communication on a single TCP connection. It is used on the Web

Utilizing C++ to implement real-time audio and video processing functions of embedded systems The application range of embedded systems is becoming more and more extensive, especially in the field of audio and video processing, where the demand is growing. Faced with such demand, using C++ language to implement real-time audio and video processing functions of embedded systems has become a common choice. This article will introduce how to use C++ language to develop real-time audio and video processing functions of embedded systems, and give corresponding code examples. In order to realize the real-time audio and video processing function, you first need to understand the basic process of audio and video processing. Generally speaking, audio and video

Building a real-time chat room based on JavaScript With the rapid development of the Internet, people are paying more and more attention to instant messaging and real-time interactive experience. As a common instant messaging tool, real-time chat rooms are very important to both individuals and businesses. This article will introduce how to build a simple real-time chat room using JavaScript and provide corresponding code examples. We first need a front-end page as the UI interface of the chat room. Here is an example of a simple HTML structure: <!DOCTYPE

Building a real-time translation tool based on JavaScript Introduction With the growing demand for globalization and the frequent occurrence of cross-border exchanges and exchanges, real-time translation tools have become a very important application. We can leverage JavaScript and some existing APIs to build a simple but useful real-time translation tool. This article will introduce how to implement this function based on JavaScript, with code examples. Implementation Steps Step 1: Create HTML Structure First, we need to create a simple HTML

Live events are a great way to keep up with upcoming orders, sports games, and more. This new notification method was first introduced with the release of iOS 16 and is designed to improve the way notifications are delivered to iPhone. Any application that provides real-time data can take advantage of real-time activity, and many popular uses are tracking pending orders, scores from ongoing matches, weather data, upcoming live broadcasts, and more. Live activity always shows up in your Notification Center, even in standby mode (if you've enabled standby mode and your iPhone is docked). However, you may want to disable Live Activity when using your Apple TV for an uninterrupted experience. Here's how you do it on your iPhone. How to disable Apple TV

Introduction to building real-time stock quotation display based on JavaScript: With the continuous development of financial markets, the display of real-time stock quotation has become increasingly important for investors and traders. In a modern trading platform, it is essential to provide a real-time stock price display function. This article will introduce how to use JavaScript and some related technologies to build a simple real-time stock quote display application. Preparation work Before starting, you need to prepare the following work: a web page framework based on HTML and CSS
