0x0 Test Environment The headquarters production server and the branch backup server require remote data backup. The environment is as follows
0x1 Production server environment construction 0x1.1 Install gcc compiler and rsync
0x1.2 Copy inotify to the server and decompress it
0x1.3 Enter the inotify directory to install cd inotify-tools-3.13 ./configure make make install /usr/local/bin/inotifywait ##Check whether the installation is successful 0x2 Backup server environment construction 0x2.1 Install xinetd and rsync
0x3 The following contents are synchronized between the two servers useradd -u 600 zytest passwd zytest zytest su - zytest -c 'mkdir /home/zytest/files' ##Create a synchronization directory 0x4 Configure rsyncd on the backup server 0x4.1 Edit /etc/xinetd.d/rsync and modify it according to the following content disable = yes ==> disable = no flags = IPv6 ==> flags = IPv4 server_args = --daemon ==> server_args = --daemon --config=/etc/rsyncd.conf 0x4.2 Edit /etc/rsyncd.conf and add the following script information uid = root gid = root use chroot = no max connections = 1000 strict mode = yes port = 873 pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /var/log/rsyncd.log # following for user "zytest", change for other users [zytest] path = /home/zytest ignore errors auth users =zytest secrets file = /home/rsync-dst.ps read only = no list = false Ps: The rsyncd configuration file is on xinetd, so the backup server installs xinetd 0x4.3 Write the password to the called password file and grant permissions echo zytest:zytest >> /home/rsync-dst.ps chmod 600 /home/rsync-dst.ps 0x4.4 Start rsync via xinetd /etc/rc.d/init.d/xinetd restart 0x5 Configure the inosync script file on the primary server 0x5.1 ** ##Edit /root/inosync and add script code ** #!/bin/sh #chkconfig: 3 78 10 #This file exists from compile if [ ! -f /usr/local/bin/inotifywait ] then echo "cannot start. file inotifywait NOT exist!" exit fi #This file is a runnable shell script if [ ! -f /usr/local/bin/inosync.so.1 ] then echo "contact administrator. inosync.so.1 NOT exist!" exit fi case "$1" in 'start') /usr/local/bin/inosync.so.1 & ;; 'stop') pid=`ps -ef | grep -v grep | grep "inotifywait" | awk '{print $2}'` kill -9 $pid 2>&1 ;; 'restart') $0 stop $0 start ;; esac 0x5.2 Grant script permissions and set it to start at boot chmod a+x /root/inosync cp /root/inosync /etc/rc.d/init.d 0x5.3 Configuration call main script file /root/inosync.so.1 rhost=**Backup server IP** user=zytest src=/home/zytest/files dst=zytest #dst corresponding to [zytest] in file /etc/rsyncd.conf on dst server log=/root/inosync.log /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M:%S' --format '%T %w%f %e' -e close_write,create,move,delete,attrib $src | while read files do echo == rsync begin == >> $log rsync -avP --password-file=/home/rsync-src.ps --delete $src $user@$rhost::$dst >> $log 2>&1 echo -- rsyncd -- >> $log date >> $log echo "${files} was rsynced " >> $log 2>&1 done PS: There is a space after %T and there is also a space between %f and %e 0x5.4 Grant permissions to the inosync.so.1 script and copy it to /usr/local/bin chmod a+x /root/inosync.so.1 cp /root/inosync.so.1 /usr/local/bin 0x5.5 Write the password to the called password file and grant permissions echo zytest >> /home/rsync-src.ps chmod 600 /home/rsync-src.ps 0x6 The target server sets inosync to automatically start and turns on the inosync service chkconfig --level 3 inosync on /etc/rc.d/init.d/inosync start 0x7 Test END Create files and folders in the /home/zytest/files directory on the production server and check whether the backup storage has also synchronized the files and folders. If so, synchronization is successful. The process can be viewed through the log tail -f /root/inosync.log Summarize This is the end of this article about how to use Rsync+Inotify in Linux to achieve real-time synchronization of local and remote data. For more information about how to use rsync+inotify to achieve remote real-time synchronization, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the encapsulation and use of the Vue image magnifier component
>>: Tutorial on installing MYSQL8.0 on Alibaba Cloud ESC
This article shares the specific code of JavaScri...
!DOCTYPE Specifies the Document Type Definition (...
Equal height layout Refers to the layout of child...
illustrate: VMware IOInsight is a tool that helps...
Today I will introduce how to enable the Linux su...
Here are the types of data that can be verified l...
Table of contents Overview Front-end knowledge sy...
Table of contents 1. Use the a tag to preview or ...
The idea of using token for login verification ...
This article example shares the specific code of ...
MySQL 5.7 installation We are learning MySQL data...
The generation and verification of random codes i...
Install nginx Note that you must install nginx-fu...
What is pip pip is a Python package management to...
Table of contents Horizontal bar chart Dynamicall...