您的位置:首页 > 其它

rsync 的安装和同步测试总结

2010-12-15 15:01 330 查看
rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了--remote sync。它的特性如下:

可以镜像保存整个目录树和文件系统。

可以很容易做到保持原来文件的权限、时间、软硬链接等等。

无须特殊权限即可安装。

优化的流程,文件传输效率高。

可以使用rcp、ssh等方式来传输文件,当然也可以通过直接的socket连接。

支持匿名传输,以方便进行网站镜象。

1)Centos默认会自带Rsync,为了方便使用,建议先卸载掉

rpm -qa |grep "rsync" 查看是否带有rpm安装的rsync

rpm -e rsync-x.x.x 如果有就卸载掉

2)下载安装Rsync最新稳定版

wget http://rsync.samba.org/ftp/rsync/rsync-3.0.7.tar.gz

tar zxvf rsync-3.0.7.tar.gz

cd rsync-3.0.7

./configure --prefix=/usr/local/rsync

make

make install

说明一点,客户机和服务器都要安装rsync。客户机以客户端方式运行rsync,服务器端以服务器方式运行rsync,它监听873端口。

3) 设定 /etc/xinetd.d/rsync, 如下:

# default: off

# description: The rsync server is a good addition to am 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

}

然后执行chkconfig rsync on 使上述设定生效.

主要是要打开 rsync 這个 daemon, 一旦有 rsync client 要连接时, xinetd 会把它转介給 rsyncd (跑 port 873).

4)服务器端手动设置配置文件/etc/rsyncd.conf

vi /etc/rsyncd.conf

插入以下内容,如果之后调试遇到错误,建议把注释都去掉,以免造成不必要的错误

view plaincopy to clipboardprint?

uid = root

gid = root

use chroot = no

max connections = 4

strict modes =yes

port = 873

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

[www] # 这里是认证的模块名,在client端需要指定

path = /data0/htdocs/www/ # 需要做镜像的目录

comment = This is a test

ignore errors

read only = yes

list = no

# 认证的用户名,如果没有这行,则表明是匿名

auth users = tony

secrets file = /etc/rsync.pas

hosts allow = 192.168.10.225,10.10.10.10

hosts deny = 0.0.0.0/0

#transfer logging = yes

uid = root

gid = root

use chroot = no

max connections = 4

strict modes =yes

port = 873

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

[www] # 这里是认证的模块名,在client端需要指定

path = /data0/htdocs/www/ # 需要做镜像的目录

comment = This is a test

ignore errors

read only = yes

list = no

# 认证的用户名,如果没有这行,则表明是匿名

auth users = tony

secrets file = /etc/rsync.pas

hosts allow = 192.168.10.225,10.10.10.10

hosts deny = 0.0.0.0/0

#transfer logging = yes

5)设置密码文件

在服务器端:

echo "tony:111111" >> /etc/rsync.pas 注意格式,以及用户名要与配置文件一致

安全起见,设置密码文件的拥有者为root,权限为只读

chown root:root rsync.pas

chmod 600 /etc/rsync.pas

在客户端:

echo "111111" >> /etc/rsync.pas 注意格式,以及密码要与服务器端一致

安全起见,设置密码文件的拥有者为root,权限为只读

chown root:root rsync.pas

chmod 600 /etc/rsync.pas

service xinetd restart,使配置生效,如果没有xinetd,需求再安装一下 yum install xinetd

6)客户端服务器都启动rsync

/usr/local/bin/rsync --daemon

或者xinetd进程启动 /etc/rc.d/init.d/xinetd reload

可以把该启动命令加入/etc/rc.local

在服务器端验证启动是否成功:

netstat -na|grep 873

7)打开iptables防火墙:

vi /etc/sysconfig/iptables

加入-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT

service iptables restart

8)从客户端进行测试:

从服务器端取文件

/usr/local/rsync/bin/rsync -vzrtopg --progress --delete tony@192.168.10.220::www /data0/htdocs/www --password-file=/etc/rsync.pas

向SERVER端上传文件

/usr/local/rsync/bin/rsync -vzrtopg --progress --password-file=/root/rsync.pas /data0/htdocs/www tony@192.168.10.220::www

9)如果有比较复杂的工作,利用一些常见的脚本语言可以有帮助。比如:

vi /usr/local/bin/rsync.sh

#!/bin/sh

DATE=`date +%w`

/usr/local/rsync/bin/rsync -vzrtopg --progress --delete tony@192.168.10.220::www /data0/htdocs/www --password-file=/etc/rsync.pas >

/var/log/rsync.$DATE

修改/etc/crontab做好定时

比如:

echo “15 4 * * 6 root rsync.sh”>>/etc/crontab

10)测试过程可能遇到的问题:

安装好rsync后,执行/usr/local/rsync/bin/rsync --daemon启动rsync时报错:

rsync: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory

解决办法:在/etc/ld.so.conf中加一行/usr/local/lib,运行ldconfig。再运行/usr/local/rsync/bin/rsync --daemon,就可以了。报错的原因可能之前更新过iconv库.

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ydt619/archive/2010/11/09/5997606.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: