最近一个朋友让我帮忙搭建匿名的rsync服务器。

具体要求是:
匿名rsync,此段是废话可以略过。
分析:
这个问题看起来简单其实也不简单。我们经常用到的rsync命令是依托于ssh传输的,这个肯定需要两个前提一个是开放22端口和需要输入密码。当然我们可以使用公钥认证方式,但是这就不符合要求了。所以只能在rsync服务上考虑。之前只知道rsync服务时开放是873端口,总以为是多余的。现在终于明白了,哎,我真无知啊!
 具体是实现过程:

     1.开启rsync服务

      打开rsync服务很简单,修改 vim /etc/xinetd.d/rsync 将disable 改为 no
    
 
    
  1. service rsync 
  2.         disable = no 
  3.         socket_type     = stream 
  4.         wait            = no 
  5.         user            = root 
  6.         server          = /usr/bin/rsync 
  7.         server_args     = --daemon 
  8.         log_on_failure  += USERID 
   重新启动服务xinetd,命令为:service xinetd restart
    检查是否开启:
         netstat -pant 查看一下是否有873端口开放,如下:
   Proto Recv-Q  Send-Q Local Address     Foreign Address       State       PID/Program name   
       tcp        0             0 0.0.0.0:873                        0.0.0.0:*               LISTEN      10510/xinetd  

2.编写配置--rsyncd.conf

      1.有些版本的rsync并没有生成rsyncd.conf,那么就要自己手动生成。放在/etc下面就是了。
       2.编写rsyncd.conf,其实我就是照抄人家的例子,如何去查看范例,如下:
          
 
    
  1. # rpm -ql rsync 
  2. /etc/xinetd.d/rsync 
  3. /usr/bin/rsync 
  4. /usr/share/doc/rsync-2.6.8 
  5. /usr/share/doc/rsync-2.6.8/COPYING 
  6. /usr/share/doc/rsync-2.6.8/README 
  7. /usr/share/doc/rsync-2.6.8/tech_report.tex 
  8. /usr/share/man/man1/rsync.1.gz 
  9. /usr/share/man/man5/rsyncd.conf.5.gz 
  10. # man /usr/share/man/man5/rsyncd.conf.5.gz 
用此方打开帮助文档后,最后面有范例,如下:
 
    
  1. EXAMPLES 
  2.   A simple rsyncd.conf file that allow anonymous rsync to a ftp area at /home/ftp would be: 
  3.  
  4.        [ftp]  #这个同步的时候用到的模块
  5.                path = /home/ftp  # 同步时放入的位置
  6.                comment = ftp export area  #提示,这个好像作用不到吧
  7.  
  8.        A more sophisticated example would be: 
  9.  
  10.        uid = nobody  #这个很重要!之前没弄出啦就是卡在这个地方了。系统如果没有这个用户
  11.        gid = nobody  #就可能不允许匿名登录。使用useradd -r nobody 进行增加(系统用户)
  12.        use chroot = no  #使用chroot,建议2.6.9以下版本都要打开。这是一个安全漏洞
  13.        max connections = 4  #连接数量
  14.        syslog facility = local5  #生成日志
  15.        pid file = /var/run/rsyncd.pid #rsync运行时的PID
  16.  
  17.        [ftp] 
  18.                path = /var/ftp/pub 
  19.                comment = whole ftp area (approx 6.1 GB) 
  20.  
  21.        [sambaftp] 
  22.                path = /var/ftp/pub/samba 
  23.                comment = Samba ftp area (approx 300 MB) 
  24.  
  25.        [rsyncftp] 
  26.                path = /var/ftp/pub/rsync 
  27.                comment = rsync ftp area (approx 6 MB) 
  28.  
  29.        [sambawww] 
  30.                path = /public_html/samba 
  31.                comment = Samba WWW pages (approx 240 MB) 
  32.  
  33.        [cvs] 
  34.                path = /data/cvs 
  35.                comment = CVS repository (requires authentication) 
  36.                auth users = tridge, susan 
  37.                secrets file = /etc/rsyncd.secrets #如果使用密码文件时。
  38.  
  39.        The /etc/rsyncd.secrets file would look something like this: 
  40.  
  41.               tridge:mypass  #那个密码文件的格式
  42.               susan:herpass 

格外还要加上几个参数:

timeout = 600 #客户端要及时的断开,不然其他客户端无法连接上来。

refuse options = c delete #不允许客户端进行任何删除或者删除目录更新文件(这个有时很有用!)

3.同步过程。

很多时候,我就盲从网上给的方法。我不能说不对,但是我根据网上的说明都没弄出来!
客户端几乎不用配置。一个命令搞定:

rsync -Pav <要同步的文件> <rsync服务器IP>::<模块名称,按上面来就是FTP>

这样就OK了。


问题:

1.不能传输。请看客户端的报错信息。

1.大部分这样的信息都是集中与权限的问题。我们要把服务器端的ftp指定的/home/ftp/这个文件夹设置为777,这样很危险,因此我们一定要设置use chroot选项。

2.可能服务器上就没有nobody这个用户,不能匿名传输。
2.还是需要密码。

1.检查一下命令是否正确?主要看后面的 不要指定用户名可能也会出现错误。
2.是不是ssh进行传输了?

3.传输过来的文件属性问题。

1.匿名上传的文件属主和属主都是nobody。

2.尽量不要人工干预备份,如果要手动建立文件夹的话 必须修改属主属组都为nobod

4.生成日志格式。

1.默认格式 "%o %h [%a] %m (%u) %f %l", and a "%t [%p] "

 
    
  1. o      %a the remote IP address 
  2. o      %b the number of bytes actually transferred 
  3. o      %B the permission bits of the file (e.g. rwxrwxrwt) 
  4. o      %c the checksum bytes received for this file (only when sending) 
  5. o      %f the filename (long form on sender; no trailing "/"
  6. o      %G the gid of the file (decimalor "DEFAULT" 
  7. o      %h the remote host name 
  8. o      %i an itemized list of what is being updated 
  9. o      %l the length of the file in bytes 
  10. o      %L the string " -> SYMLINK"" => HARDLINK"or "" (where SYMLINK or HARDLINK is a filename) 
  11. o      %m the module name 
  12. o      %M the last-modified time of the file 
  13. o      %n the filename (short form; trailing "/" on dir) 
  14. o      %o the operation, which is "send""recv"or "del." (the latter includes the trailing period) 
  15. o      %p the process ID of this rsync session 
  16. o      %P the module path 
  17. o      %t the current date time 
  18. o      %u the authenticated username or an empty string 
  19. o      %U the uid of the file (decimal
2.不生成日志? rsync服务如果已经启动,重启xinetd服务并不能生成日志。需要你重启rsync进程。