1、$ make$ make install但是需要注意的是必须在主服务器和同步服务器上都安装rsync,其中主服务器上是以服务器模式运行rsync,而同步上则以客户端方式运行rsync。这样在主服务器上运行rsyn守护进程,在同步上用crond定时运行客户程序来同步主服务器上需要同步的内容。配置rsync服务器端对于rsync服务器来说,最重要和复杂的就是它的配置了。rsync服务器的配置文件为/etc/rsyncd.conf,其控制认证、访问、日志记录等等。该文件是由一个或多个模块结构组成。一个模块定义以方括弧中的模块名开始,直到下一个模块定义开始或者文件结束,模块中包含格式为name=val
2、ue的参数定义。每个模块其实就对应需要备份的一个目录树,比方说在我们的实例环境中,有三个目录树需要备份:/www/和/mirror/file0/和/mirror/file1/目录,那么就需要在配置文件中定义三个模块,分别对应三个目录树。配置文件是行为单位的,也就是每个新行都表示一个新的注释、模块定义或者参数赋值。例如,在168上创建rsyncd的配置文件/etc/rsyncd.conf,内容如下:uid = nobody # 备份以什么身份进行,用户IDgid = nobody # 备份以什么身份进行,组ID#注意这个用户ID和组ID,如果要方便的话,可以设置成root,这样rsync几乎就可
3、#以读取任何文件和目录了,但是也带来安全隐患。建议设置成只能读取你要备#份的目录和文件即可。#use chroot = nomax connections = 0 # 最大连接数没有限制pid file = /var/log/rsync/rsyncd.pidlock file = /var/log/rsync/rsync.locklog file = /var/log/rsync/rsyncd.logattachment # 指定认证的备份模块名path = /www/htdocs/pub/attachment/ # 需要备份的目录comment = BACKUP attachment # 注
4、释ignore errors # 忽略一些无关的IO错误read only = false # 设置为非只读list = false # 不允许列文件#hosts allow = 210.51.0.80 #允许连接服务器的主机IP地址#hosts deny = 0.0.0.0/0.0.0.0 #禁止连接服务器的主机IP地址auth users = msyn # 认证的用户名,如果没有这行,则表明是匿名secrets file = /etc/rsyncd.scrt # 认证文件名,用来存放密码98htdocsuid = nobodygid = nobodypath = /www/htdocs/#
5、ignore errorsread only = falselist = false#hosts allow = 210.51.0.98#hosts deny = 202.108.211.38#hosts deny = 0.0.0.0/0.0.0.0auth users = msynsecrets file = /etc/rsyncd.scrt98htmluid = ejbftppath = /www/htdocs/pub/html/auth users = 98synsecrets file = /etc/rsync98.scrt这里分别定义了attachment、98htdocs、98ht
6、ml三个模块,分别对应于三个需要备份的目树。三个模块授权的备份用户分别为msyn,msyn,98syn,用户信息保存在文件/etc/rsyncd.scrt和/etc/rsync98.scrt中,其内容如下:rootwww /etc# cat /etc/rsyncd.scrt msyn:xxxxxxxxx并且该文件只能是root用户可读写的,注意,出于安全目的,这个文件的属性必需是只有属主可读,否则rsync将拒绝运行。我们可以设置它的属性为600:rootwww /etc# chmod 600 /etc/rsyncd.scrt rootwww /etc# mkdir /var/log/rsyn
7、c这些文件配置完毕以后,就需要在主服务器上启动rsyncd服务:rootwww /etc# /usr/local/bin/rsync -daemon执行完毕上面的命令后,rsync即可启动。rsync默认服务端口为873,服务器在该端口接收客户的匿名或者认证方式的备份请求。二、配置客户端1、linux下执行rsync客户端命令下一步就要运行rsync客户端的启动命令了:backupbackup / /usr/bin/rsync -vlzrtogp -progress -delete 98synx.x.x.168:98html /usr/local/apache/htdocs/pub/html/
8、 -password-file=/etc/rsync98.scrt上面这个命令行中-vzrtopg里的v是代表verbose(详细),z是代表zip(压缩),r是代表recursive(递归),topg都是保持文件原有属性如属主、时间的参数。-progress是指显示出详细的进度情况,-delete是指如果服务器端删除了这一文件,那么客户端也相应把文件删除,保持真正的一致。98synx.x.x.168:98html 是表示该命令是对服务器x.x.x.168中的98html模块进行备份,其中98syn表示使用98syn用户来对该模块进行备份。-password-file=/etc/rsync98
9、.scrt来指定密码文件,这样就可以在脚本中使用而无需交互式地输入验证密码了,这里需要注意的是这份密码文件权限属性要设得只有执行这个命令的当前用户可读,本例中是98syn用户。 这里将备份的内容存放在备份机的/usr/local/apache/htdocs/pub/html/目录下。这样,rsync同步服务就搭建好了,最后我们可以将在客户端执行的命令通过crontab定时执行来实现自动备份,或者写一些脚本,这样rsync同步服务的搭建就更加完美了。2、Windows配置客户端为了在Windows环境使用rsync工具,我们需要去下载cwRsync工具,这是一个rsync for windows
10、的版本。下载安装完成之后的目录结构类似下图所示:现在我们可以在Windows环境下运行rsync工具了,举例使用下面的命令连接服务器并开始备份目录和文件:rsync -vzrtopg -progress -delete 98synxx.xx.xx.xx:98html .bak应该可以看到:password:要求输入密码的提示,正确输入密码后就应该看到开始备份了。当然,也有可能出现类似下面的错误信息:引起这种错误有几种可能性,一是你没有输入正确的用户名或密码,二是你的服务器端存储密码的文件没有正确的权限,也就是你的密码文件不是类似这样子的权限:-rw- 1 root root在备份完成之后,我们
11、可以看到类似下图所示的状态:可以采用从文件读取密码的方式:98html .bak -password-file=.rsync98.scrt可以写成批处理,做到windows计划任务里面去,可以定时执行来实现自动备份。你也可以在这里下载cwRsync-1.2.8版:cwRsync_1.2.8_Installer.exe注:本文引用地址:/WWW.VFOCUS.NET/BLOG/mt-tb.cgi/6。请尊重原创,如有转载请注明出处。Posted by vitter at July 6, 2005 01:48 PM | 引用 评论一、faq q:如何通过ssh进行rsync,而且无须输入密码? a
12、:可以通过以下几个步骤 1. 通过ssh-keygen在server a上建立ssh keys,不要指定密码,你会在/.ssh下看到identity和identity.pub文件 2. 在server b上的home目录建立子目录.ssh 3. 将a的identity.pub拷贝到server b上 4. 将identity.pub加到user b/.ssh/authorized_keys 5. 于是server a上的a用户,可通过下面命令以用户b ssh到server b上了 e.g. ssh -l userb serverb 这样就使server a上的用户a就可以ssh以用户b的身份无
13、需密码登陆到server b上了。如何通过在不危害安全的情况下通过防火墙使用rsync?解答如下:这通常有两种情况,一种是服务器在防火墙内,一种是服务器在防火墙外。无论哪种情况,通常还是使用ssh,这时最好新建一个备份用户,并且配置sshd仅允许这个用户通过rsa认证方式进入。如果服务器在防火墙内,则最好限定客户端的ip地址,拒绝其它所有连接。如果客户机在防火墙内,则可以简单允许防火墙打开tcp端口22的ssh外发连接就ok了。我能将更改过或者删除的文件也备份上来吗?当然可以:你可以使用如:rsync -other -options -backupdir = ./backup-2000-2-1
14、3 .这样的命令来实现。这样如果源文件:/path/to/some/file.c改变了,那么旧的文件就会被移到./backup-2000-2-13/path/to/some/file.c, 这里这个目录需要自己 手工建立起来 我需要在防火墙上开放哪些端口以适应rsync?视情况而定 rsync可以直接通过873端口的tcp连接传文件,也可以通过22端口的ssh来进行文件传递,但你也可以通过下列命令改变它的端口:rsync -port 8730 otherhost:或者 rsync -e ssh -p 2002 otherhost:我如何通过rsync只复制目录结构,忽略掉文件呢?rsync -
15、av -include */ -exclude * source-dir dest-dir 为什么我总会出现read-only file system的错误呢?看看是否忘了设read only = no了 为什么我会出现error: invalid gidrsync使用时默认是用uid=nobody;gid=nobody来运行的,如果你的系统不存在nobody组的话,就会出现这样的错误,可以试试gid =nogroup或者其它 绑定端口873失败是怎么回事?如果你不是以root权限运行这一守护进程的话,因为1024端口以下是特权端口,会出现这样的错误。你可以用-port参数来改变。为什么我认证
16、失败?从你的命令行看来:你用的是: bash$ rsync -a 144.16.251.213:test test password: error: auth failed on module test i dont understand this. can somebody explain as to how to acomplish this. all suggestions are welcome. 应该是没有以你的用户名登陆导致的问题,试试rsync -a max144.16.251.213:二、一些可借鉴的脚本 这里这些脚本都是rsync网站上的例子:1、每隔七天将数据往中心服务器做
17、增量备份 #!/bin/sh # this script does personal backups to a rsync backup server. you will end up # with a 7 day rotating incremental backup. the incrementals will go # into subdirectories named after the day of the week, and the current # full backup goes into a directory called current# tridge # direct
18、ory to backup bdir=/home/$user # excludes file - this contains a wildcard pattern per line of files to exclude excludes=$home/cron/excludes # the name of the backup machine bserver=owl # your password on the backup server export rsync_password=xxxxxx # backupdir=date +%a opts=-force -ignore-errors -
19、delete-excluded -exclude-from=$excludes -delete -backup -backup-dir=/$backupdir -aexport path=$path:/bin:/usr/bin:/usr/local/bin # the following line clears the last weeks incremental directory -d $home/emptydir | mkdir $home/emptydir rsync -delete -a $home/emptydir/ $bserver:$user/$backupdir/ rmdir
20、 $home/emptydir # now the actual transfer rsync $opts $bdir $bserver:$user/current 2、备份至一个空闲的硬盘 export path=/usr/local/bin:/bin list=rootfs usr data data2for d in $list; do mount /backup/$d rsync -ax -exclude fstab -delete /$d/ /backup/$d/ umount /backup/$d done day=date +%a rsync -a -delete /usr/lo
21、cal/apache /data2/backups/$day rsync -a -delete /data/solid /data2/backups/$day 3、对vger.rutgers.edu的cvs树进行镜像 /bin/bash cd /var/www/cvs/vger/ path=/usr/local/bin:/usr/freeware/bin:run=lps x | grep rsync | grep -v grep | wc -l if $run -gt 0 ; then echo already running exit 1 fi rsync -az vger.rutgers.
22、edu:cvs/cvsroot/changelog $home/changelog sum1=sum $home/changelog sum2=sum /var/www/cvs/vger/cvsroot/changelog $sum1 = $sum2 ;echo nothing to do exit 0 rsync -az -delete -force vger.rutgers.edu:cvs/ /var/www/cvs/vger/ 4、利用find的一种巧妙方式 rsync -avr remote:find /home -name *.ch /tmp/ 可以用这种方法列出需要备份的文件列表这种方法似乎比较少人用到。
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2