Chinaunix首页 | 论坛 | 博客
  • 博客访问: 284868
  • 博文数量: 84
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -10
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-05 09:11
文章分类
文章存档

2015年(1)

2014年(6)

2013年(8)

2012年(1)

2011年(6)

2010年(2)

2009年(16)

2008年(44)

我的朋友

分类: LINUX

2008-05-23 18:06:40

 
需要创建的目录和文件
mkdir /etc/rsyncd 注:在/etc目录下创建一个rsyncd的目录,我们用来存放rsyncd.conf 和rsyncd.secrets文件;
touch /etc/rsyncd/rsyncd.conf  注:创建rsyncd.conf ,这是rsync服务器的配置文件;
touch /etc/rsyncd/rsyncd.secrets  注:创建rsyncd.secrets ,这是用户密码文件;
chmod 600 /etc/rsyncd/rsyncd.secrets  注:为了密码的安全性,我们把权限设为600;
touch /etc/rsyncd/rsyncd.motd

rsyncd.secrets 权限必须是600
 
服务器:172.18.3.208 
简要说明:服务器上有两个模块linuxsirhome,beinan 两个用户linuxsir,beinan 两个需要通途同步的文件目录/home/wangzm/ /opt/wangzm/
密码文件rsyncd.secrets,格式如下
[root@localhost rsyncd]# cat rsyncd.secrets
linuxsir:222222
beinan:333333
 
 
 
配置文件
[root@localhost rsyncd]# cat rsyncd.conf
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid  
port = 873
address = 172.18.3.208 
#uid = nobody
#gid = nobody   
uid = root  
gid = root  
use chroot = yes 
read only = yes 

#limit access to private LANs
#hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 
hosts allow=172.18.3.0/255.255.255.0
hosts deny=*
max connections = 5
motd file = /etc/rsyncd/rsyncd.motd
#This will give you a separate log file
log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
[linuxsirhome]  
path = /home/wangzm/   
list=yes
ignore errors
auth users = linuxsir
secrets file = /etc/rsyncd/rsyncd.secrets 
comment = linuxsir home 
exclude =   beinan/  samba/     
[beinan]
path = /opt/wangzm/
list=yes
ignore errors
comment = optdir  
auth users = beinan
secrets file = /etc/rsyncd/rsyncd.secrets
 
 
启动服务 /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
 
端口信息
[root@localhost rsyncd]# netstat -antp|grep 873
tcp        0      0 172.18.3.208:873            0.0.0.0:*                   LISTEN      5049/rsync
 
 
客户机:172.18.3.205
 
客户端只需要安装rsync,不用启动服务,客户端用的命令
rsync  --list-only  ::
rsync  --list-only 
rsync -avzP   linuxsirhome
rsync -avzP  --delete
rsync -Hxva --delete --exclude=logs    linuxdir
 
删除客户断与服务器不同的文件但不包括logs
rsync -avzP --delete --exclude=logs    linuxdir
 
让rsync 客户端自动与服务器同步数据
 
放到cron里
 
rsync -avzP  --delete  --password-file=rsyncd.secrets     $(date +'%m-%d-%y')
 
该语句的解释同步服务器上的新数据,同时删除客户端上于服务器不符合的文件
 
 
 
 
如果服务器端不启动rsync
后面直接跟绝对路径:
rsync -Hxva --delete --exclude=logs     linuxdir
rsync -Hxva --delete --exclude=logs 172.18.3.208:/home/wangzm/    aaaa
 
 
在10.4.9.244上执行如下:
 
同步数据到10.4.9.233
rsync -Hxva --delete --exclude=*logs /home/wangzm/ 10.4.9.233:/home/wangzm/cc/

同步10.4.9.233的数据到本机
rsync -Hxva --delete --exclude=logs 10.4.9.233:/home/wangzm/cc/ /home/wangzm/
 
 ============================================================
192.168.8.133 服务器端
root@ubuntu:/home/wangzm/133# cat /etc/rsyncd/rsyncd.conf 
pid file = /var/run/rsyncd.pid   
port = 873
address = 192.168.8.133
uid = root   
gid = root  
use chroot = no 
read only = yes 


hosts allow=192.168.8.0/255.255.255.0 
hosts deny=*
max connections = 5 
motd file = /etc/rsyncd/rsyncd.motd
log file = /var/log/rsync.log
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
[linuaaa]   
path = /home/wangzm/133/    
list=yes 
ignore errors 
auth users = mingming
secrets file = /etc/rsyncd/rsyncd.secrets  
comment = linuxaaa home  
root@ubuntu:/home/wangzm/133# 

root@ubuntu:/home/wangzm/133# cat /etc/rsyncd/rsyncd.secrets 
mingming:123
----->注:不是系统用户

 /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
启动

客户端
root@ubuntu:/home/wangzm/test1# cat /home/wangzm/srync.pass
123
--》只写密码

===================================================================
在客户端同步服务器端的数据,连接到服务器的daemon上
 rsync -avzrtopg --progress mingming@192.168.8.133::linuaaa /home/wangzm/test1 --password-file=/home/wangzm/srync.pass 
或者
/usr/bin/rsync  -Hxva --delete mingming@192.168.8.133::linuaaa /home/wangzm/test1 --password-file=/home/wangzm/srync.pass
或者
rsync -avzrtopg --progress --password-file=/home/wangzm/srync.pass  rsync://mingming@192.168.8.133/linuaaa /home/wangzm/test1
或者
rsync -avzrtopg --progress --password-file=/home/wangzm/srync.pass  rsync://mingming@192.168.8.133:/linuaaa /home/wangzm/test1


rsync -avzrtopg --progress --password-file=/home/wangzm/srync.pass  rsync://mingming@192.168.8.133:/linuaaa /home/wangzm/test1/  #/test1/ 后不能有/,否则会出现文件格式错误








如果要连接到daemon上 此处必须是linuaaa,不能是/home/wangzm/123 绝对路径,用 rsync://开头,在ip后面直接加/模块名或者加:/模块名
如果不是以rsync://开头的,则需要加::模块名


增量备份要把--delete去掉,否则会同步备份


======================================================================================

如果不连接到rsync服务器daemon上 不能用配置文件里的用户,和密码,模块路径linuaaa 
1 rsync -avzrtopg --progress 192.168.8.133:/home/wangzm/133/ /home/wangzm/test1/ 
2 rsync   -Hxva  192.168.8.133:/home/wangzm/133/ /home/wangzm/test1/

跟绝对路径,后面必须有个:号
123后面如果不跟/则会把123目录同步过来,而不是123目录下的文件,如果不连接daemon,后面test1 可以加/ 也可以不加/ 不会产生文件格式错误


======================================================================
如果客户如果要连接对方的端口,在另一端必须配置成服务器端,就daemon形式,默认端口为873

rsync -avzrtopg --progress --password-file=/home/wangzm/rsyncd.secrets rsync://clbus@ip:端口/mybackup /home/wangzm/
rsync -avzrtopg --progress --password-file=/home/wangzm/rsy_sec rsync://mingming@192.168.8.133:873/linuaaa /home/wangzm/test1
如果在外网有防火墙,则需要在防火墙上把一个端口映射到服务器内部的873端口,例如8873--》873,这时客户端需要连接8873.

如果另一端不是daemon形式,则客户端不能加端口号,默认就去ssh 连接22端口

==================================
详细配置请见
 
 
 
 
 
 
 
 
 
 
 
 
阅读(1200) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~