Description:
192.168.1.2 (sersync+rsync)—————FTP
192.168.1.3 (rsync)————————–backup
Objective:
Real-time automatic sync:192.168.1.2 ——->192.168.1.3 to directory: /data/ftpdata ;
I. FTP Server(sersync+rsync)
1. Prepare the software packages
[root@ftp ~]# wget http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz
[root@ftp ~]# wget http://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz
2. Install sersync
[root@ftp ~]# mkdir /data/ftpdata
[root@ftp ~]# tar -zxvf sersync2.5_64bit_binary_stable_final.tar.gz -C /usr/bin/
[root@ftp ~]# cd /usr/bin/GNU-Linux-x86/
[root@ftp GNU-Linux-x86]# cp confxml.xml confxml.xml.bak
[root@ftp GNU-Linux-x86]# ls
confxml.xml #Main configuration file
confxml.xml.bak
sersync2 #Main program binary file
Edit the confxml.xml configuration file:
[root@ftp GNU-Linux-x86]# vim confxml.xml
<sersync>
<localpath watch="/data/ftpdata"> #Monitored directory
<remote ip="192.168.1.3" name="ftpdata"/> #backup server IP, ftpdata is the client rsync module name
<!–<remoteip="192.168.8.39" name="tongbu"/>–>
<!–<remoteip="192.168.8.40" name="tongbu"/>–>
</localpath>
:wq
3. Install Rsync
[root@ftp ~]# tar -zxvf rsync-3.0.9.tar.gz
[root@ftp ~]# cd rsync-3.0.9
[root@ftp rsync-3.0.9]# ./configure –prefix=/usr/local/rsync
[root@ftp rsync-3.0.9]# make;make install
Open the rsync port in the firewall: 873
[root@ftp ~]# vim /etc/sysconfig/iptables/
Add:
-A INPUT -m state –state NEW -m tcp -p tcp–dport 873 -jACCEPT
Restart:
[root@ftp ~]# /etc/init.d/iptables restart
II. Backup Server(rsync)
1. Preparation
Create the backup directory:
[root@backup ~]# mkdir /data/ftpdata
2. Prepare the software package
[root@backup ~]# wgethttp://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz
3. Install rsync (Only install rsync on the backup server)
[root@backup ~]# tar -zxvf rsync-3.0.9.tar.gz
[root@backup ~]# cd rsync-3.0.9
[root@backup rsync-3.0.9]# ./configure –prefix=/usr/local/rsync
[root@backup rsync-3.0.9]# make;make install
4. Set up the rsyncConfiguration File
[root@backup ~]# vim /etc/rsyncd.conf
uid=root
gid=root
maxconnections=36000
usechroot=no
logfile=/var/log/rsyncd.log
pidfile=/var/run/rsyncd.pid
lockfile=/var/run/rsyncd.lock
[ftpdata]
path=/data/ftpdata
comment =ftp files
ignoreerrors = yes
read only= no
hostsallow = 192.168..1.0/24
hostsdeny = *
:wq
Start the rsync Service
[root@backup ~]# rsync –daemon
Add rsync startup to boot sequence
[root@backup ~]# echo "rsync–daemon" >> /etc/rc.local
[root@backup ~]# ps -ef |grep rsync
root525010 19:24 ?00:00:00 rsync –daemon
Open the firewall port for rsync: 873
[root@backup ~]# vim /etc/sysconfig/iptables
Add:
-A INPUT -m state –state NEW -m tcp -p tcp–dport 873 -jACCEPT
Restart:
[root@backup ~]# /etc/init.d/iptablesrestart
3. Start the sersync Service
On the FTP server (sersync+rsync), start the sersync daemon process to run in the background and enable real-time synchronization.
[root@ftp GNU-Linux-x86]# ./sersync2 -d -r
set thesystem param
execute: echo50000000 > /proc/sys/fs/inotify/max_user_watches
execute: echo 327679> /proc/sys/fs/inotify/max_queued_events
parse thecommand param
option:-drun as a daemon
option:-rrsync all the local files to theremote servers before the sersync work
daemonthread num: 10
parse xmlconfig file
host ip :localhosthost port: 8008
daemonstart, sersync run behind the console
config xmlparse success
pleaseset /etc/rsyncd.conf max connections=0 Manually
sersyncworking thread 12= 1(primary thread) +1(fail retry thread) + 10(daemon sub threads)
Maxthreads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
pleaseaccording your cpu , use -n param to adjust the cpu rate
——————————————
rsync thedirectory recursivly to the remote servers once
workingplease wait…
executecommand: cd /data/ftpdata && rsync -artuz -R –delete ./ 192.168.1.3::ftpdata>/dev/null 2>&1
run thesersync:
watchpath is: /data/ftpdata
*Indicates that sersynchas been started. You can create a file in the local monitored path and check whether the remote side syncs successfully!
[root@ftp GNU-Linux-x86]# ps -ef |grep rsync
root137710 18:48 ?00:00:00 ./sersync2 -d –r
Finally, you need to add the sersync command to /etc/rc.local for auto-start on boot.
[root@ftp GNU-Linux-x86]# echo "cd/usr/bin/GNU-Linux-x86&&./sersync2 -d -r" >> /etc/rc.local
IV. Testing and Verification
1. On the ftp server, create a folder under /data/ftpdata:
[root@ftp ftpdata]# mkdir zl
2. On the backup server, check if the /data/ftpdata directory matches;
[root@backup ~]# ll /data/ftpdata/
V. Backup and Recovery
1. Manual Backup
192.168.1.2———->192.168.1.3
[root@ftp~]# /usr/bin/rsync -vzrtopg –delete /data/ftpdata/ [email protected]::ftpdata
2. Manual Recovery
192.168.1.3———->192.168.1.2
[root@ftp~]# /usr/bin/rsync -vzrtopg –delete [email protected]::ftpdata/data/ftpdata/
Original article: http://yanghuawu.blog.51cto.com/2638960/1221875
