RSYNC Downward Synchronization + real-time synchronization post notification (detailed graphical explanation)

Fast incremental backup tool

  • remote sync and remote sync
  • Support for local replication or synchronization with other SSH and RSYNC hosts
  • Official website:

  • RSYNC synchronous source
  • Refers to the remote backup server, also known as backup sources

The server synchronizes the data of server B, and server B is the backup source
On the contrary, server B synchronizes server data, and then server A is the backup source

1. Main ideas

  • Set the configuration file rsyncd.conf, an independent account file
  • Enable rsync-daemon mode

2. Prepare the rsyncd.conf file

  • Authentication configuration users, secrets file without adding it, it is anonymous

3. Independent account file

  • Username password
  • User log for each line
  • Independent account data, not dependent on the system account number

4. Enable the RSYNC service

  • Through -daemon to provide services by itself, rsync-daemon
  • do –kill $(cat /var/run/ Close the service

  • Driving by rules

    Rsync [опции] исходное местоположение целевого местоположения позиции
  • General options

-a Archive mode, recursive and preserving object attributes, is equivalent to -rlptgod
-Fifth Show details of the sync process
-z pressure during transmission
-h Save the hard link file
-a Save ACL attribute information
-delete Delete the file with the target location and the source location without the source location
– Checksum Specify whether to skip the file according to the check and the item
…… ……

The role of delete is simple, that is, to delete the differential files and keep the sequence

Format 1:

[email protected] address :: name модуля поделиться

Second format:

rsync: // [email protected] address/name модуля обмена

You can monitor the file system change and respond to the notification

  • Setting initial kernel parameters (improved)

  • /etc/sysctl.conf (kernel parameter configuration file)

    MAX_QUEUE_EVENTS #Monitoring События Размер очереди
     MAX_USER_WATCHES #ECHEACE ENCESTER MORITE максимальное количество файлов  
  • INOTIFYWAIT: For continuous monitoring of output results in real time

  • Inotifywatch: For short-term monitoring, it displays the result after the task is completed


inotifywait -mrq -e modify,create,move,delete /var/www/html
M Keep watching
-r Frequent monitoring of all sub-objects
-Q Simplify the output
-e Events to identify, events to monitor
change Repair
Create Create
moves moves
delete delete

  • environment configuration
Perfects OS IP address Program/Package/Installation Tools
Perfects CentOS7 rsync
Slave CentOS7 rsync / inotify-tools-3.14.tar.gz

Low concurrency: backup master server data to slave server


systemctl stop firewalld.service 
setenforce 0

yum -y install httpd rsync 

vim /etc/rsyncd.conf 

uid = nobody
gid = nobody
use chroot = yes                                                
address =
port 873                                                                
log file = /var/log/rsyncd.log                  
pid file = /var/run/                  
hosts allow =
path = /var/www/html                                    
comment = Document Root of
read only = yes                                                  
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z        
auth users = kiki                                               
secrets file = /etc/rsyncd_users.db             

vim /etc/rsyncd_users.db

chmod 600 /etc/rsyncd_users.db

rsync --daemon
netstat -natp | grep rsync

cd /var/www/html
touch aaa.html bbb.html


systemctl stop firewalld.service 
setenforce 0

yum -y install rsync

cd /opt
mkdir haha
chmod 777 haha

vim /etc/server.pass

chmod 600 /etc/server.pass 

rsync -az --delete --password-file=/etc/server.pass [email protected]::wwwroot /opt/haha

ls haha


vim /etc/rsyncd.conf
read only = no

kill `cat /var/run/`
netstat -natp | grep rsync

rsync --daemon
netstat -natp | grep rsync
chmod 777 /var/www/html


cat /proc/sys/fs/inotify/max_queued_events
cat /proc/sys/fs/inotify/max_user_instances 
cat /proc/sys/fs/inotify/max_user_watches 

vim /etc/sysctl.conf 

fs.inotify.max_queued_events = 32768
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576

sysctl -p

yum -y install gcc gcc-c++ 

 #Put в пакете установки
tar zxvf inotify-tools-3.14.tar.gz -C /opt

cd /opt/inotify-tools-3.14/

make && make install

vim /opt/
INOTIFY_CMD="inotifywait -mrq -e create,delete,move,modify,attrib /opt/haha/"
RSYNC_CMD="rsync -azH --delete --password-file=/etc/server.pass /opt/haha/ [email protected]::wwwroot"
    if [ $(pgrep rsync | wc -l) -le 0 ] ; then

cd /opt/
chmod +x 

cd /opt/haha
touch ccc.html
rm -rf aaa.html

Master ( Check

cd /var/www/html

However, there will be an error when synchronizing the above slave. The reason is that we are logging in as an anonymous user





Leave a Comment