In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how Linux can achieve real-time synchronization of local and remote remote data. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
0x0 test environment
Headquarters production server and branch backup server are required to back up data in different places, the environment is as follows
* * centos 6.5 backup * production server directory: / home/zytest/files backup server directory: / home/zytest/files user / password: zytest/ zytest
Construction of 0x1 production server environment
0x1.1 installs gcc compiler and rsync
Yum install gcc rsync-y
0x1.2 copies inotify to the server and decompresses it
Cd / root tar xfvz inotify-tools-3.13.tar.gz
0x1.3 goes to the inotify directory to install
Cd inotify-tools-3.13./configuremakemake install / usr/local/bin/inotifywait # # check whether the installation is successful
Setting up 0x2 backup server environment
0x2.1 installs xinetd and rsync
Yum install xinetd rsync-y
0x3 the following: two servers synchronize their operations
Useradd-u 600 zytest passwd zytest zytest su-zytest-c 'mkdir / home/zytest/files' # # create a synchronization directory
Configure rsyncd on the 0x4 backup server
0x4.1 editor / etc/xinetd.d/rsync is modified as follows
Disable = yes = = > disable = noflags = IPv6 = > flags = IPv4server_args =-- daemon = = > server_args =-- daemon-- config=/etc/rsyncd.conf
0x4.2 edit / etc/rsyncd.conf and add the following script information
Uid = rootgid = rootuse chroot = nomax connections = 1000strict mode = yesport = 873pid 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/zytestignore errorsauth users = zytestsecrets file = / home/rsync-dst.psread only = nolist = false
Ps: the rsyncd configuration file is on xinetd, so the backup server installs xinetd
0x4.3 writes the password to the calling password file and grants permissions
Echo zytest:zytest > > / home/rsync-dst.pschmod 600 / home/rsync-dst.ps
0x4.4 starts rsync through xinetd
/ etc/rc.d/init.d/xinetd restart
Configure inosync script files on the 0x5 master server
* * # Edit / root/inosync add script code * *
#! / bin/sh#chkconfig: 3 78 10 # This file exist from compileif [!-f / usr/local/bin/inotifywait] then echo "cannot start. File inotifywait NOT exist!" Exitfi # This file is runnable shell scriptif [!-f / usr/local/bin/inosync.so.1] then echo "contact administrator. Inosync.so.1 NOT exist!" Exitfi 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 > & 1X;' restart') $0 stop $0 start;; esac
0x5.2 gives the script permission to set boot up
Chmod axix / root/inosync cp / root/inosync / etc/rc.d/init.d
Main script file / root/inosync.so.1 for 0x5.3 configuration call
Rhost=** backup server IP**user=zytestsrc=/home/zytest/filesdst=zytest#dst corresponding to [zytest] in file / etc/rsyncd.conf on dst serverlog=/root/inosync.log/usr/local/bin/inotifywait-mrq-- timefmt'% d/%m/%y% HV% MVR% 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:% T is followed by a space between% f and% e
0x5.4 gives inosync.so.1 script permission to copy to / usr/local/bin
Chmod axix / root/inosync.so.1cp / root/inosync.so.1 / usr/local/bin
0x5.5 writes the password to the calling password file and grants permissions
Echo zytest > > / home/rsync-src.pschmod 600 / home/rsync-src.ps
0x6 target server sets inosync to automatically start and start the inosync service
Chkconfig-level 3 inosync on/etc/rc.d/init.d/inosync start
0x7 Test END
Create files and folders under the production server / home/zytest/files directory to see if the backup storage synchronizes the files and folders, and the synchronization is successful.
The process can be viewed through the log
Tail-f / root/inosync.log
At this point, this is the end of the article on the real-time synchronization of local and remote remote data by Linux through Rsync+Inotify.
This is how to realize the real-time synchronization of local and remote remote data in Linux shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.