The configuration of real-time automatic synchronization for LSYNCD and rsync

Source: Internet
Author: User
Tags inotify mkdir file permissions rsync

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 Copy Code

[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 Copy Code

[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 Copy Code

[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 Copy Code

[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 Copy Code

[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

The code is as follows Copy Code
[Root@example1 ~]# Mkdir/usr/local/rsync/etc
[Root@example1 ~]# vi/usr/local/rsync/etc/rsyncd.conf
UID = root
GID = root
Use chroot = no
Max connections = 4
Log file =/var/log/rsyncd.log
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsync.lock
[Share]
Path =/tmp/share #保存将要被同步的数据的目录www. 111cn.net
Comment = My Share Documents
Hosts allow = 192.168.0.54 #允许访问的主机IP
Hosts Deny = 0.0.0.0/32
List = yes
Ignore errors = yes
Read Only = False #是否只读

2) Configure LSYNCD

The code is as follows Copy Code
[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"/>
<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 Copy Code

[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 Copy Code

[Root@example1 ~]#/usr/local/rsync/bin/rsync–daemon

2, rsync Client

The code is as follows Copy Code

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.