Rsync is the data under Unix-like systems Mirror Backup tool--remote Sync,inotify is a Linux feature that monitors file system operations such as read, write, and create. The combination of the two enables real-time synchronization of files between the server and the client.
Experimental logic diagram
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6F/1E/wKioL1WSWOrRsbMjAACrIefFLOE128.jpg "title=" rsync+ Inotify.png "alt=" Wkiol1wsworrsbmjaacrieffloe128.jpg "/>
I. Install and configure RSYNC service
Master, standby server check if Rsync service is installed, typically the system is installed by default
[Email protected] bin]# Rpm-qa rsync
Rsync-3.0.6-6.el5_11
1, first to configure the Rsync-slave
Add the configuration of rsync files, configuration content for/data/directory for backup, virtual user syncuser, password file/etc/rsyncd.pass
Vim/etc/rsyncd.conf
# section 1:global Settings
Port = 873
UID = root
GID = root
Use chroot = no
Read Only = no
Max connections = 7
PID file =/var/run/rsyncd.pid
Log file =/var/log/rsyncd.log
Hosts allow = *
Transfer logging = yes
Log format =%t%a%m%f%b
Syslog facility = Local3
Timeout = 300
# section 2:directory to be synced
[Data]
Path =/data/
List = False
Ignore errors = yes
Auth users = Syncuser
Secrets file =/etc/rsyncd.pass
Add a virtual user and password for primary and standby authentication
Vim/etc/rsyncd.pass
syncuser:12345
Assign 600 permissions when editing is complete
chmod Rsyncd.pass
Start rsync Service after completion
Rsync--daemon--config=/etc/rsyncd.conf
Check startup, rsync default port 873
Ps-ef |grep rsync |grep-v grep
NETSTAT-LNT |grep 873
Lsof-i tcp:873
2, Configuration Rsync-master
Add Password verification files, note that only passwords are required
Vim/etc/rsyncd.pass
12345
chmod Rsyncd.pass
Test the Rsync service to push the/data/folder contents of the master side to the slave side
Rsync-avz-p/data/[email protected]::d ATA--password-file=/etc/rsyncd.pass
second, on the master side Installation Configuration inotify Service
1, check whether support inotify, the following instructions system support INotify Service
[Email protected] mp3]# ls-l/proc/sys/fs/inotify/
Total 0
-rw-r--r--1 root root 0 Apr 09:17 max_queued_events
-rw-r--r--1 root root 0 Apr 09:17 max_user_instances
-rw-r--r--1 root root 0 Apr 09:17 max_user_watches
2. Download and install Inotify-tool tools
wget http://nchc.dl.sourceforge.net/project/inotify-tools/inotify-tools/3.13/inotify-tools-3.13.tar.gz
Download to local, unzip and install
# tar XZVF inotify-tools-3.14.tar.gz
# CD inotify-tools-3.14
#./configure --prefix=/usr/local/inotify
# make &&make install
3, complete installation, to/usr/local/inotify/bin under the establishment of inotify monitoring script, content detection server/data and client/data directory is consistent, inconsistent rsync synchronization
[Email protected] etc]# vim/usr/local/inotify/bin/inotify_rsync.sh
#!/bin/bash
Srcdir= "/data/"
ip= "192.168.6.128"
dstdir= "Data"
/usr/local/inotify/bin/inotifywait-mrq--timefmt '%d/%m/%y-%h:%m '--format '%T%w%f '-e modify,delete,create,attrib ${ Srcdir} | while read file;
Do
For I in ${ip}
Do
Rsync-avz--progress--password-file=/etc/rsyncd.pass ${srcdir} [email Protected]${i}::${dstdir} Done
Done
~
Give script permission to execute
#chmod +x inotify_rsync.sh
Running in the background
#./inotify_rsync.sh &
4, testing, by modifying the/data content on the Mater side, you can view slave/data directory content
In addition, the Rsync service can be transferred using the SSH channel
SSH-free authentication
Server-side command: ssh-keygen-t RSA
SCP. ssh/id_rsa.pub [Email protected]:~.ssh/id_rsa.pub
Client commands: Cat id_rsa.pub >>. Ssh/authorized_keys
chmod. Ssh/authorized_keys
Rsync-avz-p/Local Directory-e ' ssh-p 22 ' user @ip:/directory push local directory to remote
Rsync-avz-p-E ' ssh-p 22 ' user @ip:/directory/local directory grab remote directory to local
This article is from the "Filter New" blog, please be sure to keep this source http://wahehe.blog.51cto.com/8935316/1669488
Real-time synchronization in Linux under Rsync+inotify