Linux下架设rsync服务器


In: 网络服务 | Author: easylife | 115 views

9 2010

  本文主要以Linuxsir.Org上[rsync 服务器架设方法 v0.1b]为蓝本修订而成,在原文的基础上参考其它文章后加入了更多的细节描述。由于时间匆忙,可能会出现笔误的地方。如各位有发现文档错误的地方请留言告知以,以便即时修改!顺带提一下在整理完这个文档后,我认为在两台服务器做文件备份或者传输rsync是个不错的选择。这么说的原因是因为记得前段时间QQ群上某网友说ftp后台上传后更加好一些,也没有做过很大数据量的测试,有比较过的网友请留言告知!

  一、什么是rsync

  rsync,remote synchronize顾名思意就知道它是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限、时间、软硬链接等附加信息。rsync是用 “rsync 算法”提供了一个客户机和远程文件服务器的文件同步的快速方法,而且可以通过ssh方式来传输文件,这样其保密性也非常好,另外它还是免费的软件。

  rsync 包括如下的一些特性:

  能更新整个目录和树和文件系统;
  有选择性的保持符号链链、硬链接、文件属于、权限、设备以及时间等;
  对于安装来说,无任何特殊权限要求;
  对于多个文件来说,内部流水线减少文件等待的延时;
  能用rsh、ssh 或直接端口做为传输入端口;
  支持匿名rsync 同步文件,是理想的镜像工具;

  二、架设rsync服务器

  架设rsync 服务器比较简单,写一个配置文件rsyncd.conf 。文件的书写也是有规则的,我们可以参照rsync.samba.org 上的文档来做。当然我们首先要安装好rsync这个软件才行;

  A、rsync的安装;

  获取rsync

  rysnc的官方网站:http://rsync.samba.org/可以从上面得到最新的版本。目前最新版是3.05。当然,因为rsync是一款如此有用的软件,所以很多Linux的发行版本都将它收录在内了。

  软件包安装

  # sudo apt-get  install  rsync  注:在debian、ubuntu 等在线安装方法;
  # yum install rsync    注:Fedora、Redhat 等在线安装方法;
  # rpm -ivh rsync       注:Fedora、Redhat 等rpm包安装方法;

  其它Linux发行版,请用相应的软件包管理方法来安装。

  源码包安装

  tar xvf  rsync-xxx.tar.gz
  cd rsync-xxx
  ./configure –prefix=/usr  ;make ;make install   注:在用源码包编译安装之前,您得安装gcc等编译开具才行;
    
  B、配置文件

  rsync的主要有以下三个配置文件rsyncd.conf(主配置文件)、rsyncd.secrets(密码文件)、rsyncd.motd(rysnc服务器信息)

  服务器配置文件(/etc/rsyncd.conf),该文件默认不存在,请创建它。

  具体步骤如下:

  #touch /etc/rsyncd.conf  #创建rsyncd.conf,这是rsync服务器的配置文件。
  #touch /etc/rsyncd.secrets  #创建rsyncd.secrets ,这是用户密码文件。
  #chmod 600 /etc/rsyncd/rsyncd.secrets  #将rsyncd.secrets这个密码文件的文件属性设为root拥有, 且权限要设为600, 否则无法备份成功!
  #touch /etc/rsyncd.motd

  下一就是我们修改rsyncd.conf和rsyncd.secrets和rsyncd.motd文件的时候了。

  设定/etc/rsyncd.conf

  rsyncd.conf是rsync服务器主要配置文件。我们先来个简单的示例,后面在详细说明各项作用。

  比如我们要备份服务器上的/home和/opt,在/home中我想把easylife和samba目录排除在外;

  # Distributed under the terms of the GNU General Public License v2
  # 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 = 192.168.1.171 
  #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 deny=*

  max connections = 5
  motd file = /etc/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

  [rhel4home]  
  path = /home   
  list=yes
  ignore errors
  auth users = root
  secrets file = /etc/rsyncd.secrets 
  comment = This is RHEL 4 data 
  exclude = easylife/  samba/     

  [rhel4opt]
  path = /opt
  list=no
  ignore errors
  comment = This is RHEL 4 opt
  auth users = easylife
  secrets file = /etc/rsyncd/rsyncd.secrets

  注:关于auth users是必须在服务器上存在的真实的系统用户,如果你想用多个用户以,号隔开,比如auth users = easylife,root

页面: 1 2 3 4 5

Comment Form

About this blog

这是一个Linux/Unix技术交流群成员交流知识、分享技巧的群交流平台。如果你有好的资料愿意分享,但暂时不是本群成员,可以点击顶部导航Add Group按钮进行入群测试。欢迎你的加入!

Photostream

    理解Linux的处理器负载均值

    Unix和Unix-like的发展历史

  • Vincent: 这个问题我也遇到了,很久都没解决,编译了N多次,感谢啊~~~(内牛满面) [...]
  • 天空之城: 恩,是这样的。iptables的问题遇到过吗?我在头疼这个问题。 [...]
  • ky: 楼上的太恶劣了。。。 [...]
  • fh.cn: ....再板凳 [...]
  • fh.cn: 呵呵、板凳 [...]
  • yoyojacky: well done! Mike, it’s unbeliveable! wish this site a fabulous 2010… [...]
  • init4: 这个问题我也遇到过 [...]
  • 19466846: 这个问题在debian的bug report中已经有过讨论: Upgrading kernel to 2.6.25.9, the LVM utilities could not find any Volume Groups. This is due to the new /sys/block layout and the LVM sysf [...]

无觅相关文章插件,快速提升流量