一.rsync服务器:
1.安装rsync
yum install rsync
2.配置rsyncd
vim /etc/rsyncd.conf
uid = apache
gid = apache
max connections = 5
use chroot = no
log file = /var/log/rsyncd.log
pid file= /var/run/rsyncd.pid
[test]
path=/root/test
read only = false
auth users = haodou
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.1.0/255.255.255.0
[yongfu]
path=/data/www/yongfu
read only = false
auth users = yongfu
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.1.0/255.255.255.0
vim /etc/rsyncd.secrets
yongfu:thepasswd
3.启动rsyncd服务
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf
二.rsync客户端
1.安装rsync
yum install rsync
2.连接rsync服务器
rsync -ave ssh root@192.168.1.33:/home/ftp/pub/ /home/ftp/pub/
上例中把源路径中的远程机器192.168.1.33上/home/ftp/pub/目录中的内容,通过rsync同步到本地的/home/ftp/pub/目录下。
三.参考资料
命令格式:
rsync [option] 源路径 目标路径
其中:
[option]:
a:使用文档 模式,等于-rlptgoD,即保持原有的文件权限
z:表示传输时压缩数据
v:显示到屏幕中
e:使用远程shell程序(可以使用rsh或ssh)
--delete:精确保存副本,源主机删除的文件,目标主机也会同步删除
--include=PATTERN:不排除符合PATTERN的文件或目录
--exclude=PATTERN:排除所有符合PATTERN的文件或目录
--password-file:指定用于rsync服务器的用户验证密码
源路径和目标路径可以使用如下格式:
rsync://[USER@]Host[:Port]/Path <--rsync服务器路径
[USER@]Host::Path <--rsync服务器的另一种表示形式
[USER@]Host:Path <--远程路径
LocalPath <--本地路径
※需要注意的是,来源或目的路径最少要有一个是本地路径,如果忽略本地路径,则只会列出远端的文件列表。
参考地址:http://www.linuxfly.org/post/13/
评论