Linux下rsync daemon模式下的错误汇总
一、前言:最近学习服务环境搭建,遇到了许多大大小小的问题,不过还好,经过我的一通努力终于都解决了,所以分享出来给自己留个纪念,同时也希望能帮助学习中的朋友。
二、环境:两台服务器环境相同
1 [root@czh backup]# uname -r
2 2.6.32-573.el6.x86_64
3 [root@czh backup]# uname -m
4 x86_64
5 [root@czh backup]# cat /etc/redhat-release
6 CentOS release 6.7 (Final)
三、服务器端配置文件
1 uid = rsync
2 gid = rsync
3 use chroot = no
4 max connections = 1000
5 timeout = 300
6 pid file = /var/run/rsyncd.pid
7 log file = /var/run/rsyncd.log
8 lock file = /var/run/rsyncd.lock
9 ignore errors = yes
10 read only = false
11 list = false
12 auth users = rsync_backup
13 secrets file = /etc/rsync.password
14 hosts allow = 172.16.0.0/24
15 hosts deny = 0.0.0.0/0
16 [backup]
17 path = /backup
四、rsync 错误总结
1、Q:rsync: failed to connect to 172.16.0.41: Connection refused (111)
[root@czh ~]# rsync -avz /etc/passwd rsync_backup@172.16.0.41::backup --password-file=/etc/rsync.password
rsync: failed to connect to 172.16.0.41: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]
A: 1)先检查服务端服务是否启动。(服务端未启动daemon进程)
2、Q:rsync: could not open password file "/etc/rsync.password": No such file or directory (2)
[root@czh ~]# rsync -avz /etc/passwd rsync_backup@172.16.0.41::backup --password-file=/etc/rsync.password
rsync: could not open password file "/etc/rsync.password": No such file or directory (2)
Password:
A:1)先检查服务端和客户端是否配置了密码文件,如果没有,则要在服务端和客户端配置密码文件,注意密码要统一。
2)检查服务器端配置文件中是否配置了“secrets file= ”相应值。
3、Q:password file must not be other-accessible(可进入的,可访问的)continuing without password file
[root@czh ~]# rsync -avz /etc/passwd rsync_backup@172.16.0.41::backup --password-file=/etc/rsync.password
password file must not be other-accessible
continuing without password file
Password:
A:1)先查看服务器端和客户端的密码文件权限,统一改为600
4、Q:@ERROR: invalid uid rsync
[root@czh ~]# rsync -avz /etc/passwd rsync_backup@172.16.0.41::backup --password-file=/etc/rsync.password
@ERROR: invalid uid rsync
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
A:1)先查看系统中是否存在配置文件中uid字段的值(用户,这里我用的是rsync用户),在服务器端执行命令 `id rsync`,如果没有,添加rsync用户,为了保证安全性,我们通常不给他登录权限,不创建家目录,命令为:useradd -M -s /sbin/nologin rsync(当然你也可以指定UID).
5、Q:@ERROR: chdir failed
[root@czh ~]# rsync -avz /etc/passwd rsync_backup@172.16.0.41::backup --password-file=/etc/rsync.password
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
A:1)先检查服务器端是否有备份目录(和配置文件中模块下的path字段对应的路径),如果没有,创建出来,并授权给rsync用户管理。
6、Q:ERROR: module is read only
[root@czh ~]# rsync -avz /etc/passwd rsync_backup@172.16.0.41::backup --password-file=/etc/rsync.password
sending incremental file list
ERROR: module is read only
rsync error: syntax or usage error (code 1) at main.c(866) [receiver=3.0.6]
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [sender=3.0.6]
A:1)先检查配置文件中是否有”read only = false“ ,没有的话(系统默认为只读)我们就不能向这个模块中写入,因为它是只读的,加入” read only = false”,只读为假,即可写
2)如果有,我建议你在仔细看看,是不是写错了。
3)重新启动服务,可能是修改了配置没有加载。
7、Q:rsync: mkstemp ".passwd.u8iYqh" (in backup) failed: Permission denied (13)
[root@czh ~]# rsync -avz /etc/passwd rsync_backup@172.16.0.41::backup --password-file=/etc/rsync.password
sending incremental file list
passwd
rsync: mkstemp ".passwd.z0BuYu" (in backup) failed: Permission denied (13)
A:1)权限问题,检查服务器端的备份目录权限,授权给rsync管理
2)如果是多级子目录,根据Linux权限体系,可以在父目录在用-R 参数直接递归授权,也可以单个子目录授权。
8、Q:rsync: failed to connect to 172.16.0.41: No route to host (113)
[root@czh ~]# rsync -avz /etc/passwd rsync_backup@172.16.0.41::backup --password-file=/etc/rsync.password
rsync: failed to connect to 172.16.0.41: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]
A:1)90%因为防火墙问题,实验条件下可以关闭防火墙,生产环境中加入通行。
方法:查看系统日志,上面会有系统的显示,比如,解决完上面的问题后,已经能成功推送上去了,但是仍然有一些小问题,终端显示是不会报错了,只有在日志中才能看到,如下:Name or service not know ,这是因为hosts没有解析。
[1499] rsyncd version 3.0.6 starting, listening on port 873
[1561] name lookup failed for 172.16.0.31: Name or service not known
[1561] connect from UNKNOWN (172.16.0.31)
[1561] rsync to backup/ from rsync_backup@unknown (172.16.0.31)
在/etc/hosts中加入解析:
[root@czh backup]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.0.31 nfs
172.16.0.41 backup