Data is the most valuable property! The company's servers are required to have a complete backup strategy for the data, using scripts, planning tasks, open source software, and so on, regardless of that way, to real-time synchronization of data, is the most ideal effect! The following details the use of rsync with inotify to achieve real-time data triggering synchronization.
Rsync: Can be mirrored to save the entire tree and file system. It is easy to maintain the original file permissions, time, soft and hard links and so on. At the first synchronization, rsync copies the entire contents, but only the modified files are transferred the next time.
Scenario: Initially using rsync data backup is the use of planning tasks, the timing of the implementation of the command to achieve rsync synchronization, but recently developed this side of the change more frequently, it seems to need real-time synchronous backup to improve the backup mechanism! So need to use inotify trigger to improve! Sync it up once you have a new change in the position you specified!
Environment:
CentOS 6.4 64-bit
rsync-3.0.9
inotify-tools-3.14
Description
10.10.1.6 (rsync+inotify)----------Web site program (/data0/htdocs/)
10.10.1.9 (rsync)------------------Web site program Backup (/data0/htdocs/)
Objective:
Any changes in the/data0/htdocs/directory that implement 10.10.1.6 will be synchronized to 10.10.1.9/data0/htdocs/in real time
(another, both of these are running Keepalived+nginx, to achieve the failure of automatic failover disaster, detailed configuration will be in the back to fill)
First, Web server 10.10.1.6 (rsync+inotify)
1. Prepare Package
# Mkdir/data/ftpdata
# wget http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz
# wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
2. Install Rsync
TAR-ZXVF rsync-3.0.9.tar.gz
cdrsync-3.0.9
./configure--prefix=/usr/local/rsync
Make;makeinstall
Establish Password Authentication file
[Root@ftp ~]# echo "111111" >/etc/rsyncd/rsyncd.secrets Establish password Authentication file
* 111111 can set their own password, rsyncd.secrets name can also set their own;
Permissions: To set the/etc/rsyncd/rsyncd.secrets to root, with a permission of 600.
# chmod 600/etc/rsyncd/rsyncd.secrets
3. Installation INotify
TAR-ZXVF inotify-tools-3.14.tar.gz
cdinotify-tools-3.14
./configure--prefix=/usr/local/inotify
Make;makeinstall