介绍

rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件。rsync使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而不是每次都整份传送,因此速度相当快。 rsync是一个功能非常强大的工具,其命令也有很多功能特色选项,我们下面就对它的选项一一进行分析说明。

常用场景

无密码同步

服务端:vim /etc/rsyncd.conf

#This is the rsync daemon configuration 

#global settings
pid file = /var/run/rsyncd.pid
port =
lock file = /var/run/rsyncd.lock
log file = /var/log/rsync.log
gid = root
uid = root #module settings
[share_data]
path = /web/rsync/share_data
use chroot = no
max connections =
read only = yes
write only = no
list = no
ignore errors = yes
timeout =
/usr/bin/rsync --daemon
mkdir -p /web/rsync/share_data

客户端

rsync -avz --progress root@192.168.1.98::share_data /home/hadoop/share_data

限制流量同步

rsync -avz --bwlimit= --progress root@192.168.1.98::share_data /home/hadoop/share_data

有密码同步

服务端

vim /etc/rsyncd.conf

#This is the rsync daemon configuration 

#global settings
pid file = /var/run/rsyncd.pid
port =
lock file = /var/run/rsyncd.lock
log file = /var/log/rsync.log
gid = root
uid = root #module settings
[auth_data]
path = /web/rsync/auth_data
use chroot = no
max connections =
read only = yes
write only = no
list = no
ignore errors = yes
timeout =
auth users = hadoop
secrets file = /etc/rsyncd.passwd
echo "hadoop:password123" > /etc/rsyncd.passwd
chmod /etc/rsyncd.passwd
mkdir -p /web/rsync/auth_data

客户端

echo "password123" > /home/hadoop/rsyncd.passwd
chmod /home/hadoop/rsyncd.passwd
rsync -avz --progress --password-file=/home/hadoop/rsyncd.passwd hadoop@192.168.1.98::auth_data /home/hadoop/auth_data

或者是

export RSYNC_PASSWORD="password123"
rsync -avz --progress hadoop@192.168.1.98::auth_data /home/hadoop/auth_data

写入同步

服务端

vim /etc/rsyncd.conf

#global settings
pid file = /var/run/rsyncd.pid
port =
lock file = /var/run/rsyncd.lock
log file = /var/log/rsync.log
gid = root
uid = root #module settings
[write_data]
path = /web/rsync/write_data
use chroot = no
max connections =
read only = no
list = no
ignore errors = yes
timeout =
auth users = hadoop
secrets file = /etc/rsyncd.passwd
mkdir -p /web/rsync/write_data

客户端

echo "" > /home/hadoop/write_file
export RSYNC_PASSWORD="password123"
rsync -avz --progress --delete /home/hadoop/write_file hadoop@192.168.1.98::write_data

限定IP或者网段

#global settings
pid file = /var/run/rsyncd.pid
port =
lock file = /var/run/rsyncd.lock
log file = /var/log/rsync.log
gid = root
uid = root #module settings
[write_data]
path = /web/rsync/write_data
use chroot = no
max connections =
read only = no
list = no
ignore errors = yes
timeout =
auth users = hadoop
secrets file = /etc/rsyncd.passwd
hosts allow = 192.168.2.32 192.168.1.0/

常见场景例子

指定端口

rsync -avz --port= --progress /home/hadoop/auth_data hadoop@192.168.1.98::auth_data 

限速

rsync --bwlimit= -avz --progress /home/hadoop/auth_data hadoop@192.168.1.98::auth_data 

限速100kb/s同步数据

Rsync通过SSH传输

rsync -e "ssh -p 22"  --progress /home/hadoop/auth_data hadoop@192.168.1.98::auth_data 

更多命令参考

客户端 https://download.samba.org/pub/rsync/rsync.html

服务端 https://download.samba.org/pub/rsync/rsyncd.conf.html

rsync命令详解的更多相关文章

  1. (转)Rsync命令详解

    Rsync命令详解 原文:http://blog.51cto.com/irow10/1826249 说明: Rsync是linux/Unix文件同步和传送工具.用于替代rcp的一个工具,rsync可以 ...

  2. rsync命令详解、rsync用ssh隧道方式同步

    ● rsync格式安装命令 yum install -y rsync与scp的区别:scp复制为完全覆盖,rsync为增量同步,只同步修改过的数据.rsync命令格式如下: rsync 选项 源文件 ...

  3. 第三章 rsync 命令详解和实战用法

    一.rsync传输模式 1.本地模式2.远程模式3.守护进程模式 二.守护进程模式 1.安装rsync[root@backup ~]# yum -y install rsync 2.配置rsync[r ...

  4. Linux rsync 命令详解

    服务器之间常常要保持些文件或目录的一致,比如一些大的软件下载网站,它们通常使用多台服务器来提供下载服务.当一台服务器上的文件更新后,其它的服务器 也需要更新,而且 在更新的时候应该是只对新增或是修改过 ...

  5. rsync指令详解

    rsync指令详解(更详细的看官方文档http://rsync.samba.org/ftp/rsync/rsync.html) [root@Centos epel]# rsync --help rsy ...

  6. bg,fg,job命令详解

    基础命令学习目录首页 原文链接:http://www.cnblogs.com/chjbbs/p/6307333.html linux提供的fg和bg命令,可以让我们轻松调度正在运行的任务 假如你发现前 ...

  7. scp命令详解—跨服务器复制文件

    scp在跨机器复制的时候为了提高数据的安全性,使用了ssh连接和加密方式,如果机器之间配置了ssh免密码登录,那在使用scp的时候密码都不用输入. 在服务器104.238.161.75上操作,将服务器 ...

  8. 【转】scp命令详解

    先说下常用的情况: 两台机器IP分别为:A.104.238.161.75,B.43.224.34.73. 在A服务器上操作,将B服务器上/home/lk/目录下所有的文件全部复制到本地的/root目录 ...

  9. rsync参数详解

    Rsync的参数详细解释 -v, --verbose 详细模式输出-q, --quiet 精简输出模式-c, --checksum 打开校验开关,强制对文件传输进行校验-a, --archive 归档 ...

随机推荐

  1. (转)如何处理iOS中照片的方向

    如何处理iOS中照片的方向 31 May 2015 • 7 min. read • Comments 使用过iPhone或者iPad的朋友在拍照时不知是否遇到过这样的问题,将设备中的照片导出到Wind ...

  2. JDK1.7 安装配置

    JDK1.7 安装配置 1.下载jdk1.7安装包,下载地址为http://pan.baidu.com/s/1bnvWc5x: 2.安装jdk1.7,安装完成后可在安装目录下看到以下两个文件夹,如下图 ...

  3. 安卓微信浏览器中location.href失效的问题

    在移动web中,经常会使用window.location.href去跳转页面,这个方法在绝大多数浏览器中都不会存在问题,但是在安卓手机的微信自带浏览器中,会出现一个奇怪的bug. window.loc ...

  4. Repeater 根据某一列的值加颜色

    //排队中 protected void rptOrdersList_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterIt ...

  5. Linux LVM硬盘管理及LVM扩容

    LVM磁盘管理 一.LVM简介... 1 二. LVM基本术语... 2 三. 安装LVM... 3 四. 创建和管理LVM... 4 2. 创建PV.. 6 3. 创建VG.. 7 4. 创建LV. ...

  6. pthread_cond_wait()函数的理解(摘录)

    /************pthread_cond_wait()的使用方法**********/pthread_mutex_lock(&qlock);    /*lock*/pthread_c ...

  7. Linux下得到毫秒级时间--C语言实现(转-度娘818)

    Linux下得到毫秒级时间--C语言实现 原文链接: http://www.cnblogs.com/nwf5d/archive/2011/06/03/2071247.html #ifdef HAVE_ ...

  8. final评价Ⅱ

    1.飞天小女警: 礼物挑选这个项目相比之前的发布功能更完善了些,但是整体界面还是不太美观,用户界面上呈现出的选项字不够清晰,使用起来不是很方便,但是增加了猜你喜欢的功能,可以根据用户的浏览记录猜测用户 ...

  9. 王爽< 汇编语言>实验十二

    ;此乃安装程序 ;功能:将8086cpu中断类型码为0 的中断向量设置为我们编写的中断服务程序入口地址 ;该中断在除法发送溢出的时候产生 assume cs:code code segment mai ...

  10. LeetCode-Search a 2D Matrix

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...