安装方式一:
下载
#wget http://rsync.samba.org/ftp/rsync/rsync-2.6.9.tar.gz
安装,客户端和服务器端都需要安装
#tar zxf rsync-2.6.9.tar.gz
#cd rsync-2.6.9
#./configure --prefix=/usr/local/rsync/
#make && make install
#make clean
安装方式二:
也可以采用yum方式安装rsync
查看是否已安装
[root@localhost ~]# rpm -qa|grep rsync
rsync-3.0.6-4.el5_7.1
未安装则执行:
#yum -y install rsync*
修改rsync的配置文件,disable = yes 改为 no
# vim /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
}
改完重启xinetd ,再查看rsync端口有没有开启
# service xinetd restart
# netstat -an|grep 873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN
端口在监听中,说明rsync 启动了
配置:
环境介绍
server端172.31.0.7,AS4
client端172.31.0.12,AS4
配置server端
#vi /etc/rsyncd.conf #文件名必须是rsyncd.conf,默认rsync执行的时候在/etc/下查找rsyncd.conf(可自行创建)
uid = nobody
gid = nobody
use chroot = no
max connections = 4 #最大连接数为4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log #日志记录文件
secrets file = /etc/rsyncd.secrets #存放密码的文件
read only = yes #只读
ignore errors #忽略IO错误
hosts allow = 172.31.0.0/16 #允许部分主机访问
hosts deny = 192.168.1.0/24 #禁止这些主机访问
[test] #实例名,同步的时候就需要指定实例名
path = /home/saman/ #需要同步的目录
comment = BACKUP TEST #类似描述信息
list = no #不允许list文件目录
auth users = saman #认证的用户名
#vi /etc/rsyncd.secrets
saman:123456 #指定用户saman的密码为123456
#chmod 600 /etc/rsyncd.secrets #为了安全,密码文件的属性只能是所有者可读
#/usr/local/rsync/bin/rsync --daemon #以daemon方式运行rsync
客户端不需要特殊配置,同步的时候执行
#/usr/local/rsync/bin/rsync -vaz --delete saman@172.31.0.7::test /data/backupall/saman/test/
参数详细提示
a 以archive模式操作,复制目录、符号连接,相当于参数-rlptgoD
z 传输的时候进行压缩
--delete如果服务器端删除了文件,客户端也删除相应的文件,保持真正的同步
saman@172.31.0.7中的saman即认证的用户名
::test中的test即server端指定的实例名
/data/backupall/saman/test/即客户端被同步的文件夹
执行后会提示输入密码,输入/etc/rsyncd.secrets指定的密码即可,也可以创建一个包含密码的文件,用--password-file=file来指定密码文件
#vi /data/saman/rsync.pass
123456
#chmod 600 /data/saman/rsync.pass #为了安全,密码文件的属性只能是所有者可读
#/usr/local/rsync/bin/rsync -vaz --delete --password-file=/data/saman/rsync.pass saman@172.31.0.7::test /data/backupall/saman/test/
实例
server 10.0.0.3
[logbak]
path=/var/log/logbak
comment=nagios plugins
ignore errors = yes
uid=nagios
gid=nagios
list = yes
read only = no
hosts allow=60.101.101.101
hosts deny=*
auth users=backup
secrets file = /etc/rsyncd.secrets
[root@wholesale-dress ~]# cat /etc/rsyncd.secrets
backup:backup
client
rsync -avzp --delete backup@10.0.0.3::logbak /usr/local/hexin/data/logbak