网站首页 - 关于我们 - 团队成员 - 联系我们

 rss
♀ 您现在的位置在:首页 -> CNFUG期刊 -> 正文(阅读
RSYNC ON FreeBSD 5.2 HOWTO V1.0

tonnyom < tonnyom@hotmail.com >

版权声明:可以任意转载,转载时请务必以文字形式标明文章原始出处和作者信息及本声明.

前言
RSYNC是Linux,UNIX系统下的数据镜像及备份工具,具有可使本地和远程两台主机的文件,目录之间,快速同步镜像,远程数据备份等功能.在同步过程中,可根据远程服务器上的数据变动,相应的删除或者更新本地机的数据,同步数据不用全部传送,大大提高同步及备份文件的速度.同时在网络安全方面,也可以设置为SSH传输模式. 远程主机(Rsync Server)可为RSYNC daemon模式,开启之后将开放tcp4 873 port,等待本地主机(Rsync client)的连接,连接时远程主机会进行认证,确认合法用户进入,便开始进行资料传输,在第一次传输时会把整个资料都备份同步到本地主机上,在下一次传输时,添加相应参数则可根据远程主机的数据变动来相应调整同步操作. 本文只是 RSYNC 软件的一个简单应用操作文档,主要是给初学者一个初步介绍,如果大家在应用中,有什么更好的意见和建议,请Mail 我.我将继续更新此文档,谢谢! :)
软件及平台
FreeBSD 5.2 (Server and Client)

Server IP:172.18.5.251 Hostname: freebsd-1
Client IP:172.18.5.247 Hostname: freebsd-2

apache_1.3.29
rsync-2.5.7

目的
备份Rsync Server(172.18.5.251)上的 /usr/local/www/data-dist 目录下所有内容,到Rsync Client(172.18.5.247)的/backup/www 下


安装及配置

一,Rsync Server

Step 1: 安装

freebsd-1#cd /usr/ports/net/rsync
freebsd-1#make install clean

Step 3: 配置rsyncd.conf

freebsd-1#vi /usr/local/etc/rsyncd.conf //加入以下内容

[www]
comment = web server backup
path = /usr/local/www/data-dist
auth users = tonny
uid = nobody
gid = nogroup
secrets file = /usr/local/etc/rsyncd.secrets
read only = no


Step 4: 配置rsyncd.secrets
freebsd-1#vi /usr/local/etc/rsyncd.secrets //加入以下内容

tonny:123456 // 认证所需的用户名/密码

freebsd-1#chmod 600 rsyncd.secrets


Step 5: 配置rc.conf
freebsd-1#vi /etc/rc.conf //加入以下内容

rsyncd_enable="YES"


Step 6: 启动 Rsync daemon模式
freebsd-1#vi /usr/local/etc/rc.d/rsyncd.sh //加入以下内容

command_args="-4 --daemon" <<<--- 启用ipv4 协议

freebsd-1#/usr/local/etc/rc.d/rsyncd.sh start


Step 7: 检查Rsync daemon启动状态
freebsd-1# sockstat | grep rsync
root rsync 440 3 dgram -> /var/run/log
root rsync 440 4 tcp4 *:873 *:*

二,Rsync Client

Step 1: 安装

freebsd-2#cd /usr/ports/net/rsync
freebsd-2#make install clean

Step 2: 建立备份目录
freebsd-2#cd /
freebsd-2#mkdir -p backup/www

Step 3: 配置rsyncd.secrets
freebsd-2#vi /usr/local/etc/rsyncd.secrets //加入以下内容

123456 //Rsync Server上的认证密码,不用输入用户名

freebsd-2#chmod 600 rsyncd.secrets


Step 4: 检查备份同步状态
freebsd-2#/usr/local/bin/rsync -avzP --delete
--password-file=/usr/local/etc/rsyncd.secrets tonny@172.18.5.251::www
/backup/www/

--->>> 将Rsync Server的Web页面,备份或同步到了Rsync Client的/backup/www下


Step 5: Auto Rsync Shell:

freebsd-2#cd /usr/local/etc/rc.d/

freebsd-2#chmod a-x rsyncd.sh

freebsd-2#vi rsync.sh //加入以下内容

#!/bin/sh

/usr/local/bin/rsync -avzP --delete
--password-file=/usr/local/etc/rsyncd.secrets tonny@172.18.5.251::www
/backup/www/

freebsd-2#chmod a+x rsync.sh

freebsd-2#crontab -e //加入以下内容(每天下午5点半自动备份同步)

30 17 * * * /usr/local/etc/rc.d/rsync.sh

三,高级应用(Rsync With SSH)

Rsync Server

freebsd-1#/usr/bin/ssh-keygen -d

Rsync Client

freebsd-2#/usr/bin/ssh-keygen -d

freebsd-2#scp ~/.ssh/id_dsa.pub 172.18.5.251:/root/.ssh/authorized_keys

freebsd-2#ssh-agent csh 或 (ssh-agent bash) --->>> #echo $SHELL
查看当前SHELL
freebsd-2#ssh-add id_dsa --->>> 输入 passphase


freebsd-2#/usr/local/bin/rsync -avzP --delete -e ssh
172.18.5.251:/usr/local/www/data-dist/ /backup/www/

PS: 参数说明

-a, --archive archive mode, equivalent to -rlptgoD
//档案模式
-v, --verbose
//详细模式
-z, --compress compress file data
//压缩文件
-P equivalent to --partial --progress
//显示进度
--delete
This tells rsync to delete any files on the receiving side
that
aren't on the sending side.
//保持远程机器的文件同步性
-e ssh use SSH connection
//使用SSH连接,保证数据安全


参考

http://rsync.samba.org/ rsync 网站

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/openssh.html
freebsd handbook手册

网友评论  以下本论与CNFUG(China FreeBSD User Group)立场无关
网友:deviant 发表时间:2004年11月17日

rsync是一种被动等带客户指令的同步。
我现在想实现的是
当server端一有文件变化(比如有新文件生成),自动的
能够使得将这些文件推送到客户端。
请问有办法吗?

网友:LeLe 发表时间:2004年11月27日

首先,rsync 作为push方式(server to client) 也是可行的.

另外你的问题,关键只是在于对于新文件的判断(可以通过写shell,或者其他方式实现),至于rsync不管是pull方式,还是push方式,那就无所谓了.

网友:Walter Zhou 发表时间:2004年12月14日

You can use UNISON mirror tools.

网友:muyijin 发表时间:2005年02月22日

那复制到客户机的磁带机上也可以同样的操作?
反正FREEBSD对所有的设备当作目录处理的。

网友:dentelle 发表时间:2005年04月13日

hotel londra
hotel milano
hotel parigi
hotel roma
hotel venezia
albergo roma
hotel barcellona
hotel nizza
prenotazione hotel milano
prenotazione hotel roma
alberghi venezia
albergo venezia
monitor lcd
balazzo bauer
portatili usati

网友:dd 发表时间:2005年04月13日

http://hotel-londra.has.it
http://hotel-milano.has.it
http://hotel-parigi.has.it
http://hotel-roma.has.it
http://hotel-venezia.has.it
http://albergo-roma.has.it
http://hotel-barcellona.has.it
http://hotel-nizza.has.it
http://prenotazione-hotel-milano.has.it
http://prenotazione-hotel-roma.has.it
http://alberghi-venezia.has.it
http://albergo-venezia.has.it
http://monitor-lcd.has.it
http://palazzo-bauer.has.it
http://portatili-usati.has.it

我也说几句




推荐给好友

  


文章下载

本功能正在开发中,目前不能使用,敬请原谅。

√ 期刊在线投稿: /journal/contribute.html

√ 本文打印于《CNFUG期刊》,欢迎访问 http://www.cnfug.net 获取更多技术文章。