rsync 服务器架设方法
1、 yum install rsync
2、 创建以下文件:
a)         [root@linuxsir:~]#mkdir /etc/rsyncd 注:在/etc目录下创建一个rsyncd的目录,我们用来存放rsyncd.conf 和rsyncd.secrets文件;
b)         [root@linuxsir:~]#touch /etc/rsyncd/rsyncd.conf 注:创建rsyncd.conf ,这是rsync服务器的配置文件;
c)         [root@linuxsir:~]#touch /etc/rsyncd/rsyncd.secrets 注:创建rsyncd.secrets ,这是用户密码文件;
d)         [root@linuxsir:~]#chmod 600 /etc/rsyncd/rsyncd.secrets 注:为了密码的安全性,我们把权限设为600;
e)         [root@linuxsir:~]#ls -lh /etc/rsyncd/rsyncd.secrets
f)          -rw------- 1 root root 14 2007-07-15 10:21 /etc/rsyncd/rsyncd.secrets
g)         [root@linuxsir:~]#touch /etc/rsyncd/rsyncd.motd
3、 下一就是我们修改 rsyncd.conf 和rsyncd.secrets 和rsyncd.motd 文件的时候了
rsyncd.conf 是rsync服务器主要配置文件,我们来个简单的示例;比如我们要备份服务器上的 /home 和/opt ,在/home中,我想把beinan和samba目录排除在外;
# Distributed under the terms of the GNU General Public License v2
 
# 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
address = 192.168.1.171 
#uid = nobody
#gid = nobody   
uid = root  
gid = root  
 
use chroot = yes 
read only = yes 
 
 
#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=*
 
max connections = 5
motd file = /etc/rsyncd/rsyncd.motd
 
#This will give you a separate log file
#log file = /var/log/rsync.log
 
#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
 
[linuxsirhome]  
path = /home   
list=yes
ignore errors
auth users = linuxsir
secrets file = /etc/rsyncd/rsyncd.secrets 
comment = linuxsir home 
exclude =   beinan/ samba/     
 
[beinan]
path = /opt
list=no
ignore errors
comment = optdir  
auth users = beinan
secrets file = /etc/rsyncd/rsyncd.secrets
 
注: 关于 auth users 是必须在服务器上存在的真实的系统用户,如果你想用多个用户,那就以,号隔开;比如 auth users = beinan , linuxsir 密码文件:/etc/rsyncd/rsyncd.secrets的内容格式:用户名:密码
 
而我们在例子中rsyncd.secrets的内容如下类似的;在文档中说,有些系统不支持长密码,自己尝试着设置一下吧。另外 rsyncd.secrets文件权限对其它用户组是不可读的。如果你设置错了,可能rsync不工作。
linuxsir:222222
beinan:333333
 
注: 这里的密码值得注意,为了安全,你不能把系统用户的密码写在这里。比如你的系统用户 linuxsir 密码是 abcdefg ,为了安全,你可以让rsync 中的linuxsir 为 222222 。这和samba的用户认证的密码原理是差不多的;
 
rsyncd.motd 文件;
它是定义rysnc 服务器信息的,也就是用户登录信息。比如让用户知道这个服务器是谁提供的等;类似ftp服务器登录时,我们所看到的 linuxsir.org ftp ……。 当然这在全局定义变量时,并不是必须的,你可以用#号注掉,或删除;我在这里写了一个 rsyncd.motd的内容为:welcome to rsync
4、 架设rsync服务器的示例说明:
4.1 全局定义;
 在rsync 服务器中,全局定义有几个比较关健的,根据我们前面所给的配置文件 rsyncd.conf 文件;
pid file = /var/run/rsyncd.pid   注:告诉进程写到 /var/run/rsyncd.pid 文件中;
port = 873 注:指定运行端口,默认是873,您可以自己指定;
address = 192.168.1.171 注:指定服务器IP地址;
uid = nobody  
gid = nobdoy  
 
注:服务器端传输文件时,要发哪个用户和用户组来执行,默认是nobody。 如果用nobody 用户和用户组,可能遇到权限问题,有些文件从服务器上拉不下来。所以我就偷懒,为了方便,用了root 。不过您可以在定义要同步的目录时定义的模块中指定用户来解决权限的问题。
use chroot = yes 
 
 
注:用chroot,在传输文件之前,服务器守护程序在将chroot 到文件系统中的目录中,这样做的好处是可能保护系统被安装漏洞侵袭的可能。缺点是需要超级用户权限。另外对符号链接文件,将会排除在外。也就是说,你在rsync服务器上,如果有符号链接,你在备份服务器上运行客户端的同步数据时,只会把符号链接名同步下来,并不会同步符号链接的内容;这个需要自己来尝试;
 
read only = yes 
 
注: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 
 
 
注:在您可以指定单个IP,也可以指定整个网段,能提高安全性。格式是ip 与ip 之间、ip和网段之间、网段和网段之间要用空格隔开;
 
max connections = 5   
 
注:客户端最多连接数;
 
motd file = /etc/rsyncd/rsyncd.motd
 
 
注:motd file 是定义服务器信息的,要自己写 rsyncd.motd 文件内容。当用户登录时会看到这个信息。比如我写的是:
 
Welcome to rsync
 
log file = /var/log/rsync.log
 
 
注:rsync 服务器的日志;
 
transfer logging = yes
 
注:这是传输文件的日志;
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
 
 
 
 4.2 模块定义;
 模块定义什么呢?主要是定义服务器哪个目录要被同步。每个模块都要以[name]形式。这个名字就是在rsync 客户端看到的名字,其实有点象Samba服务器提供的共享名。而服务器真正同步的数据是通过 path 来指定的。我们可以根据自己的需要,来指定多个模块。每个模块要指定认证用户,密码文件、但排除并不是必须的;
 
 
下面前面配置文件模块的例子:
 
[linuxsirhome]  
注:模块,它为我们提供了一个链接的名字,链接到哪呢,在本模块中,链接到了/home目录;要用[name] 形式;
path = /home    注:指定文件目录所在位置,这是必须指定的;
auth users = linuxsir   注:认证用户是linuxsir ,是必须在 服务器上存在的用户;
list=yes   注:list 意思是把rsync 服务器上提供同步数据的目录在服务器上模块是否显示列出来。默认是yes 。如果你不想列出来,就no ;如果是no是比较安全的,至少别人不知道你的服务器上提供了哪些目录。你自己知道就行了;
ignore errors 注:忽略IO错误,详细的请查文档;
secrets file = /etc/rsyncd/rsyncd.secrets   注:密码存在哪个文件;
comment = linuxsir home data 注:注释可以自己定义,写什么都行,写点相关的内容就行;
exclude =   beinan/   samba/     
 
 注:exclude 是排除的意思,也就是说,要把/home目录下的beinan和samba 排除在外; beinan/和samba/目录之间有空格分开 ;
 
 
[beinan] 
path = /opt 注:指定文件目录所在位置;
list=no
comment = optdir  
auth users = beinan 注:是必段在服务器上存在的用户;
secrets file = /etc/rsyncd/rsyncd.secrets
ignore errors
5、 启动rsync服务器
/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
6、 列出rsync 服务器上的所提供的同步内容
rsync --list-only linuxsir@linuxsir.org::
7、 rsync 客户端同步数据
 
重点配置文件:
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# 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
address = 192.168.3.24
#uid = nobody
#gid = nobody   
uid = root
gid = root
 
use chroot = yes
read only = yes
 
 
#limit access to private LANs
hosts allow=*
hosts deny=*
 
max connections = 5
motd file = /etc/rsyncd/rsyncd.motd
 
#This will give you a separate log file
#log file = /var/log/rsync.log
 
#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
 
[test]
path = /backup
list=yes
ignore errors
auth users = root
secrets file = /etc/rsyncd/rsyncd.secrets
 
自动执行
*/5 * * * * zhixingmingling