I. Key Technologies
Csync2 + SQLite is used to implement efficient and real-time Incremental backup of data. Related directories and file information are stored in the SQLite database,
The synchronization speed and efficiency are greatly improved. inotify is used to execute the csync command in real time to update files.
Ii. Applicable Solution
Image server cluster solution: reiserfs4 + csync2 + inotify
Distributed Solution for website service programs: csync2 + inotify + NFS
[Note] (for example, if a cache directory exists in a website program, exclude this directory synchronization and mount the cache directory on NFS)
Distributed cluster software configuration update synchronization solution: csync2 + inotify
[Note] (for example, heartbeat-related configuration files in the cluster, such as Apache and nginx configuration files, and relevant scripts can be executed)
Iii. Actual configuration process
System: centos5.1
Structure: three serversReference # vi/etc/hosts 192.168.4.188 csync1194254.190 csync2192.168.4.191 csync3
1. Create a download file list and reference CD/usr/local/src/
VI List // the following content:
Ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.7.tar.gz
Ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.4.4.tar.gz
Ftp://ftp.gnutls.org/pub/gnutls/libtasn1/libtasn1-2.1.tar.gz
Http://www.sqlite.org/sqlite-2.8.17.tar.gz
Http://internode.dl.sourceforge.net/sourceforge/librsync/librsync-0.9.7.tar.gz
Ftp://ftp.gnu.org/pub/gnu/gnutls/gnutls-2.6.6.tar.bz2
Http://oss.linbit.com/csync2/csync2-1.34.tar.gz
Http://jaist.dl.sourceforge.net/sourceforge/inotify-tools/inotify-tools-3.13.tar.gz
2. Create an installation script and execute reference VI install. Sh // the following content:
Wget-I list
CD/usr/local/src/
Tar zxvf libgpg-error-1.7.tar.gz
CD libgpg-error-1.7
./Configure & make install
CD ..
Tar zxvf libgcrypt-1.4.4.tar.gz
CD libgcrypt-1.4.4
./Configure -- With-GPG-error-Prefix =/usr/local & make install
CD ..
Tar zxvf libtasn1-2.1.tar.gz
CD libtasn1-2.1
./Configure & make install
CD ..
Tar zxvf sqlite-2.8.17.tar.gz
CD sqlite-2.8.17
./Configure & make install
CD ..
Tar zxvf librsync-0.9.7.tar.gz
CD librsync-0.9.7
./Configure & make install
CD ..
Tar jxvf gnutls-2.6.6.tar.bz2
CD gnutls-2.6.6
./Configure -- With-libgcrypt-Prefix =/usr/local/& make install
CD ..
Echo "/usr/local/lib">/etc/lD. So. confldconfig
Tar zxvf csync2-1.34.tar.gz
CD csync2-1.34
./Configure & make install & make Cert
CD ..
Tar zxvf inotify-tools-3.13.tar.gz
CD inotify-tools-3.13
./Configure & make install
CD ..
Echo "csync2 30865/tcp">/etc/services
Echo "service csync2
{
Disable = No
Protocol = TCP
Flags = Reuse
Socket_type = stream
Wait = No
User = root
Group = root
Server =/usr/local/sbin/csync2
Server_args =-I
# Only_from = 192.168.10.50 192.168.10.51
} ">/Etc/xinetd. d/csync2
Chkconfig xinetd on
3. Grant the script executable permission and execute: Reference (Note: You need to execute the script on each node) chmod 755 install. Sh
./Install. Sh 4. Edit the hosts file as follows: Reference VI/etc/hosts
192.168.4.188 csync1194254.190 csync2192.168.4.191 csync3 (all three hosts must be modified)
5. Generate and distribute the key to each node: Reference csync2-k/etc/test. Key
SCP/etc/test. Key root @ node2:/etc/
6. Create a Backup Directory: Reference mkdir/var/csync_backup
Note: It is used to prevent modification and error recovery. If it is enabled, create directories on other nodes.
7. Modify the csync2 configuration file (all nodes are the same): Reference VI/etc/csync2.cfg // the following content:
Group testgroup
{
Host csync1 csync2 csync3; // defines group members.
Key/etc/test. Key; // specify the key
Include/var/www/html; // directory to be synchronized
Exclude/var/www/html/temp; // directory to be excluded.
Exclude/var/www/html/templates _; // you need to exclude the synchronized cache directory.
Exclude *~ . *; // Exclude files starting with synchronization.
Backup-directory/var/csync_backup; // The backup directory is configured according to your needs.
Backup-generations 3;
Auto younger; // synchronize updates based on the latest files.
}
Start Service: Reference/etc/init. d/xinetd start or: Service xinetd start
Note: csync2 related test commands reference csync2-vvv-t to test whether the csync configuration is correct. You can see the related SQL Execution Process.
Csync2-XV run the synchronization command
Csync2-xvvv: Execute the synchronization command and display detailed information 8. make a soft link 32-bit system: ln-S/usr/local/lib/libinotifytools. so.0/usr/lib/libinotifytools. so.064-bit system: ln-S/usr/local/lib/libinotifytools. so.0/usr/lib64/libinotifytools. so.0 9. Configure inotify to trigger the synchronization script (all nodes are the same): Reference VI/usr/local/sbin/csync2_test.sh // the following content:
#! /Bin/bash
Src =/var/www/html
/Usr/local/bin/inotifywait-mrq -- timefmt '% d/% m/% Y % H: % m' -- format' % T % w % F '/
-- Exclude "/. SWP $ "/
-E close_write, modify, delete, create, attrib, move/
$ {SRC }/
| While Read File
Do
Csync2-x>/dev/null 2> & 1
Done
Run the script in the background: Reference chmod A + x/usr/local/sbin/csync2_test.sh
Csync2_test.sh &
10 reproduced from http://jlsfwq.blog.51cto.com/818700/207782
Test file synchronization:
Create, modify, move, or delete files or directories on any node, and check whether the synchronization is performed on other nodes. If the synchronization is not performed, use the test commands of csync2 to test whether the synchronization is normal.