rsync介绍:
rsync是一个提供快速增量文件传输的开源工具。其基于GNU General Public License 发布,目前主要有 Wayne Davison ( http://opencoder.net/)维护。
主页: http://samba.anu.edu.au/rsync/
通过他所提供的功能,rsync是一个用来做备份或者镜像的理想工具。
2009年的5月8好,rsync 3.0.6版本发布,
rsync介绍(3.0.6)
rsync是一个Unix系统的的文件传输程序,通过使用“rsync 算法”,提供远程文件同步的快速方法。顾名思义,rsync就是 remote sync。通过过程中,只是发送发生改变的文件,而不是发送全部的内容。现在是边列表变备份(删除)
他的特性如下:
1、可以更新整个目录树和文件系统;
2、可以保留文件的软链接、硬链接、权限信息、属主信息、设备和时间信息;
3、无须特殊权限即可安装;
4、内部的流水线提高了多文件传输的速度;
5、可以使用ssh、rsh或者socket链接进行传输;
6、支持匿名传输;
环境介绍
Rsync server IP:192.168.81.128
Rsync client IP: 192.168.81.130
操作系统:centos5.3 32位
1、
检查系统是否装了rsync 和xinetd包
rpm -q rsync xinetd
如果没有安装就用 yum install rsync xinetd 装上
2、
vi /etc/xinetd.d/rsync
disable         = no  <---------- change to yes
3、
Rsync server端相关配置
(1).在/etc/下创建三个文件
rsyncd.conf     rsyncd.motd     rsyncd.secrets
 
(2).新建配置文件
vi rsyncd.conf
read only = no
list = yes
uid = root                         #可以创建了备份用户,也可用root,默认是nobody
gid = root
Use chroot =no                    #默认是yes(需root运行rsync)额外的安全保护
hosts allow = 192.168.81.0/24
#hosts deny =192.168.128.0/24
max connections = 10              #设置连接数为10, 默认连接数不限制
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
motd file = /etc/rsyncd.motd      #欢迎文件,里面的内容可以随便写,就是rsync client客户端连接时显示的欢迎词
#define dirctory for rsync
[test]                              #模块:rsync的客户端
#comment = opt directory from 192.168.81.128
path =/opt/pub   #欲备份的文档目录
secrets file =/etc/rsyncd.secrets                 #密码存放文件
auth users = test              #连接帐号,和系统帐号没关系,服务器必须上存在此账号
read only = no
 
(3).欢迎文件
[root@localhost test]# vi /etc/rsyncd.motd
Welcome to use the test rsync services!
 
(4).密码文件
[root@localhost test]#vi /etc/rsyncd.secrets #密码文件权限为600,此步必须设置
test:test
(5).chmod 600 /etc/rsyncd.*
(6).运行rsync
rsync --daemon /etc/rsyncd.conf
rsync的路径    rsync配置文件
 
 
4、Rsync client端相关配置
(1)安装rsync包 ----yum install rsync
(2)创建密码文件
[root@localhost ~]#vi /etc/rsyncd.secrets 
test#客户端只需密码无须用户
注:此处密码一定要与rsync服务器端密码文件中密码保持一致,并且应为rsync客户端密码。
(3)chmod 600 /etc/rsyncd.secrets ----修改权限
如果没有这步会报如下:
password file must not be other-accessible
continuing without password file
Password:

5、同步连接测试
[root@mail pub]# rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.secrets test@192.168.81.128::test /opt/pub/
receiving incremental file list
./
test.txt
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/2)
 
sent 78 bytes  received 150 bytes  152.00 bytes/sec
total size is 0  speedup is 0.00
[root@mail pub]# ls
test.txt

测试成功
6、实现定时同步,假设凌晨2两同步
vim crond.rsync
00 2 * * * rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.secrets test@192.168.81.1128::test /opt/pub
crontab crond.rsync
crontab -e编辑现在有crontab
crontab -l
 
测试结果:
把rsync server端 的文件 同步到 rsync client相应的目录下面