CentOS6.5 rsync+inotify数据实时同步

 


环境介绍:

 Linux版本:CentOS6.5

 rsync版本:3.0.6

 inotify版本:3.14

 服务器IP:192.168.213.131

 客户端IP:192.168.213.134

 压缩包位置:/opt/tools

 安装位置:/usr/local/rsync  /usr/local/inotify

 配置文件:/etc/rsyncd.conf

 密码文件:/etc/rsync.password

 

一、rsync安装配置

  服务器:

1.用yum安装rsync远程同步

  yum -y install rsync

2.从rsync默认安装目录复制一份安装文件到/usr/local/rsync(这步可以省略,只是为了不混乱)

  cp -r /usr/share/doc/rsync-3.0.6 /usr/local/rsync

3.建立配置文件和密码文件

 1)vim /etc/rsyncd/rsync.password

  echo "rsync_test:123456" >> /etc/rsyncd/rsync.password

  chmod 600 /etc/rsyncd/rsync.password

 2)vim /etc/rsyncd/rsyncd.conf

  uid=root

gid=root

max connections=4

log file=/var/log/rsyncd.log

pid file=/var/run/rsyncd.pid

lock file=/var/run/rsyncd.lock

 

[rsync]

path= /rsync/

read only = no

auth users= rsync_test

secrets file= /etc/rsyncd/rsync.password

4.启动rsync并设置开机启动

  rsync --daemon

  或者/usr/local/rsync/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf

echo "/usr/bin/rsync --daemon" >> /etc/rc.local

 

客户端:

1.用yum安装rsync远程同步

  yum -y install rsync

2.创建一个跟服务器相对应的密码文件

  echo "123456" >> /etc/rsyncd/rsync.passwd

  chmod 600 /etc/rsyncd/rsync.password

3.在/tmp/test下新建几个文件,然后同步到到服务器上

  echo "hello world" >> hello

  rsync -avz -P /tmp/test/ rsync_test@192.168.213.131::rsync --password-file=/etc/rsyncd/rsync.passwd

== rsync -avz -P /tmp/test rsync://rsync_test@192.168.213.131:/rsync/ --password-file=/etc/rsyncd/rsync.passwd

3.从服务器上下载同步文件到客户端

  rsync -avz -P rsync_test@192.168.213.128::rsync/ /rsync/ --password-file=/etc/rsyncd/rsync.passwd

== rsync -avz -P rsync://rsync_test@192.168.213.128:/rsync/ /rsync/ --password-file=/etc/rsyncd/rsync.passwd

4.在服务器下的/rsync/下查看是否有hello文件

 

二、inotify的安装和配置

   客户端:

    1.获取inotify的压缩安装包

     wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

2.解压并且安装inotify

  tar -zxf inotify-tools-3.14.tar.gz

  cd inotify-tools-3.14

  ./configure --prefix=/usr/local/inotify

  make && make install

3.创建inotify的启动脚本并授权

  vim /usr/lcoal/inotify/inotify.sh

#!/bin/bash

#

host=192.168.213.128

data_dir=/tmp/test

dst=rsync

username=rsync_test

 

/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $data_dir |while read files

do

  cd $data_dir rsync -avz -R --delete ./ --timeout=100 --password-file=/etc/rsync.password $username@$host::$dst >/dev/null 2>&1

done

 

chmod 755 inotify.sh

4.启动脚本,并在后台运行

  sh inotify.sh &

  关闭:

kill -9 `ps -ef|grep inotify |awk -F ' ' '{print $2}'`

5.在客户端/tmp/test下创建文件,在服务器的/rsync下查看是否有刚创建的文件

 

 

 


这是网上收集到出现的问题和解决方法

 

问题:

    问题一:

@ERROR: chroot failed

rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

 

原因:

服务器端的目录不存在或无权限,创建目录并修正权限可解决问题。

 

问题二:

@ERROR: auth failed on module tee

rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

 

原因:

服务器端该模块(tee)需要验证用户名密码,但客户端没有提供正确的用户名密码,认证失败。

提供正确的用户名密码解决此问题。

 

问题三:

@ERROR: Unknown module ‘tee_nonexists'

rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

 

原因:

服务器不存在指定模块。提供正确的模块名或在服务器端修改成你要的模块以解决问题。

 

 

问题1:

在client上遇到问题:

rsync -auzv --progress --password-file=/etc/rsync.pas root@192.168.133.128::backup /home/

rsync: could not open password file "/etc/rsync.pas": No such file or directory (2)

Password:

@ERROR: auth failed on module backup

rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]

遇到这个问题:client端没有设置/etc/rsync.pas这个文件,而在使用rsync命令的时候,加了这个参数--

password-file=/etc/rsync.pas

 

问题2:

rsync -auzv --progress --password-file=/etc/rsync.pas root@192.168.133.128::backup /home/

@ERROR: auth failed on module backup

rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]

遇到这个问题:client端已经设置/etc/rsync.pas这个文件,里面也设置了密码111111,和服务器一致,但是

服务器段设置有错误,服务器端应该设置/etc/rsync.pas ,里面内容root:111111 ,这里登陆名不可缺少

 

问题3:

rsync -auzv --progress --password-file=/etc/rsync.pas root@192.168.133.128::backup /home/

@ERROR: chdir failed

rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]

遇到这个问题,是因为服务器端的/home/backup 其中backup这个目录并没有设置,所以提示:chdir failed

 

问题4:

rsync: write failed on "/home/backup2010/wensong": No space left on device (28)

rsync error: error in file IO (code 11) at receiver.c(302) [receiver=3.0.7]

rsync: connection unexpectedly closed (2721 bytes received so far) [generator]

rsync error: error in rsync protocol data stream (code 12) at io.c(601) [generator=3.0.7]

磁盘空间不够,所以无法操作。

可以通过df /home/backup2010 来查看可用空间和已用空间

 

问题5:网络收集问题

1、权限问题

类似如下的提示:rsync: opendir "/kexue" (in dtsChannel) failed: Permission denied (13)注意查看同步的目录权限是否为755

2、time out

rsync: failed to connect to 203.100.192.66: Connection timed out (110)

rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]

检查服务器的端口netstat –tunlp,远程telnet测试。

可能因为客户端或者服务端的防火墙开启 导致无法通信,可以设置规则放行 rsync(873端口) 或者直接关闭防火墙。

 

还有一种在同步过程中可能会提示没有权限 (将同步目录加上SvcwRsync全部权限即可,更简单的方法就是将SvcwRsync设为管理员即可)

 

 

3、服务未启动

rsync: failed to connect to 10.10.10.170: Connection refused (111)

rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]

启动服务:rsync --daemon --config=/etc/rsyncd.conf

4、磁盘空间满

rsync: recv_generator: mkdir "/teacherclubBackup/rsync……" failed: No space left on device (28)

*** Skipping any contents from this failed directory ***

5、Ctrl+C或者大量文件

rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [receiver=3.0.5]

rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(544) [generator=3.0.5]

说明:导致此问题多半是服务端服务没有被正常启动,到服务器上去查查服务是否有启动,然后查看下 /var/run/rsync.pid 文件是否存在,最干脆的方法是杀死已经启动了服务,然后再次启动服务或者让脚本加入系统启动服务级别然后shutdown -r now服务器

 

6、xnetid启动

rsync: read error: Connection reset by peer (104)

rsync error: error in rsync protocol data stream (code 12) at io.c(759) [receiver=3.0.5]

查看rsync日志

rsync: unable to open configuration file "/etc/rsyncd.conf": No such file or directory

xnetid查找的配置文件位置默认是/etc下,根据具体情况创建软链接。例如:

ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf

或者更改指定默认的配置文件路径,在/etc/xinetd.d/rsync配置文件中。

 

7、问题:

  出现错误:/usr/local/bin/inotifywait: error while loading shared libraries: libinotifytools.so.0

解决方法:

ln -sv /usr/local/lib/libinotify* /usr/lib/

ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0


 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值