具备可以使本地和远程两台主机之间的数据快速复制同步镜像,远程备份的功能,这个功能相似ssh带的scp命令,但又优于scp命令的功能,scp每次都是全量拷贝,而rsync能够增量拷贝。固然,Rsync还能够在本地主机的不一样分区或目录之间全量及增量的复制数据,这又相似cp命令,但一样也优于cp命令,cp每次都是全量拷贝,而rsync能够增量拷贝。web
rsync的流氓属性:我复制给你你所没有的文件,同时删除你有我没有的文件(保存两台服务器数据的彻底同步)vim
#两台服务器都必须装两个软件包 [root@yangwenbo /]# yum -y install rsync openssh-clients [root@yangwenbo /]# rpm -qa rsync openssh-clients openssh-clients-7.4p1-16.el7.x86_64 rsync-3.1.2-4.el7.x86_64
rsync 命令经常使用参数选项说明:服务器
v,--verbose 详细模式输出,传输时的进度等信息
z,--compress 传输时进行压缩以提升传输效率,--compress-level=NUM可按级别压缩。
a,--archive 归档模式,表示以递归方式传输文件,并保持全部文件属性,等于-rtopgD1(字母1)网络
/backup
推到本地的/yunwei
目录相下/backup
里有如下内容/yunwei
里有如下内容/yunwei
目录本地
共享目录/backup
目录下备份Web服务器/yangwenbo
目录下本地
挂载备份备份Wbo服务器
检查[root@root ~]# vim /etc/rsyncd.conf [root@root ~]# cat /etc/rsyncd.conf uid = rsync gid = rsync use chroot = no max connections = 200 timeout = 300 pid file = /var/run/rsyncd.pid lock file = /var/log/rcyncd.lock [backup] path = /backup/ ignore errors read only = false list = false hosts allow = 192.168.200.0/24 hosts deny = 0.0.0.0/24 auth users = rsync_backup secrets file = /etc/rsync.password
由客户端操做:ssh
问题1:socket
@ERROR: chroot failed
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3] 测试
缘由:服务器端的目录不存在或无权限,建立目录并修正权限可解决问题。 ui
问题2: this
@ERROR: auth failed on module tee
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3] spa
缘由:服务器端该模块(tee)须要验证用户名密码,但客户端没有提供正确的用户名密码,认证失败。
问题3:
@ERROR: Unknown module ‘tee_nonexists'
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]
缘由:服务器不存在指定模块。提供正确的模块名或在服务器端修改为你要的模块以解决问题。
问题4: 在client上遇到问题:
4.1
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
4.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 ,这里登录名不可缺乏
问题5:
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
问题6:
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 来查看可用空间和已用空间
问题7:网络收集问题
7.1 权限问题
相似以下的提示:
rsync: opendir "/kexue" (in dtsChannel) failed: Permission denied (13)
注意查看同步的目录权限是否为755
7.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设为管理员便可)
7.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
7.4磁盘空间满
rsync: recv_generator: mkdir "/teacherclubBackup/rsync……" failed: No space left on device (28)
*** Skipping any contents from this failed directory ***
7.5Ctrl+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服务器
问题8.Rsync error:
错误一:
@ERROR: auth failed on module xxxxx
rsync: connection unexpectedly closed (90 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(150)
说明:这是由于密码设置错了,没法登入成功,检查一下rsync.pwd,看客服是否匹配。还有服务器端没启动rsync 服务也会出现这种状况。
错误二:
password file must not be other-accessible
continuing without password file
Password:
说明:这是由于rsyncd.pwd rsyncd.sec的权限不对,应该设置为600。如:chmod 600 rsyncd.pwd
错误三:
@ERROR: chroot failed
rsync: connection unexpectedly closed (75 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(150)
说明:这是由于你在 rsync.conf 中设置的 path 路径不存在,要新建目录才能开启同步
错误四:
rsync: failed to connect to 218.107.243.2: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(104) [receiver=2.6.9]
说明:防火墙问题致使,这个最好先完全关闭防火墙,排错的基本法就是这样,不管是S仍是C,还有ignore errors选项问题也会致使
错误五:
@ERROR: access denied to www from unknown (192.168.1.123)
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(359)
说明:此问题很明显,是配置选项host allow的问题,初学者喜欢一个容许段作成一个配置,而后模块又是同一个,导致致使
错误六:
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(244) [generator=2.6.9]
rsync error: received SIGUSR1 (code 19) at main.c(1182) [receiver=2.6.9]
说明:致使此问题多半是服务端服务没有被正常启动,到服务器上去查查服务是否有启动,而后查看下 /var/run/rsync.pid 文件是否存在,最干脆的方法是杀死已经启动了服务,而后再次启动服务或者让脚本加入系统启动服务级别而后shutdown -r now服务器
错误七:
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(604) [sender=2.6.9]
说明:原数据目录里没有数据存在