1.1.1 下载最新的Rsync(2011.07.22)
服务端、客户端:rsync-3.0.9pre1.tar.gz #这个是2010年07月22日时最新的版本
1.1.2 安装Rsync
将下载好的rsync-3.0.9pre1.tar.gz,放到:/RsyncDemo,或任意一个自定义的文件夹。
注意:需要在服务端和客户端分别安装,安装使用的包和命令都一样的。
[root@redhat6 RsyncDemo]# tar zxvf rsync-3.0.9pre1.tar.gz
[root@redhat6 RsyncDemo]# cd rsync-3.0.9pre1 #如果版本不是3.0.9了,请输入cd rsync后按tab键自动补齐
[root@redhat6 rsync-3.0.9pre1]# ./configure
# 出现“rsync 3.0.9pre1 configuration successful ”表示安装成功,如果不成功,则看前面差什么包就下载并安装什么包即可。
[root@redhat6 rsync-3.0.9pre1]# make
[root@redhat6 rsync-3.0.9pre1]# make install
#无错误内容回显,表示安装成功,如果make那一步就失败,估计是你没有gcc编译环境或其他问题。
1.1.3 配置Rsync
1.1.3.1 服务端配置
[root@redhat6 rsync-3.0.9pre1]# vi /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no#这里原本是yes,修改成no即可。
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[root@redhat6 rsync-3.0.9pre1]# chkconfig rsync on
[root@redhat6 rsync-3.0.9pre1]# chkconfig rsync --list
rsync 启用
[root@redhat6 etc]# touch /etc/rsync.conf
[root@redhat6 etc]# vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 5
strict modes = yes
port = 873
[demo]
path = /RsyncDemo
comment = This is demo.
auth users = test
uid = root
gid = root
secrets file = /etc/rsync.password
ignore errors
read only = no
list = no
[root@redhat6 etc]# vi /etc/rsync.password #创建密码认证文件
test:password #在文件加入此行
[root@redhat6 etc]# chown root.root rsync.password #修改权限
[root@redhat6 etc]# chmod 400 rsync.password #修改权限
[root@redhat6 etc]# /usr/bin/rsync –daemon #启动服务
[root@redhat6 etc]# vi /etc/rc.local #设置系统启动时,加载rsync服务
/usr/local/rsync –daemon#在rc.local文件的最后一行加入此行信息即可
[root@redhat6 etc]# lsof -i :873 #检查服务是否启动,有如下内容表示已经启动
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync 29673 root 4u IPv4 80341 0t0 TCP *:rsync (LISTEN)
rsync 29673 root 5u IPv6 80342 0t0 TCP *:rsync (LISTEN)
1.1.3.2 客户端配置
#注意:要在客户端的机器上也安装rsync才可以,安装方法同上1.1.2,如果是本机备份,则不需要,也不需要下列配置,直接使用命令即可。
[root@redhat6 home]# vi /home/rsync.password #创建密码文件,直接放在家目录下
password #密码文件中只需要输入服务端对应账户密码中的密码即可
[root@redhat6 home]# chown root.root rsync.password #修改权限
[root@redhat6 home]# chmod 600 rsync.password #修改权限,注意这里是600
1.1.4 使用Rsync
1.1.4.1 从客户端操作,将服务端的数据备份到本地
[root@redhat6 ~]# rsync -avz --password-file=/home/rsync.password test@192.168.0.11::demo /home/
#出现类似以下的内容,表示服务端和客户端都已经配置完成
receiving incremental file list
./
rsync-3.0.9pre1.tar.gz
rsync-3.0.9pre1/zlib/zutil.o
sent 5387 bytes received 7389029 bytes 4929610.67 bytes/sec
total size is 7368437 speedup is 1.00
#如果提示以下内容,表示服务端的防火墙策略有问题,需对rsync放行,或直接关闭防火墙
rsync: failed to connect to 192.168.0.11 (192.168.0.11): Connection timed out (110)
rsync error: error in socket IO (code 10) at clientserver.c(122) [Receiver=3.0.9pre1]
[root@eadhat6 ~]# /etc/init.d/iptables stop #附,关闭防火墙命令,注意此行是在服务器端执行的
1.1.4.2 从客户端操作,将本地数据上传到客户端
[root@redhat6 home]# rsync -avz --password-file=/home/rsync.password /home/rsynctest test@192.168.0.11::demo
#出现以下类似内容,表示成功
sending incremental file list
rsynctest/
sent 41 bytes received 12 bytes 35.33 bytes/sec
total size is 0 speedup is 0.00
1.1.4.3 从服务端操作,主动将数据备份到客户端上
[root@redhat6 /]# rsync -avz /RsyncDemo root@10.10.4.193:/home/test/
#工具虽然允许这么做,但不推荐这么做,因为会占用需要备份的服务器资源。