2023年7月26日发(作者:)
Rsync同步过程中遇到的常见问题⼀、Rsync服务介绍Rsync属于⼀款实现全量及增量同步数据的软件⼯具,适⽤于unix/linux/windows等多种操作系统平台。Rsync软件能实现本地复制,远程复制,或者远程守护进程⽅式复制。它以其delta-transfer算法闻名,减少通过⽹络数据发送数量,利⽤只发送源⽂件和⽬标⽂件之间的差异信息,从⽽实现数据的增量同步复制。⼆、Rsync⼯作⽅式1. 本地数据备份⽅式2. 远程传输数据⽅式3. 守护进程传输数据⽅式以rsync守护进程⽅式实现为主,通过man rsync帮助,查看⽤法。#拉取数据的命令参数⽤法Pull:rsync [] [USER@]HOST:: [DEST] rsync [] rsync://[USER@]HOST[:PORT]/ [DEST]参数解释: [USER@]HOST:: --- 指定远程连接的认证⽤户 SRC --- 指定相应的模块信息 [DEST] --- 将远程数据保存到本地的路径信息#推送数据的命令参数⽤法Push: rsync [] [USER@]HOST::DEST rsync [] rsync://[USER@]HOST[:PORT]/DEST参数解释: [USER@]HOST:: --- 指定远程连接的认证⽤户 SRC --- 指定本地要进⾏推送的数据信息 [DEST] --- 远程进⾏保存数据的模块信息三、守护进程部署流程3.1 服务端部署1)主机环境检查[root@backup ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)[root@backup ~]# uname -6.x86_64[root@backup ~]# uname -mx86_642)检查软件是否安装[root@backup ~]# rpm -qa 6.x86_643)编辑配置⽂件配置⽂件默认不存在,需要在/etc⽬录下创建。参数⽤法:man 。#created by user at 2018### start###uid = www #管理备份⽬录的⽤户(需要在linux系统下创建虚拟⽤户)gid = www #管理备份⽬录的⽤户组use chroot = no #保护模式,⼀般内⽹使⽤,可以选择禁⽤nomax connections = 200 #可以同时处理的并发连接数timeout = 300 #连接超时,在指定时间内没有数据传输,⾃动释放连接pid file = /var/run/k file = /var/run/g file = /var/log/
ignore errors #备份传输过程中,忽略⼀些I/O产⽣的传输错误read only = false #对备份⽬录开启读写权限,默认为true,只读模式list = false #禁⽌通过客户端查询服务端配置的模块信息hosts allow = 172.16.1.0/24 #允许指定⽹段或主机来访问备份⽬录auth users = rsync_backup #认证⽤户(虚拟认证⽤户),不是真实存在的,⾮linux系统管理的虚拟⽤户secrets file = /etc/ #设置免交互⽅式⽤户认证⽂件[data] #指定备份⽬录的模块名称comment = "sersync dir by myself"path = /data #以绝对路径⽅式,设置备份⽬录路径信息4)创建备份⽬录管理⽤户[root@backup ~]# useradd www -M -s /sbin/nologin5)创建备份⽬录[root@backup ~]# mkdir /data[root@backup ~]# chown -R /data6)创建⽤户认证⽂件[root@backup ~]# echo 'rsync_backup:123456' >>/etc/[root@backup ~]# chmod 600 /etc/追加内容"认证⽤户:密码"到认证⽂件中,在追加前先切换为英⽂输⼊法,⾏尾不添加空格或tab等内容,防⽌认证出错。可以通过vim编辑器尾⾏模式,输⼊:set list检查,或者使⽤命令cat -A /etc/检查。7)启动Rsync服务[root@backup ~]# rsync --daemon[root@backup ~]# netstat -lntp|grep rsynctcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 12805/rsync
tcp 0 0 :::873 :::* LISTEN 12805/rsync[root@backup ~]# echo '/usr/bin/rsync --daemon' >>/etc/如果rsync服务默认端⼝873被其他服务占⽤,使⽤rsync --daemon --port=PORT命令启动测试,更多帮助查看rsync --daemon --help。3.2 客户端部署1)主机环境检查[root@nfs ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)[root@nfs ~]# uname -6.x86_64[root@nfs ~]# uname -mx86_642)检查软件是否安装[root@nfs ~]# rpm -qa 6.x86_643)创建认证⽂件[root@nfs ~]# echo '123456' >>/etc/[root@nfs ~]# chmod 600 /etc/客户端认证⽂件只需要添加密码即可,认证⽤户在客户端通过rsync命令进⾏设置。4)进⾏数据备份测试#客户端备份数据[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::data --password-file=/etc/
sending incremental file listhostssent 180 bytes received 27 bytes 414.00 bytes/sectotal size is 294 speedup is 1.42#服务端检查备份数据[root@backup ~]# ll /data/hosts-rw-r--r-- 1 www www 294 Nov 6 2018 /data/hosts四、Rsync备份过程中常见的错误问题总结1. 客户端执⾏rsync命令发⽣错误问题错误提⽰ERROR: The remote path must start with a module name not a /演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::/data --password-file=/etc/ROR: The remote path must start with a module name not a /rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]问题解决rsync命令语法错误,::/data错误的语法,data为模块,⽽不是⽬录,正确写法::data。2. 配置了免交互⽅式备份数据,客户端依旧需要输⼊密码问题错误提⽰password file must not be other-accessible演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::data --password-file=/etc/ssword file must not be other-accessiblecontinuing without password filePassword:sending incremental file listsent 26 bytes received 8 bytes 9.71 bytes/sectotal size is 294 speedup is 8.65问题解决Rsync客户端的认证⽂件不是600权限。3. Rsync服务端防⽕墙问题错误提⽰No route to host演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::data --password-file=/etc/ync: failed to connect to 172.16.1.41: No route to host (113)rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]问题解决Rsync服务端开启了防⽕墙功能,关闭即可。4. Rsync⽤户认证失败问题错误提⽰ERROR: auth failed on module data演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::data --password-file=/etc/@ERROR: auth failed on module datarsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]问题解决1.客户端rsync命令认证⽤户没写对,或者认证⽂件密码所在⾏的结尾有多余的空格或tab(cat -A /etc/检查)2.客户端认证⽂件/etc/配置错误,不需要rsync_backup认证⽤户,只需要设置认证密码即可。3.服务端认证⽂件中rsync_backup:123456后有空⾏或tab,需要注意。4.服务端认证⽂件/etc/权限不是600。5.服务端配置⽂件中,secrets file参数设置的认证⽂件名称与系统中创建的认证⽂件名称不⼀致。6.服务端配置⽂件中,uid和gid设置的管理⽤户与备份⽬录管理⽤户不⼀致。5. Rsync服务权限阻⽌问题错误提⽰Permission denied演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::data --password-file=/etc/nding incremental file listhostsrsync: mkstemp ".1" (in data) failed: Permission denied (13)sent 180 bytes received 27 bytes 414.00 bytes/sectotal size is 294 speedup is 1.42rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]问题解决1.服务端/etc/⽂件中,uid和gid设置的管理⽤户与备份⽬录的属主和属组不⼀致。2.备份⽬录的⽂件权限不是755。6. Rsync服务备份⽬录异常问题错误提⽰ERROR: chdir failed演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::data --password-file=/etc/@ERROR: chdir failedrsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]问题解决服务端/etc/⽂件中,备份⽬录模块path路径设置存在问题,检查⽬录是否存在,或者path路径是否填写正确。7. Rsync服务备份模块异常问题错误提⽰ERROR: Unknown module 'data'演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::data --password-file=/etc/@ERROR: Unknown module 'data'rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]问题解决1.客户端rsync命令执⾏时,指定的模块名称不正确。2.服务端/etc/⽂件中,指定的备份⽬录的模块名称不正确。⽆效的⽤户问题错误提⽰ERROR: invalid uid mine演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::data --password-file=/etc/@ERROR: invalid uid minersync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]问题解决服务端管理备份⽬录的虚拟⽤户不存在,通过“useradd ⽤户 -M -s /sbin/nologin”进⾏创建即可。9. Rsync服务未开启问题错误提⽰Connection refused演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::data --password-file=/etc/ync: failed to connect to 172.16.1.41: Connection refused (111)rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]问题解决1.检查服务:ps -ef|grep [r]sync2.开启服务:rsync --daemon10. Rsync服务连接超时问题错误提⽰Connection timed out演⽰过程[root@nfs ~]# rsync -avz /etc/hosts rsync_backup@172.16.1.51::data --password-file=/etc/ync: failed to connect to 172.16.1.51: Connection timed out (110)rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]问题解决检查⽬标主机IP地址,ping⽬标主机检查链路是否正常。[root@nfs ~]# ping 172.16.1.41PING 172.16.1.41 (172.16.1.41) 56(84) bytes of data.64 bytes from 172.16.1.41: icmp_seq=1 ttl=64 time=0.438 ms64 bytes from 172.16.1.41: icmp_seq=2 ttl=64 time=0.543 ms11. Rsync服务连接慢的问题⽇志分析[root@backup ~]# tailf /var/log/2019/06/27 12:49:35 [22251] params.c:Parameter() - Ignoring badly formed line in configuration file: ignore errors--- 未对rsync客户端主机在服务端进⾏host解析,导致反向解析域名,使得连接缓慢。2019/06/27 12:49:55 [22251] name lookup failed for 172.16.1.31: Temporary failure in name resolution2019/06/27 12:49:55 [22251] connect from UNKNOWN (172.16.1.31)2019/06/27 12:49:55 [22251] rsync to data/ from rsync_backup@unknown (172.16.1.31)2019/06/27 12:49:55 [22251] receiving file list2019/06/27 12:49:56 [22251] sent 76 bytes received 81 bytes total size 294问题解决[root@backup ~]# echo -e '172.16.1.31tnfs' >>/etc/hosts[root@backup ~]# tailf /var/log/2019/06/27 12:55:06 [22268] params.c:Parameter() - Ignoring badly formed line in configuration file: ignore errors--- 可以查看到服务端对nfs主机进⾏了正确的反向解析过程。2019/06/27 12:55:06 [22268] connect from nfs (172.16.1.31)2019/06/27 12:55:06 [22268] rsync to data/ from rsync_backup@nfs (172.16.1.31)2019/06/27 12:55:06 [22268] receiving file list2019/06/27 12:55:06 [22268] sent 76 bytes received 81 bytes total size 294
发布者:admin,转转请注明出处:http://www.yc00.com/web/1690379543a340693.html
评论列表(0条)