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: https://rsync.samba.org/

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

Example:
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/rsyncd.pid) 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_INSTANCES #ТЕМЕРИНГ МОНИТОРИНГ
     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

Example:

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 192.168.184.10 rsync
Slave CentOS7 192.168.184.20 rsync / inotify-tools-3.14.tar.gz

Low concurrency: backup master server data to slave server

1、MA(192.168.184.10)

systemctl stop firewalld.service 
setenforce 0

yum -y install httpd rsync 

vim /etc/rsyncd.conf 

uid = nobody
gid = nobody
use chroot = yes                                                
address = 192.168.184.10
port 873                                                                
log file = /var/log/rsyncd.log                  
pid file = /var/run/rsyncd.pid                  
hosts allow = 192.168.184.0/24
[wwwroot]                                                               
path = /var/www/html                                    
comment = Document Root of www.lic.com
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
kiki:123123

chmod 600 /etc/rsyncd_users.db

rsync --daemon
netstat -natp | grep rsync

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

2、Abd 192.168.184.20

systemctl stop firewalld.service 
setenforce 0

yum -y install rsync

cd /opt
mkdir haha
chmod 777 haha

vim /etc/server.pass
123123

chmod 600 /etc/server.pass 

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

ls haha


1、MA(192.168.184.10)

vim /etc/rsyncd.conf
read only = no

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

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


2、Abd 192.168.184.20

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/

./configure
make && make install



vim /opt/inotify.sh
#!/bin/bash
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"
 
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
    if [ $(pgrep rsync | wc -l) -le 0 ] ; then
        $RSYNC_CMD
	fi
done

cd /opt/
chmod +x inotify.sh 
./inotify.sh 

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

Master (192.168.184.10) Check

cd /var/www/html
ls


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

Rain(192.168.184.10)

Slave(192.168.184.20)

master(192.168.184.10)


End

Leave a Comment