rsync安装
wget http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz
tar -xvzf rsync-3.0.9.tar.gz; cd rsync-3.0.9;
./configure; make;
make install
rsync服务器端配置
vi /etc/rsyncd.conf(需要手动生成)
uid = root
gid = root
use chroot = no
max connections = 4
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[client1]
path = /data/client1data
comment = client1 file
ignore errors
read only = no
write only = no
list = false
hosts allow = 192.168.10.7
hosts deny = *
uid = root
gid = root
auth users = davy
secrets file = /usr/local/rsync/etc/client1.pass
vi /usr/local/rsync/etc/client1.pass
davy:123456
chown root:root /usr/local/rsync/etc/client1.pass
chmod 600 /usr/local/rsync/etc/client1.pass
启动rsync服务
/usr/local/bin/rsync --daemon --config=/etc/rsyncd.conf
检查进程是否存在,
ps -aux |grep rsync
root 4406 0.0 0.0 4228 588 ? Ss May14 0:00 /usr/local/bin/rsync --daemon
netstat -an |grep 873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN
打开防火墙
vi /etc/sysconfig/iptables
-A INPUT -p tcp -s X.X.X.X --dport 873 -j ACCEPT
service iptables restart
or
iptables -i INPUT -p tcp --dport 873 -j ACCEPT
iptables -L
结果如下
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:rsync
结束进程:kill -9 pid的值
kill -15 进程名
rsync开机启动
echo "/usr/bin/rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.local
注意事项
1) 提示密码文件不能读,需要手工输入密码时,可能就是密码文件权限不是600,或者格式不对,或者是路径不对。
2) 提示要创建新目录或文件传输失败时,可能是欲同步的目录没有权限,最好把欲同步的目录权限修改为744。
3) 从客户端同步文件到服务端时,最好单个文件目录传输,否则易出错。
rsync客户端配置
客户端不用配置,直接使用rsync命令就可以,
rsync -vzrtopg --progress --delete root@118.244.216.177::logs /data/lnmp
如果想rsync无密码登陆,客户端只要配置密码文件即可。
vim /etc/rsyncd.secretes ,这个文件只包含服务器端auth user的密码,不需要配置用户名
123456
chmod 600 rsyncd.secretes (密码文件权限为600,此步必须设置)
rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.secretes root@118.244.216.177::logs /data/lnmp
若想反过来,把客户端的文件同步到服务端,则为如下:
rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.secretes /data/lnmp root@118.244.216.177::logs
rsync定时任务 早上四点执行rsync备份
crontab -e
00 04 * * * rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.secretes root@118.244.216.177::logs /data/lnmp
Rsync 同步参数说明
-vzrtopg里的v是verbose,z是压缩,r是recursive,topg都是保持文件原有属性如属主、时间的参数。
--progress是指显示出详细的进度情况
--delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除
root@xxx.xxx.xxx.xxx中的root是指定密码文件中的用户名,xxx为ip地址
logs是指在rsyncd.conf里定义的模块名
/data/lnmp 是指本地要备份目录
rsync常用参数:
#rsync [option] 源路径 目标路径
其中[option]为:
a:使用archive模式,等于-rlptgoD,即保持原有的文件权限
z:表示传输时压缩数据
v:显示到屏幕中
e:使用远程shell程序(可以使用rsh或ssh)
–delete:精确保存副本,源主机删除的文件,目标主机也会同步删除
–include=PATTERN:不排除符合PATTERN的文件或目录
–exclude=PATTERN:排除所有符合PATTERN的文件或目录
–password-file:指定用于rsync服务器的用户验证密码
----------------------------------------------------------------------------------------------------------------------------
rsync常见错误排错
1.
rsync: failed to connect to 118.244.216.177: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.6]
原因:防火墙屏蔽了端口
解决:打开873段考
iptables -i INPUT -p tcp --dport 873 -j ACCEPT
iptables -L
如果以上指令不行,可以直接停掉防火墙
/etc/init.d/iptables stop
2.
@ERROR: auth failed on module backup
rsync error: error starting client-server protocol (code 5) at main.c(1506) [Receiver=3.0.7]
那估计是密码文件没有设置权限哦: chmod 600 /home/admin/security/rsync.pass
应该差不多就可以了
3.@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.scrt 中的密码, 二端是否一致?
4.password file must not be other-accessible
continuing without password file
Password:
这表示 rsyncd.scrt 的档案权限属性不对, 应设为 600。
5.@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 路径所设的那个目录并不存在所致.请先用 mkdir开设好要备份目录
6.@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)
最后原因终于找到了。因为有两个网段都需要同步该文件夹内容,但没有在hosts allow 后面添加另一个IP段
hosts allow = 192.168.1.0/24
改为
hosts allow = 192.168.1.0/24 192.168.2.0/24
重新启动rsync服务,问题解决
7.@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.scrt
8.rsync: recv_generator: mkdir "/teacherclubBackup/rsync……" failed: No space left on device (28)
*** Skipping any contents from this failed directory ***
磁盘空间满了
9.rsync: opendir "/kexue" (in dtsChannel) failed: Permission denied (13)
同步目录的权限设置不对,改为755
10.rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [receiver=3.0.5]
未启动xinetd守护进程
[root@CC02 /]# service xinetd start
11.rsync: unable to open configuration file "/etc/rsyncd.conf": No such file or directory
xnetid查找的配置文件位置默认是/etc下,在/etc下找不到rsyncd.conf文件
12.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测试
13.我需要在防火墙上开放哪些端口以适应rsync?
视情况而定。rsync可以直接通过873端口的tcp连接传文件,也可以通过22端口的ssh来进行文件传递,但你也可以通过下列命令改变它的端口:
rsync --port 8730 otherhost::
或者
rsync -e 'ssh -p 2002' otherhost:
14.我如何通过rsync只复制目录结构,忽略掉文件呢?
rsync -av --include '*/' --exclude '*' source-dir dest-dir
15.为什么我总会出现"Read-only file system"的错误呢?
看看是否忘了设"read only = no"了
16.@ERROR: chroot failed
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]
原因:
服务器端的目录不存在或无权限。创建目录并修正权限可解决问题。
17.@ERROR: auth failed on module tee
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]
原因:
服务器端该模块(tee)需要验证用户名密码,但客户端没有提供正确的用户名密码,认证失败。提供正确的用户名密码解决此问题。
18.@ERROR: Unknown module ‘tee_nonexists’
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]
原因:
服务器不存在指定模块。提供正确的模块名或在服务器端修改成你要的模块以解决问题。
19.权限无法复制。去掉同步权限的参数即可。(这种情况多见于Linux向Windows的时候)
相关推荐
linux发行版中大多都自带rsync,不过版本比较低,一般都是2.6.X 在2.X的版本中,rsync备份时都是先列表再备份(添加或者删除),在处理大量文件时,会耗费比较多的内存。 备份的时候,rsync扫描到的每个文件(目录也...
Rsync命令详解 在对rsync服务器配置结束以后,下一步就需要在客户端发出rsync命令来实现将服务器端的文件备份到客户端来。rsync是一个功能非常强大的工具,其命令也有很多功能特色选项。 一、rsync的六种工作模式: ...
3、进入到“auto_rsync_bat”文件夹下,修改批处理文件“rsync-demo.bat” 4、修改rsync-demo.bat 注意: 4.1、源目录必须使用“demo“中的样式。 4.2、其他几个变量请根据你实际操作的目录和远程主机信息来设置...
rsync+inotify实现实时同步 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐渐暴露出了很多不足,首先,rsync同 步数据时,需要扫描所有文件后进行比对,进行差...
rsync 服务器架设方法 v0.1b (正在修订中) 作者: 北南南北 来自:Linuxsir.Org 摘要: rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用。...
RSYNC软件介绍: rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync。它的特性如下: 可以镜像保存整个目录树和文件系统。 可以很容易做到保持原来文件的权限、时间、软硬链接...
rsync同步指定目录 rsync使用–include参数与–exclude参数来实现同步指定目录,并且–exclude目录放在后面。 例如: linux上文件目录 代码如下: ls /usr/local/apache/htdocs/site aa bb cc dd ee .. zz 只想同步...
ubuntu rsync中文乱码 window ubuntu rsync同步中文乱码.docx
aix下rsync安装包,可用于AIX平台下与linux平台下的数据同步
Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options ...
AIX文件同步复制工具RSYNC,rsync-3.1.2 for aix6.1。。。
rsync常见错误及解决方法rsync常见错误及解决方法rsync常见错误及解决方法
linux 下rsync文件夹同步配置,可以定时。
适用于Centos7.9的rsync 工具安装包 rsync-3.1.2-10.el7.x86_64.rpm
rsync-3.1.2-4.el7.x86_64.rpm linux系统下rsync安装包
于是放弃,打算用rsync进行同步,在摸索的过程中走了很多湾路,所以写出来让大家参考,网上的大部份的windows 和 rsync的教程都是存在问题的同步不了! 首先是要进群晖的SSH里进行修改相关配置文件,详细的见附件。 ...
rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync。它的特性如下: 1、可以镜像保存整个目录树和文件系统。 2、可以很容易做到保持原来文件的权限、时间、软硬链接等等。 3、...
演示如何在 cygwin 下安装 rsync-3.0.8,以及此工具的使用方法,以及如何使用。以及相关工具
linux系统下rsync同步数据命令详细解答。
ranger-2.1.0-usersync.tar.gz