lsyncd+rsync实时同步rsync同步

lsyncd可以达到的要求:

1. 采用开源软lsyncd采用inotify原理监听某一目录,如果目录内发生增、删、改、利用rsync协议自动同步到多服务器。
2. inotify,从kernel 2.6.13开始正式并入内核,RHEL5支持。
3. 可以本地多点目录的监控并实现到远程目录的同步。
4. 144,145配置rsync服务,可以接收136 rsync推送过来的数据。
5. 官方介绍http://code.google.com/p/lsyncd

配置环境:
本地服务器 :192.168.162.136
rsync服务器:192.168.162.144::soft
           :192.168.162.145::www
 
lsyncd的安装
1. 136安装lsyncd
# wget http://lsyncd.googlecode.com/files/lsyncd-1.26.tar.gz
# tar zxvf lsyncd-1.26.tar.gz
# cd lsyncd-1.26
# ./configure
# make && make install

2. 本地136需要安装rsync客户端
centos 默认状态下rsync已经安装上了。没有安装可以装rpm包,也可以安装源码包进行,只需要客户端工具。
#  wget http://www.samba.org/ftp/rsync/src/rsync-3.0.6.tar.gz
# tar zvxf rsync-3.0.6.tar.gz
# cd rsync-3.0.6
# ./configure --prefix=/usr/local/rsync
# make && make install
# cp /usr/local/rsync/bin/rsync /usr/bin/

3. 本地136 lsyncd启动默认日志文件,可以查看lsyncd启动与工作状态
/var/log/lsyncd

4. 本地手动同步目录并监视磁盘目录情况,运行后作为进程一直在后台运行。
# /usr/local/bin/lsyncd /data/soft/ 192.168.162.144::soft
# /usr/local/bin/lsyncd /data/www/  192.168.162.145::www

5. 或通过配置文件的方式来启动
# vi /etc/lsyncd.conf
/data/soft/ 192.168.162.144::soft
/data/www/  192.168.162.145::www

============
启动脚本如下
============
vi /root/lsyncd.sh
#!/bin/bash
#lsyncd startup script  

lsyncd="/usr/local/bin/lsyncd"

function_start_lsyncd()
{
    printf "Starting Lsyncd...\n"
    while read i
    do
      source=`echo $i | awk '{print $1}'`
      target=`echo $i | awk '{print $2}'`
      $lsyncd $source $target
    done < /etc/lsyncd.conf
}

function_stop_lsyncd()
{
    printf "Stoping Lsyncd...\n"
    killall $lsyncd
}

function_restart_lsyncd()
{
    printf "Restarting Lsyncd...\n"
    function_stop_lsyncd
    function_start_lsyncd
}

if [ "$1" = "start" ]; then
    function_start_lsyncd
elif [ "$1" = "stop" ]; then
    function_stop_lsyncd
elif [ "$1" = "restart" ]; then
    function_restart_lsyncd
else
    printf "Usage: lsyncd.sh {start|stop|restart}\n"
fi

chmod u+x /root/lsyncd.sh

6. 日志文件如下:
出现问题要注意查看lsyncd日志文件的状态,远端rsyncd服务没有启动,lsyncd启动也不会成功。
# cat /var/log/lsyncd
Wed Jan 27 02:21:15 2010: command line options: syncing /data/soft/ -> 192.168.162.144::soft

Wed Jan 27 02:21:15 2010: Starting up
Wed Jan 27 02:21:15 2010: watching /data/soft/
Wed Jan 27 02:21:15 2010: found new directory: b in /data/soft/ -- added on tosync stack.
Wed Jan 27 02:21:15 2010: found new directory: c in /data/soft/ -- added on tosync stack.
Wed Jan 27 02:21:15 2010: found new directory: a in /data/soft/ -- added on tosync stack.
Wed Jan 27 02:21:15 2010: --- Entering normal operation with [4] monitored directories ---

7. 144,145 rsync配置文件示例
==================
144 rsyncd配置文件
==================
# vi /etc/rsyncd.conf
uid = root 
gid = root 
use chroot = no 
max connections = 4
pid file = /var/run/rsyncd.pid 
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[soft] 
path = /var/soft/  
comment = soft   
ignore errors
read only = no
write only = no 
list = no  
hosts allow = 192.168.162.136

运行rsyncd服务
# /usr/bin/rsync --daemon

==================
145 rsyncd配置文件
==================
# vi /etc/rsyncd.conf
uid = root 
gid = root 
use chroot = no 
max connections = 4
pid file = /var/run/rsyncd.pid 
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[www] 
path = /var/www/  
comment = soft   
ignore errors
read only = no 
write only = no
list = no  
hosts allow = 192.168.162.136

运行rsyncd服务
# /usr/bin/rsync --daemon

维护注意事项:1.可以用ps -aux查看启动情况 2.客户端要比rsyncd服务端后启动,否则自动启动不了,这时需要手动启动。

如果不好用,killall lsyncd;/root/lsyncd.sh start

保证两个服务都启动起来:rsync;lsync

netstat -anp | grep rsync

重启服务:

1、杀死进程   2、删除相关文件。

报错消息:

Reported by oer...@gmail.com, Oct 15, 2010

What steps will reproduce the problem?
1. large homedir ( million files )
2. lsyncd --exclude-from=/home/oernii/.rsync_exclude --no-daemon --verbose /home/oernii/ remote::/BACKUP/

What is the expected output? What do you see instead?
sync should run without errors

What version of the product are you using? On what operating system?
1.39

Please provide any additional information below.
After running I am getting a LOT of this:

watching /home/oernii/.kde
ERROR: Cannot add watch /home/oernii/.kde (28:No space left on device)


Comment 1 by d...@dans.im, Oct 15, 2010

"No space left on device" probably means you need to increase /proc/sys/fs/inotify/max_user_watches. Eg.: `echo 65536 >/proc/sys/fs/inotify/max_user_watches'.

解决方法:
在任何目录下键入:echo 65536 >/proc/sys/fs/inotify/max_user_watches
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向良玉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值