Chinaunix首页 | 论坛 | 博客
  • 博客访问: 858815
  • 博文数量: 436
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -103
  • 用 户 组: 普通用户
  • 注册时间: 2016-08-01 09:48
个人简介

爱生活,爱IT

文章分类

全部博文(436)

文章存档

2015年(1)

2014年(2)

2013年(6)

2011年(39)

2010年(176)

2009年(30)

2008年(28)

2007年(54)

2006年(91)

2005年(9)

分类: LINUX

2006-03-28 14:19:14

Rsync,可用于全自动的网络备份(镜像),目前由rsync.samba.org 维护.
 
本文环境:
rsync:  version 2.6.3  protocol version 28
OS: Slackware 9.2
启动 Rysncd
rsync(d)服务端启动两种方式
1.daemon  2.xinetd inetd
启动后绑在 TCP/873 端口
% cat /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
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
}


配置/etc/rsyncd.conf

如果没有创建rsyncd.conf文档,自己需要创建rsyncd.conf文档(下面其实配置相同)

[root@linuxas3 root]# vi /etc/rsyncd.conf

uid=nobody
gid=nobody
max connections=4
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
#auth users=root
secrets file=/etc/rsyncd.secrets

[postfix]
path=/var/mail
comment = backup mail
ignore errors
read only = yes
list = no
auth users = postfix

[netkiller]
path=/home/netkiller/web
comment = backup 9812.net
ignore errors
read only = yes
list = no
auth users = netkiller

[pgsqldb]
path=/var/lib/pgsql
comment = backup postgresql database
ignore errors
read only = yes
list = no



选择说明

uid = nobody
gid = nobody
use chroot = no # 不使用chroot
max connections = 4 # 最大连接数为4
pid file = /var/run/rsyncd.pid #进程ID文件
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log # 日志记录文件
secrets file = /etc/rsyncd.pwd # 认证文件名,主要保存用户密码,权限建议设为600,所有者root

[module] # 这里是认证的模块名,在client端需要指定
path = /var/mail # 需要做镜像的目录
comment = backup xxxx # 注释
ignore errors # 可以忽略一些无关的IO错误
read only = yes # 只读
list = no # 不允许列文件
auth users = postfix # 认证的用户名,如果没有这行,则表明是匿名

[other]
path = /path/to...
comment = xxxxx


密码文件A,(被认证的用户,就是本地与要其它地同上时,需要的认证用户)

在server端生成一个密码文件/etc/rsyncd.pwd
[root@linuxas3 root]# echo postfix:xxx >>/etc/rsync_passwd
[root@linuxas3 root]# chmod 600 /etc/rsync_passwd
密码文件B,(为远程用户的认证:就是其它需要与本地同步时,远程PC在执行同步时所需要的帐号)
在server端生成一个密码文件/etc/rsyncd.secrets
[root@linuxas3 root]# echo postfix:xxx >>/etc/rsyncd.secrets[[root@linuxas3 root]# chmod 600 /etc/rsyncd.secrets


启动rsync daemon

[root@linuxas3 root]# rsync --daemon


测试

[root@linux docbook]# rsync rsync://

[root@linux tmp]# rsync rsync://netkiller@
Password:

[chen@linux temp]$ rsync -vzrtopg --progress --delete postfix@ /tmp
Password:


rsync rsync://认证用户@主机/模块

rsync -vzrtopg --progress --delete 认证用户@主机::模块 /mirror目录

添加到启动文件

echo "rsync --daemon" >> /etc/rc.d/rc.local

完成!
 
rsync的参数不是很多,比较常用的:
-z 压缩
-r 递归,就是文件夹下所有东西
-l 链接当链接
-t 同步文件时间
-o -g 同步文件owner group
----delete  删除目标目录(镜像目前服务器上)中的文件,就是如果源服务器上没有文件A,而目标目票中有文件A,则删除A。如果没有这个选项,那么每次执行镜像,就把源目录的文件或子目录同步到目标服务器,并不管服务器上的文件(文件名相同则覆盖)。
 
郁闷的问题:
 
2.4.29 Slackware linux
我用编的脚本运行一些同步时,系统有提示:password file must not be other-accessible,
-rw-r--r--    1 root     root    11 Oct 17 09:45 /etc/rsync_passwd
-rw-r--r--    1 root     root    1097 Feb  7 09:33 /etc/rsyncd.conf
-rw-r--r--    1 root     root    12 Feb  3  2004 /etc/rsyncd.secrets
 
我把这些文件都改为如下600,则OK,
-rw-----    1 root     root    11 Oct 17 09:45 /etc/rsync_passwd
-rw-----    1 root     root    1097 Feb  7 09:33 /etc/rsyncd.conf
-rw-----    1 root     root    12 Feb  3  2004 /etc/rsyncd.secrets
 
但是在2.4.20 Slackware linux,这些文件属性就是(644) -rw-r--r-- ,可能是版的原因
 
再补充:
同步时注意注意 / 最后的问题
不放/  则目录名也包含mirror
放 / 则只有目录里面的东西mirror了
参考文献:
 

可能會遇到的疑難問題:

1. Q: 出現以下這個訊息, 是怎麼一回事?

@ERROR: auth failed on module xxxxx
rsync: connection unexpectedly closed (90 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(150)

A: 這是因為密碼設錯了, 無法登入成功, 請再檢查一下 rsyncd.secrets 中的密碼設定, 二端是否一致?

2. Q: 出現以下這個訊息, 是怎麼一回事?

password file must not be other-accessible

continuing without password file

Password:

A: 這表示 rsyncd.secrets 的檔案權限屬性不對, 應設為 600

請下 chmod 600 rsyncd.secrets

3. Q: 出現以下這個訊息, 是怎麼一回事?

@ERROR: chroot failed
rsync: connection unexpectedly closed (75 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(150)

A: 這通常是您的 rsyncd.conf 中
的 path 路徑所設的那個目錄並不存在所致.
請先用 mkdir 開設好備份目錄.

 
Windy.Chan 修改于 28 Mar, 2007 13:05
 
 

阅读(4875) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~