天空小小岛技术论坛

 找回密码
 注册
搜索
查看: 9641|回复: 1
打印 上一主题 下一主题

rsync安装配置详解

[复制链接]
跳转到指定楼层
1#
s.Bo 发表于 2015-4-10 14:05:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
网上下载源码包 rsync.tar.gz 解压
  1. >tar zxvf rsync.tar.gz
  2. >cd rsync
复制代码

配置编译目录
  1. >./configure --prefix=/usr/local/rsync
复制代码
  1. make && make install
复制代码


创建目录
  1. >mkdir /etc/rsyncd
复制代码

创建rsync服务器配置文件
  1. >touch /etc/rsyncd/rsyncd.conf
复制代码

创建rsync用户密码文件
  1. >touch /etc/rsyncd/rsyncd.secrets
复制代码

创建rsync motd文件
  1. >touch /etc/rsyncd/rsyncd.motd
复制代码

将密码文件权限改为600,该文件的所有者必须是root,权限是600
  1. >chmod 600 /etc/rsyncd/rsyncd.secrets
复制代码

创建rsync日志目录
  1. >mkdir /var/log/rsyncd.log
复制代码


编辑配置文件 rsyncd.conf
  1. >vim rsyncd.conf
复制代码
  1. #端口号,默认为873
  2. port=873

  3. #Server Address
  4. address=192.168.1.123

  5. #服务器端执行的用户,默认是nobody
  6. uid=0
  7. #服务器端执行的用户组,默认是nobody
  8. gid=0

  9. #客户端只读(允许上传文件到服务器上)
  10. read only=no

  11. #同步符号链接的内容
  12. use chroot=no

  13. #允许接入服务器的网络
  14. hosts allow=192.168.1.111
  15. hosts deny=*
  16. #最大连接数
  17. max connections=50

  18. #pid文件存放位置
  19. pid file = /var/run/rsyncd.pid
  20. #锁文件存放位置
  21. lock file = /var/run/rsync.lock

  22. #连接到服务器时,用户看到信息
  23. motd file=/etc/rsyncd/rsyncd.motd

  24. #rsync 日志
  25. log file = /var/log/rsync.log
  26. log format = %t %a %m %f %b

  27. #传输文件的日志;
  28. transfer logging = true

  29. timeout=100

  30. #模块定义
  31. [rsync]
  32. path=/tmp/rsync
  33. comment=test
  34. #可以连接到此模块的用户
  35. auth users=root,tkxxd
  36. #用户名密码文件
  37. secrets file = /etc/rsyncd/rsyncd.secrets
  38. #禁止查看文件列表
  39. list=yes
  40. #忽略无关的IO错误
  41. ignore errors
复制代码


配置用户密码文件
  1. >vim rsyncd.secrets
复制代码
  1. #格式为user:password
  2. root:mmts%6yrJZnIu!Tb
  3. tkxxd:5UKMA2g5
复制代码


配置连接到服务器时,用户看到信息
  1. >vim rsyncd.motd
复制代码
  1. +++++++++++++++++++++++++++++++++++++++++++

  2. +   tkxxd.net rsync  2009    +

  3. +++++++++++++++++++++++++++++++++++++++++++
复制代码


启动rsync服务
  1. >/usr/local/rsync/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
复制代码

检查进程是否存在
  1. >ps -aux |grep rsync

  2. >netstat -an |grep 873
复制代码

打开防火墙
  1. iptables -i INPUT -p tcp --dport 873 -j ACCEPT
  2. iptables -L
复制代码


rsync开机启动
  1. >echo "/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf" >> /etc/rc.local
复制代码



客户端直接使用rsync命令
  1. >rsync -vzrtopg --progress --delete tkxxd@192.168.1.123::rsync /data/test
复制代码


参数说明
-vzrtopg 里的v是verbose,z是压缩,r是recursive,topg都是保持文件原有属性如属主、时间的参数。
--progress 是指显示出详细的进度情况
--delete 是指如果服务器端删除了这一文件,那么客户端也相应把文件删除
rsync是指在rsyncd.conf里定义的模块名
/data/test 是指本地要备份目录

rsync常用参数:
#rsync [option] 源路径 目标路径
其中[option]为:
a:使用archive模式,等于-rlptgoD,即保持原有的文件权限
z:表示传输时压缩数据
v:显示到屏幕中
e:使用远程shell程序(可以使用rsh或ssh)
–delete:精确保存副本,源主机删除的文件,目标主机也会同步删除
–include=PATTERN:不排除符合PATTERN的文件或目录
–exclude=PATTERN:排除所有符合PATTERN的文件或目录
–password-file:指定用于rsync服务器的用户验证密码
2#
 楼主| s.Bo 发表于 2015-4-10 14:52:02 | 只看该作者
提示UID或GID非法
现象:@ERROR: invalid gid xxx  或者 @ERROR: invalid uid xxxx
解决办法:可以设置gid=0,uid=0

chdir失败(切换目录)
现象:@ERROR: chdir failed
解决办法:
1、查看日志文件,日志文件在安装目录下。从日志文件中确定是哪个目录出问题
2、查看服务启动用户对该目录是否有权限
3、确认该目录是否包含中文字符

@ERROR: failed to open lock file
现象:rsync error: error starting client-server protocol (code 5) at main.c(1495) [receiver=3.0.2]
解决:配置文件 rsync.conf中添加 lock file = rsyncd.lock 即可解决。

@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)
说明:这是因为密码设置错了,无法登入成功,检查一下rsyncd.secrets,看客服是否匹配。还有服务器端没启动rsync 服务也会出现这种情况。

password file must not be other-accessible
continuing without password file
Password:
说明:这是因为rsyncd.secrets的权限不对,应该设置为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)
说明:这是因为你在 rsyncd.conf 中设置的 path 路径不存在,要新建目录才能开启同步

rsync: failed to connect to 192.168.1.123: 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]
说明:原数据目录里没有数据存在

@ERROR: Unknown module  xxxxx
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]
原因:
服务器不存在指定模块。提供正确的模块名或在服务器端修改成你要的模块以解决问题。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|天空小小岛  |京ICP备2025130156号|

GMT+8, 2025-6-22 01:57 , Processed in 0.087524 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表