Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3439489
  • 博文数量: 349
  • 博客积分: 5771
  • 博客等级: 大校
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-06 11:52
个人简介

it

文章分类

全部博文(349)

文章存档

2019年(2)

2018年(2)

2017年(1)

2016年(2)

2015年(18)

2014年(36)

2013年(69)

2012年(100)

2011年(62)

2010年(57)

分类:

2010-06-03 15:38:19

前言:rsync 是一个单向同步。unison是双向同步。
rsync 是一个Unix系统下的文件同步和传输工具。rsync是用 “rsync 算法”提供了一个客户机和远程文件服务器的文件同步的快速方法。
Some features of rsync include
rsync 包括如下的一些特性:
* can update whole directory trees and filesystems
能更新整个目录和树和文件系统;
* optionally preserves symbolic links, hard links, file ownership, permissions, devices and times
有选择性的保持符号链链、硬链接、文件属于、权限、设备以及时间等;
* requires no special privileges to install
对于安装来说,无任何特殊权限要求;
* internal pipelining reduces latency for multiple files
对于多个文件来说,内部流水线减少文件等待的延时;
* can use rsh, ssh or direct sockets as the transport
能用rsh、ssh 或直接端口做为传输入端口;
* supports anonymous rsync which is ideal for mirroring
支持匿名rsync 同步文件,是理想的镜像工具;

笔者的操作系统A(192.168.99.25)和B(192.168.99.26)都为redhat AS4.先介绍一下A服务器RSYNC的安装
1.
下载RSYNC软件:
wget

2.
解压安装
shell> tar -zxvf rsync-2.6.9.tar.gz
shell> cd rsync-2.6.9
shell> ./configure --prefix=/server/rsync
shell> make

shell> make install
我的系统是全盘安装所以无需这步骤。但是切记默认的rsync服务是在xinet中的
2、几个文件准备
mkdir /etc/rsync
vi /etc/rsync/rsyncd.conf
vi /etc/rsync/rsyncd.scrt
chmod 600 /etc/rsync/rsyncd.scrt

3.安装完成后,rsync.2.6.9,并无RSYNC的配置文件,,要手工创建

shell>vi /etc/rsync/rsyncd.conf     #内容如下
uid=root

gid=root

max connections=4 linux

user chroot=yes

log file=/var/log/rsyncd.log

pid file=/var/run/rsyncd.pid 

lock file=/var/run/rsyncd.lock mysql

secrets file=/etc/rsync/rsyncd.scrt

#hosts allow=218.107.243.2,60.173.7.35 linux

#hosts deny=60.173.7.34 

[squid]
path = /usr/local/squid/etc/
comment = squid
ignore errors
read only = yes
list = yes
hosts allow = *
auth users = squid

4.再来创建密码文件.
vi /etc//rsync/rsyncd.scrt
squid:123456
有多个用户,在第二行列出!
处于安全原因,要将该文件更改权限(如果不更改权限,后期复制时,会出现错误) ssh
:此用户和密码,非系统用户的密码,也就是说系统中无需创建upfiles用户! ssh

5.运行服务 oracle

/usr/bin/rsync --daemon --config=/etc/rsync/rsyncd.conf  注意这里=前后是没有空格的。
此时用ps -aux|grep rsync就能看到rsync --daemon进程!
linux

6.测试

本地测试:/usr/bin/rsync -a squid@A自己的IP地址::squid

输入密码:123456

看一下能否看到自己所共享文件夹下的文件(如果上在的参数码相机list=no,可会看不到,故在测试时,请将list=yes)

[root@localhost Desktop]# rsync -a squid@192.168.99.25::squid
Password:
drwxr-xr-x        4096 2010/06/01 09:26:40 .
-rw-r--r--       16384 2009/12/03 21:47:01 .squid.conf.swn
-rw-r--r--       20480 2002/02/05 15:07:44 .squid.conf.swo
-rw-r--r--       16384 2007/10/18 11:47:39 .squid.conf.swp
drwxr-xr-x        4096 2009/06/16 08:28:31 acl
drwxr-xr-x        4096 2010/06/01 14:14:08 acl/ip
-rw-------       12288 2009/04/28 11:34:07 acl/ip/.swp
-rwxr--r--        1592 2010/05/18 15:13:01 acl/ip/8-20
-rwxr--r--        1357 2010/05/27 10:16:03 acl/ip/8-22
-rwxr--r--         982 2010/05/11 15:06:33 acl/ip/820-180
-rw-r--r--         233 2010/01/22 16:32:30 acl/ip/820-180-ssl.txt
-rwxr--r--        1338 2010/05/11 15:06:44 acl/ip/830-1730
-rwxr--r--        2935 2010/05/18 15:19:06 acl/ip/admin
-rwxr--r--        1139 2010/05/26 09:50:05 acl/ip/administrator
-rw-r--r--         114 2009/11/20 10:35:53 acl/ip/audit-user
如果能看到,则服务器的配置结束,

7、远端服务测试

下面进行服务器B的设置!
B
服务器上暂时我们只设置这的客户端的功能,也就是说,只从服务器A中同步数据!所以我们也要安装RSYNC软件,安装方法同上! mysql
安装完成后,先进行手工同步测试
/user/bin/rsync -vzrutogp --progress   a服务器
IP地址::squid /var/www/backup
要求输入密码(服务器上设置的),有看到复制数据的信息.表明成功!因为我们想让数据同步的过程自动化,所以我们要创建个脚本:
vi /usr/local/rsync/backup.sh
/server/rsync/bin/rsync -vzrutogp --progress --password-file=/etc/rsyncclien
t.pwd backup
/var/www/backup
说明:--password-file提明连接请求的密码文件,这个我们也要手工建立 oracle
vi /et/rsyncclient.pwd
mysql

只输入密码,不要输入用户名,在这里,我们只要输入123456,保存退出即可!

注意rsyncclient.pwd600 root所有
我们手工执行一次 /server/rsync/backup.sh,如果成功,直接写入crontab中即可!

unix

crontab -e
*/2* * * * /server/rsync/backup.sh
 

那么,当服务器A中填加一个文件,或删除某一个文件,有任何变化,B服务器都会跟前发生变化!但是,如果服务器B中的一个文件删除了,A是不能将其删除的!
如果你想真正的实现A,B服务器相同,可在backup.shrsync命令后加入参数--delete即可!
我没有加,是因为我不但要保证A服务器文件变化要复制到B上去,同时我还要将服务器B上的文件变化转到A上去!所以不能加--delete参数,否则两个服务器文件的同步,无法实现

安装过程常见问题解答

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

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

A: 這是因為密碼設錯了, 無法登入成功, 請再檢查一下 rsyncd.pwd ,rsyncd.sec中的密碼設定, 二端是否一致?有时服务器端没有起动服务也会出现这种情况

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

password file must not be other-accessible mysql

continuing without password file

Password: oracle

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

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

@ERROR: chroot failedrsync: 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 開設好備份目錄.

4.Q:出现一下信息是怎么回事

rsync: failed to connect to 218.107.243.2: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(104) [receiver=2.6.9]
所以情況會是:

1. 對方主機沒開機
2. 對方有 firewall 阻擋
3. 所通過的網路上有 firewall 阻擋 oracle

shell>setup   #关闭防火墙,其实最重要的也就是把tcp udp 的873端口打开。

5.Q  

[root@py-proxy-bk ~]# rsync -a root@192.168.99.25::squid /tftpboot/etc/
Password:
@ERROR: auth failed on module squid
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(359)

a:有一种可能是在配置文件rsyncd.conf有一些注释文件,可以将他们删除。


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