介绍

  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. Java 兔子问题(斐波那契数列)扩展篇

    Java兔子问题(斐波那契数列)扩展篇 斐波那契数列指的是这样一个数列 0, 1, 1, 2,3, 5, 8, 13, 21, 34, 55, 89, 144, ...对于这个数列仅仅能说将兔子生产周 ...

  2. 【dotnet跨平台】"dotnet restore"和"dotnet run"都做了些什么?

    [dotnet跨平台]"dotnet restore"和"dotnet run"都做了些什么? 前言: 关于dotnet跨平台的相关内容.能够參考:跨平台.NE ...

  3. Redis实现分布式锁(Set和Lua)

    转载:https://www.cnblogs.com/linjiqin/p/8003838.html 前言 分布式锁一般有三种实现方式:1. 数据库乐观锁:2. 基于Redis的分布式锁:3. 基于Z ...

  4. appium安装报错但运行成功

    npm install -g  appium ERR! fetch failed https://registry.npmjs.org/appium-uiauto/-/appium-uiauto-1. ...

  5. 多媒体开发之---h264快速运动估计算法

    #include "stdio.h"#include "stdlib.h"#include "malloc.h"#include " ...

  6. spark0.9.1集群模式执行graphx測试程序(LiveJournalPageRank,新增Connected Components)

    spark最新版公布了.之前的版本号就已经集成了graphx,这个版本号还改了一些bug. 我做了简单測试,只是网上关于集群模式执行spark资料太少了,仅仅有关于EC2(见參考资料1)的.可是还非常 ...

  7. SpringMVC实战(注解)

    1.前言 前面几篇介绍了SpringMVC中的控制器以及视图之间的映射方式,这篇来解说一下SpringMVC中的注解,通过注解能够非常方便的訪问到控制器中的某个方法. 2.配置文件配置 2.1 注解驱 ...

  8. 获取IOS应用安装列表

    原文转载至 http://blog.csdn.net/justinjing0612/article/details/8887747 转自鸟哥博客:http://blog.cnrainbird.com/ ...

  9. Memory cycles about Block

    Block keeps a strong point to all object referenced in side of them, so all object will stay in heap ...

  10. YTU 1439: 2.4.5 Fractions to Decimals 分数化小数

    1439: 2.4.5 Fractions to Decimals 分数化小数 时间限制: 1 Sec  内存限制: 64 MB 提交: 194  解决: 13 题目描述 写一个程序,输入一个形如N/ ...