First, rsync is a Unix-like system of data mirroring backup tools, from the name of the software can be seen-remote sync
Features are as follows:
1, can be mirrored to save the entire directory tree and file system.
2, it is easy to maintain the original file permissions, time, soft and hard links and so on.
3, no special permission can be installed.
4, the optimized process, the file transmission efficiency is high.
5, can use RCP, ssh and other means to transfer files, of course, can also be connected through the direct socket.
6, support anonymous transmission.
LSYNCD's function:
(1) Open source software LSYNCD using the inotify principle to monitor a directory, if the directory to increase, delete, change, using rsync protocol to automatically sync to multiple servers
(2) inotify, from Kernel 2.6.13 began formally merged into the kernel, RHEL5 support
(3) Local multi-point directory can be monitored and implemented to the remote directory synchronization
(4) In Rsync client on the LSYNCD monitor and push data to Rsync server rsync daemon,rsync server receive LSYNCD data, and write to local disk
(5) Official introduction: HTTP://CODE.GOOGLE.COM/P/LSYNCD
Note: And for data that changes in real time (for example, a database), this data synchronization, DRBD technology is a better choice.
Second, the software download and installation
1, server side (rsync)
(1) Download and install Rsync
| The code is as follows |
|
|
[Root@example1 ~]# wget http://www.samba.org/ftp/rsync/src/rsync-3.0.7.tar.gz
[Root@example1 ~]# tar zxvf rsync-3.0.7.tar.gz
[root@example1~]#./configure–prefix=/usr/local/rsync–with-rsyncd-conf=/usr/local/rsync/etc/rsyncd.conf– Disable-ipv6 && make && make install |
(2) Create a directory for synchronizing data (rsync server side)
Role: This directory is used to store data LSYNCD push over www.111Cn.net
| The code is as follows |
|
|
[Root@example1 ~]# mkdir/tmp/share/
[Root@example1 ~]# chown-r Root:root/tmp/share; |
2. Client (Lsyncd+rsync)
(1) Download and install rsync without configuring rsyncd.conf
| The code is as follows |
|
|
[Root@example2 ~]# wget http://www.samba.org/ftp/rsync/src/rsync-3.0.7.tar.gz
[Root@example2 ~]# tar zxvf rsync-3.0.7.tar.gz
[Root@example2 ~]#./configure–prefix=/usr/local/rsync–disable-ipv6 && make && make install |
(2) Download and install LSYNCD
| The code is as follows |
|
|
[Root@example2 ~]# wget http://lsyncd.googlecode.com/files/lsyncd-1.26.tar.gz
[Root@example2 ~]# tar zxvf lsyncd-1.26.tar.gz
[Root@example2 ~]#./configure–prefix=/usr/local/lsyncd–enable-xml-config && make && make install |
(3) Create a directory for synchronizing data (rsync client)
Role: This directory is used to store data that will be synchronized to rsync server
| The code is as follows |
|
|
[Root@example2 ~]# Mkdir/tmp/share
[Root@example2 ~]# chown-r Root:root/tmp/share; |
Third, configure Rsync server and rsync clients
1. Configure Rsync server Side
1) Configure Rsync
| code is as follows |
&nbs P; |
[root@example1 ~]# mkdir/usr/local/rsync/etc
& nbsp; [root@example1 ~]# vi/usr/local/rsync/etc/rsyncd.conf
uid = root
& nbsp GID = root
Use chroot = no
max connections = 4
log fi Le =/var/log/rsyncd.log
pid file =/var/run/rsyncd.pid
lock file =/var/run /rsync.lock
[share]
path =/tmp/share #保存将要被同步的数据的目录www. 111cn.net
& nbsp; comment = My Share Documents
hosts allow = 192.168.0.54 #允许访问的主机IP
&nbs p; hosts deny = 0.0.0.0/32
list = yes
Ignore errors = yes
 &N bsp; Readonly = False #是否只读 |
2) Configure LSYNCD
| code is as follows |
&nbs P; |
[root@example1 ~]# mkdir/usr/local/lsyncd/etc
[Root@example1 lsyncd-1.26]# CP lsyncd.conf.xml/usr/local/lsyncd/etc/
[root@example1 lsyncd-1.26]# ln-sf/usr/local/lsyncd/etc/lsyncd.conf.xml/etc/lsyncd.conf.xml
[ Root@example1 ~]# vi/usr/local/lsyncd/etc/lsyncd.conf.xml
<lsyncd version= "1″>
<settings>
<logfile filename= "/var/log/lsyncd.log"/>
<binary filename= "/usr/local/rsync/bin/rsync"/>
<pidfile Filename= "/var/run/lsyncd.pid"/>
<callopts>
<option text= "-avz"/>
<option text= "–delete"/>
&NBSP;&Nbsp; <option text= "–force"/>
<exclude-file/>
< Source/>
<destination/>
</callopts>
</SETTINGS>
<directory>
<source path=/tmp/share /"/>
#注意区别:"/tmp/share/"and"/tmp/share "
<target path=" 192.168.0.53::share "/>
</directory>
</lsyncd> |
2. Configure Rsync Client
| The code is as follows |
|
|
[Root@example2 ~]# Mkdir/usr/local/rsync/etc
[Root@example2 ~]# touch/usr/local/rsync/etc/rsyncd.conf |
Third, start related services and test
1, rsync server side
| The code is as follows |
|
|
[Root@example1 ~]#/usr/local/rsync/bin/rsync–daemon |
2, rsync Client
| The code is as follows |
|
|
[Root@example2 ~]#/usr/local/rsync/bin/rsync–daemon
[Root@example2 ~]#/usr/local/lsyncd/bin/lsyncd–conf/usr/local/lsyncd/etc/lsyncd.conf |
3, testing
Add and delete files in the/tmp/share/directory of rsync client before viewing the/tmp/share directory on the rsync server