Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Real-time data synchronization based on rsync+sersync

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

One with sersync and one with rsync service

Sersync server (data source, source machine): 192.168.0.63

Rsync client (backup side, target machine): 192.168.0.64

1. Why use the rsync+sersync architecture?

(1) sersync is based on inotify development, similar to inotify-tools tools.

(2) sersync can record the name of a specific file or directory that has changed (including adding, deleting, modifying) in the listening directory, and then use rsync to synchronize only the changed files or directories.

2. What is the difference between rsync+inotify-tools and rsync+sersync architecture?

(1) rsync+inotify-tools

1) inotify can only record the change (add, delete, change) of the listening directory, but not which file or directory has changed.

2) when rsync synchronizes, it does not know which file or directory has changed, and every time it synchronizes the entire directory. When the amount of data is very large, the synchronization of the entire directory is very time-consuming (rsync has to traverse the entire directory to find comparison files), so the efficiency is very low.

(2) rsync+sersync

1) sersync can record the name of a specific file or directory that has changed (add, delete, change) in the listening directory.

2) when rsync synchronizes, it only synchronizes the changed files or directories (the data that changes each time is very small compared to the whole synchronized directory data, and rsync is very fast when traversing to find and compare files), so it is very efficient.

3. Synchronization process:

(1) enable the sersync service on the synchronization server, and sersync is responsible for monitoring the changes of file system events in the configuration path.

(2) call the rsync command to synchronize the updated files to the target server.

(3) you need to configure sersync on the master server and rsync server on the synchronization target server (note: it is a rsync service).

4. Synchronization process and principle:

(1) the user writes update file data to the sersync server in real time.

(2) at this point, you need to configure sersync service on the synchronization master server.

(3) start the rsync daemon service on another server to pull data from the sersync server synchronously.

(4) start the rsync daemon service on another server to bring in the sersync push files.

Through the daemon service of rsync, we can find that sersync is actually monitoring local data write or update events, and then, after calling the command of the rsync client, the file corresponding to the write or update event is pushed to the target server through rsync, as shown in figure 2-3.

Figure 2-3 schematic diagram of synchronization process

2.3.1 download sersync

1. Download the executable version of sersync from google code, which contains configuration files and executable files

Wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz (sometimes downloads fail, all need to be kept locally)

2. Upload to the server / opt directory.

[root@xuegod63 ~] # cd / opt # switch the working directory to the / opt directory.

[root@xuegod63 opt] # tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz # decompress.

[root@xuegod63 opt] # mv GNU-Linux-x86 sersync # unzipped file is renamed to sersync.

2.3.2 configure sersync

[root@xuegod63 opt] # cd sersync # switch the working directory to the sersync directory.

[root@xuegod63 sersync] # cp confxml.xml confxml.xml.bak # backup configuration file for second modification

1. Change the optimized sersync profile:

[root@xuegod63 sersync] # vim confxml.xml # modify line 24 Murray 28 in the configuration file, as shown below.

# Local synchronization data directory.

# rsync module name

two。 Modify line 31Murray 34, authentication section (rsync password authentication).

3. Turn on the sersync daemon to synchronize data.

[root@xuegod63 sersync] # / opt/sersync/sersync2-d-r-o / opt/sersync/confxml.xml

Figure 2-4 start the sersync daemon

4. test

(1) add, delete or change directory files in the 63 / var/www/html/ directory.

(2) see the changes in the 64 / web-back directory

[root@xuegod64 web-back] # watch ls-l

5. Set up automatic execution of sersync monitoring boot

[root@xuegod63 sersync] # vi / etc/rc.d/rc.local # edit the rc.local file and add a line at the end.

/ opt/sersync/sersync2-d-r-o / opt/sersync/confxml.xml # set to boot and run the script automatically.

6. Add a script to monitor whether sersync is running properly

[root@xuegod63 ~] # vi / opt/check_sersync.sh # edit the script and add the following code.

#! / bin/sh

Sersync= "/ opt / sersync/sersync2"

Confxml= "/ opt / sersync/confxml.xml"

Status=$ (ps aux | grep' sersync2' | grep-v 'grep' | wc-l)

If [$status-eq 0]

Then

$sersync-d-r-o $confxml &

Else

Exit 0

Fi

[root@xuegod63 ~] # chmod + x / opt / check_sersync.sh # add script execution permissions.

Add this script to the task schedule and perform tests on a regular basis.

Those who are interested in learning Linux cloud computing architect can follow me!

I would like to recommend some entry-level learning materials, all of which are classic learning materials!

CCNA Network Foundation course

Http://edu.51cto.com/sd/3ee4c

Please compare the latest version of the basic learning video of Linux centos7 to the diced mushroom course and don't buy it if the outline is the same!

Http://edu.51cto.com/sd/d572a

Introduction to python3 function programming

Http://edu.51cto.com/sd/dd128

WEB development engineer JavaScript all your aircraft war game development video course

Http://edu.51cto.com/sd/c6223

If you are good at basic learning, you can try to understand Linux Docker virtualization and Kubernetes container cluster management.

Http://edu.51cto.com/sd/480b1

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report