介绍

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

  常用场景一

无密码同步

1、安装rsync

[root@localhost /]# yum -y install rsync

2、新建rsyncd.conf文件

vim /etc/rsyncd.conf

#This is the rsync daemon configuration 

#global settings
pid file = /var/run/rsyncd.pid
port = 873
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 = 15
read only = yes
write only = no
list = no
ignore errors = yes
timeout = 120
保存

3、执行命令

/usr/bin/rsync --daemon
mkdir -p /web/rsync/share_data #新建共享目录,实例中直接输入要共享文件的就好,可省去次步

客户端

1、安装rsync

[root@localhost /]# yum -y install rsync

2、输入命令进行同步

rsync -avz root@192.168.1.98:/var/space /home/hadoop/share_data
↓ ↓ ↓
服务器IP 配置文件共享目录名 客户端收纳目录

3、限制流量同步

限制流量同步:
rsync -avz --bwlimit=50 --progress root@192.168.1.98::share_data /home/hadoop/share_data

  常用场景二

有密码同步

服务端配置

1、配置文件修改

vim /etc/rsyncd.conf

#This is the rsync daemon configuration 

#global settings
pid file = /var/run/rsyncd.pid
port = 873
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 = 15
read only = yes
write only = no
list = no
ignore errors = yes
timeout = 120
auth users = hadoop
secrets file = /etc/rsyncd.passwd

3、执行命令

echo "hadoop:password123" > /etc/rsyncd.passwd
chmod 600 /etc/rsyncd.passwd
mkdir -p /web/rsync/auth_data

客户端配置

1、保存密码

echo "password123" > /home/hadoop/rsyncd.passwd
chmod 600 /home/hadoop/rsyncd.passwd

2、远程同步

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

  常用场景三

写入同步

服务端

1、配置文件

vim /etc/rsyncd.conf

#global settings
pid file = /var/run/rsyncd.pid
port = 873
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 = 15
read only = no
list = no
ignore errors = yes
timeout = 120
auth users = hadoop
secrets file = /etc/rsyncd.passwd 保存

2、执行命令

mkdir -p /web/rsync/write_data

客户端

1、输入同步命令

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或网段

服务端

1、配置文件修改

#global settings
pid file = /var/run/rsyncd.pid
port = 873
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 = 15
read only = no
list = no
ignore errors = yes
timeout = 120
auth users = hadoop
secrets file = /etc/rsyncd.passwd
hosts allow = 192.168.2.32 192.168.1.0/24

常见情景例子

指定端口

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

限速

rsync --bwlimit=100 -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 

本文参考:ggjucheng

更多命令参考

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

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

Rsync 实现远程同步的更多相关文章

  1. 通过在shell脚本中用scp或rsync实现远程同步文件

    通过在shell脚本中用expect实现远程scp文件  shell expect的简单用法 http://myunix.blog.51cto.com/191254/1095074 http://ji ...

  2. Rsync(远程同步): linux中Rsync命令的实际示例

    rsync的 ( 远程同步 )为在Linux / Unix系统局部 拷贝和同步文件和目录远程以及一个最常用的命令. 随着rsync命令的帮助,您可以复制并在目录中远程和本地同步数据,在磁盘和网络,进行 ...

  3. Rsync数据远程同步备份

    rsync的使用方法 一.设置Rsync Server端 Rsync server需要设定四个方面: 1.规划建立备份目录区 2.设定: /etc/xinetd.d/rsync 3.设定: /etc/ ...

  4. Linux 远程同步:rsync

    rsync 简介: (1) rsync 是一个远程数据同步工具,可通过 LAN/WAN 快速同步多台主机间的文件(2) rsync 使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步 ...

  5. rsync远程同步

    一.概念 Rsync是一个开源的快速备份工具,可以在不同主机之间镜像同步整个目录树,支持增量备份,保持连接和权限,且采用优化的同步算法,传输前执行压缩,因此非常适用于异地备份,镜像服务器等应用.rsy ...

  6. rsync 远程同步 实时同步备份 两种免交互的方式实现实时备份

    rsync 远程同步: 一款快速增量备份工具 Remote Sync,远程同步 支持本地复制,或者与其他SSH.rsync主机同步 作用:做数据备份 备份方式:      完全备份      增量备份 ...

  7. rsync远程同步的基本配置与使用

    rsync是一个开源的快速备份工具,可以在不同主机之间镜像同步整个目录树,支持增量备份,保持链接和权限,且采用优化的同步算法,传输前执行压缩,因此非常适用于异地备份,镜像服务器等应用. rsync的官 ...

  8. linux下ssh远程登录/scp远程复制文件/rsync远程同步命令的自动登录

    最近需要写一个脚本备份各个服务器上的程序到一个指定服务器上,本来以为查查rsync命令的使用321就能搞定,结果rsync命令要支持自动登 录还是要配置服务和参数,又不确定网上说的配置的行不行,因为都 ...

  9. linux 远程同步数据工具rsync (1)

    rsync 远程同步数据工具,是linux下的数据备份工具rsync(remote sync 远程同步) 特点:在本地同步数据(类似于cp,但是有不同于远程scp),它会先判断已经存在的数据和远程数据 ...

随机推荐

  1. mybatis 动态curd

    xml <select id="selectByCondition" parameterType="com.oracle.pojo.Student" re ...

  2. 全卷积神经网络FCN理解

    论文地址:https://people.eecs.berkeley.edu/~jonlong/long_shelhamer_fcn.pdf 这篇论文使用全卷积神经网络来做语义上的图像分割,开创了这一领 ...

  3. Hadoop提供的reduce函数中Iterable 接口只能遍历一次的问题

    今天在写MapReduce中的reduce函数时,碰到个问题,特此记录一下: void reduce(key, Iterable<*>values,...) { for(* v:value ...

  4. yum lock

    状态 :睡眠中,进程ID:18439Another app is currently holding the yum lock; waiting for it to exit... 另一个应用程序是: ...

  5. NEU 1683: H-Index

    题目描述 Given an array of citations (each citation is a non-negative integer) of a researcher, write a ...

  6. Delphi通过POST传递参数给PHP

    Delphi代码 ******************************************************************************************* ...

  7. xunit输出output到控制台

    1.https://xunit.github.io/docs/capturing-output 里面似乎提到2个方法,第二个方法还需要在配置文件中添加appSetting 这里采用第一种方法, 1.添 ...

  8. 目前最新版本ActiveMQ 5.15.3 和JDK版本有关的问题

    java.lang.UnsupportedClassVersionError: org/apache/activemq/ActiveMQConnectionFactory : Unsupported ...

  9. ios蓝牙开发(四)BabyBluetooth蓝牙库介绍

    BabyBluetooth 是一个最简单易用的蓝牙库,基于CoreBluetooth的封装,并兼容ios和mac osx. 特色: 基于原生CoreBluetooth框架封装的轻量级的开源库,可以帮你 ...

  10. POJ - 2142 The Balance(扩展欧几里得求解不定方程)

    d.用2种砝码,质量分别为a和b,称出质量为d的物品.求所用的砝码总数量最小(x+y最小),并且总质量最小(ax+by最小). s.扩展欧几里得求解不定方程. 设ax+by=d. 题意说不定方程一定有 ...