Debian 64位环境下面的Rsync配置详解

Rsync 配置 详细
测试环境:
 A:debian 6.0 64位操作系统 (服务器端) IP:192.168.1.100
 B:debian 6.0 64位操作系统 (客户机端) IP:192.168.1.97
 
一、服务器端配置
 1、安装Rsync
  aptitude install rsync
 2、mkdir /etc/rsyncd  注:在/etc目录下创建一个rsyncd的目录,我们用来存放rsyncd.conf 和rsyncd.secrets文件; 
 3、touch /etc/rsyncd/rsyncd.conf  注:创建rsyncd.conf ,这是rsync服务器的配置文件;
 4、touch /etc/rsyncd/rsyncd.secrets  注:创建rsyncd.secrets ,这是用户密码文件;
 5、chmod 600 /etc/rsyncd/rsyncd.secrets  注:为了密码的安全性,我们把权限设为600;
 6、ls -lh /etc/rsyncd/rsyncd.secrets
  -rw------- 1 root root 0  8月 26 11:44 /etc/rsyncd/rsyncd.secrets
 7、touch /etc/rsyncd/rsyncd.motd
 我们来个简单的示例;比如我们要备份服务器上的 /data目录 ,在/data目录中,我想把program和temp目录排除在外;
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help

# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid 
port = 873 #注:指定运行端口,默认是873,您可以自己指定;
address = 192.168.1.100 #注:指定服务器IP地址;
uid = root 
gid = root 

use chroot = yes
read only = yes
#注:用chroot,在传输文件之前,服务器守护程序在将chroot 到文件系统中的目录中,这样做的好处是可能保护系统被安装漏洞侵袭的可能。缺点是需要超级用户权限。另外对符号链接文件,将会排除在外。也就是说,你在 rsync服务器上,如果有符号链接,你在备份服务器上运行客户端的同步数据时,只会把符号链接名同步下来,并不会同步符号链接的内容;这个需要自己来尝试;
#注:read only 是只读选择,也就是说,不让客户端上传文件到服务器上。还有一个 write only选项,自己尝试是做什么用的吧;
#limit access to private LANs
hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0
hosts deny=*
#注:在您可以指定单个IP,也可以指定整个网段,能提高安全性。格式是ip 与ip 之间、ip和网段之间、网段和网段之间要用空格隔开;
max connections = 5
#注:客户端最多连接数;
motd file = /etc/rsyncd/rsyncd.motd
#注:motd file 是定义服务器信息的,要自己写 rsyncd.motd 文件内容。
#This will give you a separate log file
log file = /var/log/rsync.log
#注:rsync 服务器的日志;
#This will log every file transferred - up to 85,000+ per user, per sync
transfer logging = yes
#注:这是传输文件的日志;
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300

[data] 
#注:模块,它为我们提供了一个链接的名字,链接到哪呢,在本模块中,链接到了/data目录;要用[name] 形式;
path = /opt   #注:指定文件目录所在位置,这是必须指定的;
list=yes #注:list 意思是把rsync 服务器上提供同步数据的目录在服务器上模块是否显示列出来。默认是yes 。如果你不想列出来,就no ;如果是no是比较安全的,至少别人不知道你的服务器上提供了哪些目录。你自己知道就行了;
ignore errors #注:忽略IO错误,详细的请查文档;
auth users = root #注:认证用户是 root  ,是必须在 服务器上存在的用户;
secrets file = /etc/rsyncd/rsyncd.secrets  #注:密码存在哪个文件;
comment = linuxsir home # 注:注释可以自己定义,写什么都行,写点相关的内容就行;
exclude =   program/  temp/     #注:exclude 是排除的意思,也就是说,要把/opt目录下的program和temp 排除在外; program/和temp/目录之间有空格分开 ; 
#注: 关于 auth users 是必须在服务器上存在的真实的系统用户,如果你想用多个用户,那就以,号隔开;比如 auth users = root , root1
#
#
#
2、密码文件:/etc/rsyncd/rsyncd.secrets的内容格式:用户名:密码
rsyncd.secrets文件权限对其它用户组是不可读的。如果设置错误,可能rsync不工作。
这里的密码和系统密码无任何关系
如:root:123456
3、/etc/rsyncd/rsyncd.motd

+++++++++++++++++++++++++++
+ Tianbymy  rsync  2010-2011 +
++++++++++++++++++++++++++


启动 Rsync
/usr/bin/rsync --daemon  --config=/etc/rsyncd/rsyncd.conf
防火墙设置
Linux 防火墙是用iptables,所以我们至少在服务器端要让你所定义的rsync 服务器端口通过,客户端上也应该让通过。

iptables -A INPUT -p tcp -m state --state NEW  -m tcp --dport 873 -j ACCEPT
iptables -L  #查看一下防火墙是不是打开了 873端口;

######################################
客户机配置
######################################
1、首先:我们看看rsync服务器上提供了哪些可用的数据源;

rsync  --list-only  [email protected]::
返回:
 +++++++++++++++++++++++++++
 + Tianbymy  rsync  2010-2011 +
 +++++++++++++++++++++++++++

 data            linuxsir home # 注:注释可以自己定义,写什么都行,写点相关的内容就行;
注: 前面是rsync 所提供的数据源,也就是我们在rsyncd.conf 中所写的[data]模块。而“linuxsir home”是由[data]模块中的 comment = linuxsir home 提供的;//为什么没有把beinan 数据源列出来呢?因为我们在[beinan]中已经把list=no了。 
再:试试这个?
rsync  --list-only  [email protected]::linuxsirhome

2、 rsync 客户端同步数据;
rsync -avzP [email protected]::data   data
注: 这个命令的意思就是说,用root 用户登录到服务器上,把data数据,
同步到本地目录data上。当然本地的目录是可以你自己定义的,比如 其他任意目录也是可以的;
当你在客户端上,当前操作的目录下没有data这个目录时,系统会自动为你创建一个;
当存在 data这个目录中,你要注意它的写权限。
说明:
-a 参数,相当于-rlptgoD,-r 是递归 -l 是链接文件,意思是拷贝链接文件;-p 表示保持文件原有权限;-t 保持文件原有时间;-g 保持文件原有用户组;-o 保持文件原有属主;-D 相当于块设备文件;
-z 传输时压缩;
-P 传输进度;
-v 传输时的进度等信息,和-P有点关系,自己试试
rsync -avzP  --delete [email protected]::data   data
#这回我们引入一个 --delete 选项,表示客户端上的数据要与服务器端完全一致,如果 linuxsirhome目录中有服务器上不存在的文件,则删除。最终目的是让linuxsirhome目录上的数据完全与服务器上保持一致;用的时候要小心点,最好不要把已经有重要数所据的目录,当做本地更新目录,否则会把你的数据全部删除;
rsync -avzP  --delete  --password-file=rsync.password  [email protected]::data   data
这次我们加了一个选项 --password-file=rsync.password ,这是当我们以linuxsir用户登录rsync服务器同步数据时,密码将读取 rsync.password 这个文件。这个文件内容只是linuxsir用户的密码。我们要如下做;

touch rsync.password
chmod 600 rsync.passwod
echo "222222"> rsync.password
rsync -avzP  --delete  --password-file=rsync.password  [email protected]::data  data


##################################################################
RSYNC常见问题
问题一:

@ERROR: chroot failed

rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

原因:

服务器端的目录不存在或无权限。创建目录并修正权限可解决问题。

 

问题二:

@ERROR: auth failed on module tee

rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

原因:

服务器端该模块(tee)需要验证用户名密码,但客户端没有提供正确的用户名密码,认证失败。提供正确的用户名密码解决此问题。

 

问题三:

@ERROR: Unknown module ‘tee_nonexists’

rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

原因:

服务器不存在指定模块。提供正确的模块名或在服务器端修改成你要的模块以解决问题。

 

问题四:

password file must not be other-accessible

continuing without password file

Password:

原因:

这是因为rsyncd.pwd rsyncd.secrets的权限不对,应该设置为600。如:chmod 600 rsyncd.pwd

 

问题五:

rsync: failed to connect to 218.107.243.2: No route to host (113)

rsync error: error in socket IO (code 10) at clientserver.c(104) [receiver=2.6.9]

原因:

对方没开机、防火墙阻挡、通过的网络上有防火墙阻挡,都有可能。关闭防火墙,其实就是把tcp udp的873端口打开。

 

问题六:

rsync error: error starting client-server protocol (code 5) at main.c(1524) [Receiver=3.0.7]

原因:

/etc/rsyncd.conf配置文件内容有错误。请正确核对配置文件。

 

问题七:

rsync: chown "" failed: Invalid argument (22)

原因:

权限无法复制。去掉同步权限的参数即可。(这种情况多见于Linux向Windows的时候)

 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章