rsync+inotify实现数据同步——单向传输

实验环境:<从A主机推送数据到B主机[B主机可以有多个]>

A主机:10.1.43.102

B主机:10.1.43.103


配置流程:

—rsyncserver—- <B主机上配置>

1.vim /etc/rsyncd.conf(用户,目录,模块,虚拟用户及密码文件)

vim /etc/rsyncd.conf
uid = root
gid = root
port = 873 #post rsync使用的端口号  也是默认端口号 www.jbxue.com
hosts allow = 10.1.43.103 #allow hosts ip 应许的ip访问,也可以设置为ip段
max connections = 200  
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
    
[backup]
path =/var/www/html  #客服端已rsync服务端同步的文件路径
comment = from 10.1.43.103  #解释
read only = no
write only = no
list = no
    
auth users =rsync  #配置登陆名称
secrets file = /etc/rsync.password  #配置用户名密码文件

2.创建共享目录:/test/rsync

mkdri -pv /test/rsync

3、创建密码文件,文件路径和文件名参照配置文件里"secrets file"选项的值,然后添加密码内容

vim /etc/rsync.password
rsync:123456

4、密码文件的权限600

chmod 600 /etc/rsync.password

5、运行rsync,并且开机启动

rsync –daemon
echo "rsync –daemon" >> /etc/rc.local

6、如果出错,查看日志  

tail /var/log/rsyncd.log

——rsyncclient——<A主机上配置>

1、密码文件

vim /etc/rsync.password
123456   #注意:此处只需要写服务端虚拟帐号的密码即可

2、密码文件的权限600

chmod 600 /etc/rsync.password

3.创建共享目录:/test/rsync

mkdri -pv /test/rsync

4、安装inotify-tools软件包

yum -y install inotify-tools

5、编写同步脚本

vim /root/bin/rsync.sh
#!/bin/bash
src=/test/rsync   
des=backup       
host="10.1.43.102"  
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y%H:%M' --format '%T%w%f' -e modify,delete,create,attrib \  #此行尚未完结
$src | while read files; do
  for hostip in $host; do
    rsync -avz --delete --progress --password-file=/etc/rsync.password $src rsync@$hostip::$des
  done
  echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done

6、后台自动运行,并且开机自动启动

nohup /bin/bash /root/bin/rsync.sh &
echo "nohup /bin/bash /root/bin/rsync.sh &" >> /etc/rc.loacl

如果再配置过程中出现如下问题

问题一:

@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 backup

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

原因:

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

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

问题三:

@ERROR: Unknown module ‘backup'

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

原因:

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

问题四:

password file must not beother-accessible

continuing without password file

Password:

原因:

这是因为rsyncd.pwdrsyncd.secrets的权限不对,应该设置为600。如:chmod600 rsyncd.pwd

问题五:

rsync: failed to connect to218.107.243.2: No route to host (113)

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

原因:

对方没开机、防火墙阻挡、通过的网络上有防火墙阻挡,都有可能。关闭防火墙,其实就是把tcp udp的873端口打开

问题六:

rsync error: error startingclient-server protocol (code 5) at main.c(1524) [Receiver=3.0.7]

原因:

/etc/rsyncd.conf配置文件内容有错误。请正确核对配置文件

问题七:

rsync: chown "" failed:Invalid argument (22)

原因:

权限无法复制。去掉同步权限的参数即可。(这种情况多见于Linux向Windows的时候)

 

问题八:

@ERROR: daemon security issue –contact admin

rsync error: error starting client-server protocol (code 5) at main.c(1530)[sender=3.0.6]

原因:

同步的目录里面有软连接文件,需要服务器端的/etc/rsyncd.conf打开use chroot = yes。掠过软连接文件

原创文章,作者:megedugao,如若转载,请注明出处:http://www.178linux.com/54883

(0)
megedugaomegedugao
上一篇 2016-10-27 16:10
下一篇 2016-10-27 16:49

相关推荐

  • Linux用户与用户组的详解

    添加用户   创建或添加新用户使用useradd命令来实现,其命令用法为:   useradd [option] username   该命令的option选项较多,常用的主要有:   -c 注释      用户设置对账户的注释说明文字  …

    Linux干货 2016-08-05
  • 第十五周作业

    1、总结sed和awk的详细用法; sed:     模式空间:sed是一种在线编辑器、行编辑器,一次处理一行内容,在处理时,把当前处理的行存储在临时缓冲区当中,并在该缓冲区中完成后续的处理,该缓冲区被称为”模式空间”。     保持空间:在模式空间中处理完一行内容后会继续处理下一行,但是对于处…

    Linux干货 2017-04-18
  • rpm 程序包管理器的基本使用

    目录 安装程序包 卸载 升级 查询 校验 来源合法性和完整性验证 数据库重建 1     安装程序包 rpm -ivh /path/to/package_file -v     显示执行过程的参数。 -h   &nbsp…

    Linux干货 2016-06-22
  • Second

    1、 linux 上的文件管理类命令都有哪些, 其常用的使用方法及相关示例演示 cat     concatenate file and print ont the standard output cat [OPTION]…[FILE]…      &nbsp…

    Linux干货 2016-12-13
  • nginx

    http http协议:web服务器(类似于httpd)、http reverse proxy(类似于httpd)、imap/pop3 reverse proxy NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/P…

    Linux干货 2017-06-25