252011

解决Rsync ERROR: auth failed on module

Category: Apache/nginxlixiphp @ 7:42 下午

今天在两台服务器同步备份在用户权限上纠结了很多,主要关于这个问题网上的配置方法不一,源自rsync版本不一致。

rsync同步备份服务器配置

Rsync 版本

[root@mail video]# rsync –version
rsync  version 3.0.6  protocol version 30
Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.
Web site: rsync.samba.org
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, no symtimes

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.

服务器同步任务需求

  • 服务器A与服务器B同步备份,这里只说明服务器A同步到服务器B,服务器B还原到服务器A。
  • 考虑安全因素,使用普通用户进行同步。
  • 使用cronjob,定时同步。

错误提示

错误发生在rsync 3.0.6版本,64位 CentOS5.5 系统。

首页这篇文章主要解决的错误是以下:

@ERROR: auth failed on module ***
rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]

*** 是你/etc/rsyncd.conf 中配置的模块,我这里用

password file must not be other-accessible
continuing without password file
Password:
@ERROR: auth failed on module ***
rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]

Rsync 配置

#vi /etc/rsyncd.conf

uid = nobody
gid = nobody
max connections = 4
read only = true
#hosts allow = 202.207.177.180
hosts allow = *
transfer logging = true
log format = %h %o %f %l %b
log file = /var/log/rsyncd.log
slp refresh = 300
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock

[web]
path = /home/admin/public_html
comment = Mirror to Hk server
read only = true
list = false
auth users = lixiphp

[test]
path = /home/admin/domains/test
read only = false
auth users = lixiphp
secrets file = /etc/rsyncd.secrets

配置普通用户密码

[root@mail video]# vi /etc/rsyncd.secrets

格式为: username:password

rsync_user:rsyncofpass

设置权限为只读:

chmod 600 /etc/rsyncd.secrets

首次启动rsync

rsync –daemon –config=/etc/rsyncd.conf

如果提示

failed to create pid file /var/run/rsyncd.pid: File exists

使用指令

rm -rf /var/run/rsyncd.pid

重启已经在运行的rsync

[root@mail video]# ps -ef | grep rsync
root     27284     1  0 10:26 ?        00:00:00 rsync –daemon –config=/etc/rsyncd.conf
root     30516 29986  0 18:35 pts/3    00:00:00 grep rsync
[root@mail video]# kill -9 27284
[root@mail video]# rsync –daemon –config=/etc/rsyncd.conf

这样服务器A配置成功!


服务器B配置

一般错误都会发生在服务器B,注意这部分的讲解!

通过CentOS yum install rsync,安装rsync服务。

在rsync安装之后,运行以下指令同步备份:

rsync -vzrtopg –progress –delete –password-file=/home/admin/admin_backups/password.rsync rsync://lixiphp@203.171.237.245/test  /home/admin/admin_backups/test

地址rsync://lixiphp@203.171.237.245/test,lixiphp为服务器A用户,203.171.237.245服务器A IP地址或者域名 test为服务器A配置模块

密码存放在/home/admin/admin_backups/password.rsync,这里存放位置,可自由安排。

password.rsync内容格式为: password

rsyncofpass

设置权限为只读:

chmod 600 /home/admin/admin_backups/password.rsync

解决错误

用户密码错误

@ERROR: auth failed on module test
rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]

检查服务器A存储密码文件和服务器B密码文件。

  • 服务器A密码文件 /etc/rsyncd.secrets 格式为: username:password
  • 服务器B密码文件 password.rsync 格式为:password

文件权限错误

password file must not be other-accessible
continuing without password file
Password:
@ERROR: auth failed on module ***
rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]

检查服务器A存储密码文件和服务器B密码文件。

  • 服务器A密码文件 /etc/rsyncd.secrets 权限为600: chmod 600 /etc/rsyncd.secrets
  • 服务器B密码文件 password.rsync 权限为600:chmod 600 password.rsync

定时任务

[root@hk admin_backups]# vi backup.sh

内容如下:

#/bin/sh
rsync -vzrtopg –progress –delete –password-file=/home/admin/admin_backups/password.rsync rsync://lixiphp@203.171.237.245/test  /home/admin/admin_backups/test

添加定时任务:

[root@hk admin_backups]# crontab –e

添加以下内容:

*/1 * * * * /home/admin/admin_backups/backup.sh > /dev/null 2>&1

每个一分钟从服务器A同步到服务器B!

服务器B向下备份到服务器A

rsync -vzrtopg –progress –delete –password-file=/home/admin/admin_backups/password.rsync  /home/admin/admin_backups/test rsync://lixiphp@203.171.237.245/test

请确保服务器A同步用户lixiphp,对模块test所在目录有读、写、执行的权限。

声明:本站遵循署名-非商业性使用-相同方式共享 3.0共享协议. 转载请注明转自LixiPHP

标签: , , , , , , , , ,

相关信息

  • 推荐网址:

  • 收藏+分享: Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

已有10条评论

  1. 好东家 CHINA Google Chrome Windows 发表于2011年10月28日 3:39 上午

    学习学习,增加知识

    [回复]

    lixiphp CHINA Internet Explorer Windows 回复:

    相互学习啊。

    欢迎常来!

    [回复]

  2. 木林森 CHINA Google Chrome Windows 发表于2011年11月15日 4:11 下午

    服务器A密码文件 /etc/rsyncd.secrets 格式为: username:password
    服务器B密码文件 password.rsync 格式为:password

    我都按照这个格式来的,怎么还是出现这个问题
    @ERROR: auth failed on module ***
    rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]

    不过这里的用户是实际的A服务器存在的系统用户还是虚拟的一个用户?我是用的一个不存在的用户:rsync
    A端文件:/etc/rsyncd.d/sercets.pas 内容:rsync:123456
    B端密码文件文件::/etc/rsyncd.d/sercets.pas 内容:123456

    rsync -auvzc –password-file=/root/rsync/rsync.pas rsync@10.0.0.181::webfile /var/www/html

    rsyncd.conf具体配置
    uid = root
    gid = root
    max connections = 100
    pid file = /var/run/rsyncd.pid
    log file = /var/log/rsyncd.log
    lock file = /var/lock/rsyncd.lock
    hosts allow = *
    auth users = rsync
    secrets file = /etc/rsyncd.d/secrets.pas
    ignore errors
    read only = yes
    list = no
    timeout = 60

    [webfile]
    path = /var/www/html

    [回复]

    lixiphp CHINA Mozilla Firefox Windows 回复:

    A服务器存在的用户rsync 是实际存在的用户,确保它访问(至少有读的权限)到你要同步的那个文件夹。

    [回复]

  3. 豆诺博客 CHINA Internet Explorer Windows 发表于2011年11月18日 2:40 上午

    这个技术性太强,不怎么看得懂。

    [回复]

    lixiphp CHINA Internet Explorer Windows 回复:

    不好意思由于最近比较忙,这么久才回复你。

    的确,我是主要写PHP领域的技术类文章,我去了你的博客,页面设计和内容都简洁大方明了,相较而言,我的博客确实枯燥不少啊,呵呵~

    以后得像你多学习~

    [回复]

  4. 夜光 CHINA Google Chrome Windows 发表于2011年12月17日 6:28 下午

    技术性太强 8)

    [回复]

  5. Linux利用rsync实现文件同步 一键安装包 WordPress 发表于2011年12月29日 11:37 下午

    [...] http://blog.lixiphp.com/solve-rsync-auth-failed-on-module/ [...]

  6. moper CHINA Google Chrome Windows 发表于2012年01月22日 10:38 上午

    好像有一个在这个基础上开发的同步软件,开源的,可以试试~不过忘记名字了…… :)

    [回复]

  7. taogogo Google Chrome Ubuntu Linux 发表于2012年01月22日 8:23 下午

    随便拜下年。。。 :wink:

    [回复]

欢迎写下您的评论,其中 * 为必填项目

这里写下你想说的话

 wink neutral mad twisted :) eek sad rolleyes razz redface surprised mrgreen lol idea biggrin evil cry cool arrow confused question exclaim