inotify+rsync实现实时同步

通过rsync+inotify实现文件的实时备份同步 原文参考:http://ixdba.blog.51cto.com/2895551/580280/ http://www.bamaol.com/Psy/Showposts-010000108-5048.html 一,rsync安装 目前rsync的最新版本是3.0.9 wget http://rsync.samba.org/ftp/rsync/ 阅读详情

第1章 数据实时同步介绍

1.1 什么是实时同步:如何实现实时同步

A. 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化

B. 发现目录中数据产生变化,就利用rsync服务推送到备份服务器上

1.2 实现实时同步的方法

 inotify+rsync 方式实现数据同步

 sersync 方式实现实时数据同步

1.2.1 实时同步原理介绍

1.3 inotify+rsync 方式实现数据同步

1.3.1 Inotify简介

Inotify是一种强大的,细粒度的。异步的文件系统事件监控机制,linux内核从2.6.13起,加入了 Inotify支持,通过Inotify可以监控文件系统中添加、删除,修改、移动等各种事件,利用这个内核接口,第三方软件就可以监控文件系统下文件的各种变化情况,而 inotify-tools 正是实施这样监控的软件。国人周洋在金山公司也开发了类似的实时同步软件sersync。

提示信息:

sersync软件实际上就是在 inotify软件基础上进行开发的,功能要更加强大些 ,多了定时重传机制,过滤机制了提供接口做 CDN,支持多线程橾作。

Inotify实际是一种事件驱动机制,它为应用程序监控文件系统事件提供了实时响应事件的机制,而无须通过诸如cron等的轮询机制来获取事件。cron等机制不仅无法做到实时性,而且消耗大量系统资源。相比之下,inotify基于事件驱动,可以做到对事件处理的实时响应,也没有轮询造成的系统资源消耗,是非常自然的事件通知接口,也与自然世界事件机制相符合。

inotify的实现有几款软件:

inotify-tools,sersync,lrsyncd

1.3.2 inotify+rsync使用方式

inotify 对同步数据目录信息的监控

rsync  完成对数据信息的实时同步

利用脚本进行结合

1.4 部署inotify软件的前提

需要2.6.13以后内核版本才能支持inotify软件。2.6.13内核之后版本,在没有安装inotify软件之前,应该有这三个文件。

[root@backup ~]# ll /proc/sys/fs/inotify/
total 0
-rw-r--r-- 1 root root 0 Oct 17 10:12 max_queued_events
-rw-r--r-- 1 root root 0 Oct 17 10:12 max_user_instances
-rw-r--r-- 1 root root 0 Oct 17 10:12 max_user_watches

1.4.1 三个重要文件的说明

文件

默认值

作用说明

max_user_watches

8192

设置inotifywait或inotifywatch命令可以监视的文件数量(单进程)

max_user_instances

128

设置每个用户可以运行的inotifywait或inotifywatch命令的进程数

max_queued_events

16384

设置inotify实例事件(event)队列可容纳的事件数量

1.4.2 【服务优化】可以将三个文件的数值调大,监听更大的范围

1.4.3 【官方说明】三个重要文件

[root@nfs01 ~]# man proc
/proc/sys/fs/inotify (since Linux 2.6.13)
       This   directory   contains    files    max_queued_events,
       max_user_instances, and max_user_watches, that can be used
       to limit the amount of kernel memory consumed by the  inotify interface. 
for further details, see inotify(7).

通过man手册的第7级别中查到 inotify的默认文件的详细说明。

[root@nfs01 ~]# man 7 inotify
/proc/sys/fs/inotify/max_queued_events
       The  value  in this file is used when an application calls
       inotify_init(2) to set an upper limit  on  the  number  of
       events  that  can  be  queued to the corresponding inotify
       instance.  Events in excess of this limit are dropped, but
       an IN_Q_OVERFLOW event is always generated.
 
/proc/sys/fs/inotify/max_user_instances
       This  specifies  an  upper  limit on the number of inotify
       instances that can be created per real user ID.
 
/proc/sys/fs/inotify/max_user_watches
       This specifies an upper limit on  the  number  of  watches
       that can be created per real user ID.

1.5 inotify软件介绍及参数说明

1.5.1 两种安装方式

1) yum install -y inotify-tools

2) 手工编译安装

注:    YUM 安装需要有epel源

http://mirrors.aliyun.com

手工编译安装方式需要到github上进行下载软件包

    inotify软件的参考资料链接:

https://github.com/rvoicilas/inotify-tools/wiki

1.5.2 inotify主要安装的两个软件

inotifywait: (主要)

 在被监控的文件或目录上等待特定文件系统事件(open close delete等)发生,执行后处于阻塞状态,适合在shell脚本中使用

inotifywatch:

收集被监控的文件系统使用的统计数据,指文件系统事件发生的次数统计。

说明:在实时实时同步的时候,主要是利用inotifywait对目录进行监控

1.5.3 inotifywait命令参数说明

参数

含义

-m, --monitor

(重要参数)

Keep listening for events forever.  Without this option, inotifywait will exit after one event is received.

始终保持事件监听。

-d, --daemon

111

-r, --recursive

(重要参数)

Watch all subdirectories of any directories passed as arguments.

递归监控目录数据信息变化

-o, --outfile <file>

Print events to <file> rather than stdout.

打印事件到文件中,相当于标准正确输出

-s, --syslog

Output errors to syslog(3) system log module rather than stderr.

发送错误到syslog相当于标准错误输出

-q, --quiet

(重要参数)

If specified once, the program will be less verbose.  Specifically, it will not state  when  it  has  completed establishing all inotify watches.

输出信息少(只打印事件信息)

--exclude <pattern>

Exclude all events on files matching the extended regular expression <pattern>.

排除文件或目录

--excludei <pattern>

Like --exclude but case insensitive.

排除文件或目录时,不区分大小写

--timefmt <fmt>

(重要参数)

Print using a specified printf-like format string; read the man page for more details.

指定时间输出格式

--format <fmt>

(重要参数)

Print using a specified printf-like formatstring; read the man page for more details.

打印使用指定的输出类似格式字符串;即实际监控输出内容

-e

(重要参数)

Listen for specific event(s).  If omitted, all events are listened for.

指定监听指定的事件,如果省略,表示所有事件都进行监听

以上的信息可以通过 inotifywait --help  获得

1.5.4 -e[参数]  可以指定的事件类型

事件名称

事件说明

access

file or directory contents were read

文件或目录内容被读取

modify

file or directory contents were writterv

文件或目录内容被写入

attrib

file or directory attributes changed

文件或目录属性改变

close_write

(重要参数)

file or directory closed, after being opened in writeable mode.

文件或目录关闭,在写入模式打开之后关闭的。

close_nowrite

file or directory closed, after being opened in read-only mode.

文件或目录关闭,在只读模式打开之后关闭的

close

file or directory closed, regardless of read/write mode

文件或目录关闭,不管读或是写模式

open

file or directory opened

文件或目录被打开

moved_to

拉

file or directory moved to watched directory

文件或目录被移动到监控的目录中

moved_from

推

file or directory moved from watched directory

文件或目录被移动从监控的目录中

move

(重要参数)

file or directory moved to or from watched directory

文件或目录不管移动到或是移出监控目录都触发事件

create

(重要参数)

file or directory created within watched directory

文件或目录创建在监控目录中

delete

(重要参数)

file or directory deleted within watched directory

文件或目录被删除在监控目录中

delete_self

file or directory was deleted

文件或目录被删除,目录本身被删除

unmount

file system containing file or directory unmounted

以上的信息可以通过 inotifywait --help  获得

1.5.4.1 【实例】inotifywait监控中的事件测试

1、创建事件

[root@nfs01 data]# touch test2.txt
[root@nfs01 ~]# inotifywait -mrq  /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e create
17-10-17 11:19 /data/test2.txt 事件信息: CREATE

2、删除事件

[root@nfs01 data]# \rm -f test1.txt
[root@nfs01 ~]# inotifywait -mrq  /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e delete
17-10-17 11:28 /data/test1.txt 事件信息: DELETE

3、修改事件

[root@nfs01 data]# echo "132" > test.txt
[root@nfs01 ~]# inotifywait -mrq  /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e close_write
17-10-17 11:30 /data/test.txt 事件信息: CLOSE_WRITE,CLOSE

4、移动事件 moved_to

[root@nfs01 data]# mv /etc/hosts .
[root@nfs01 ~]# inotifywait -mrq  /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e moved_to
17-10-17 11:33 /data/hosts 事件信息: MOVED_TO

移动事件 moved_from

[root@nfs01 data]# mv ./hosts  /tmp/
[root@nfs01 ~]# inotifywait -mrq  /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e moved_from
17-10-17 11:34 /data/hosts 事件信息: MOVED_FROM

1.5.5 inotifywait 参数 --format <fmt>格式定义参数

命令参数

参数说明

%w(重要参数)

事件出现时,监控文件或目录的名称信息

%f(重要参数)

事件出现时,将显示监控目录下触发事件的文件或目录信息,否则为空

%e(重要参数)

显示发生的事件信息,不同的事件信息用逗号进行分隔

%Xe

显示发生的事件信息,不同的事件信息有x进行分隔,可以修改X为指定分隔符

%T(重要参数)

输出时间格式中定义的时间格式信息,通过 --timefmt option 语法格式指定时间信息

这个格式是通过strftime函数进行匹配时间格式信息的

以上的信息可以通过 inotifywait --help  获得

1.5.6 inotifywait 参数--timefmt <fmt>时间格式参数

命令参数

参数说明

%d(重要参数)

The day of the month as a decimal number(range 01 to 31)

每月的第几天,显示倍息为十进制数(范围是 01-31 )

%m(重要参数)

The month as a decimal number (range 01 to 12).

显示月份,显示信息为十进制(范围 01-12 )

%M

The minute as a decimal number (range 00 to 59).

显示分钟,显示信息为十进制(范围 00-59 )

%y(重要参数)

The year as a decimal number without a century (range 00 to 99).

年份信息,显示信息为十进制,并且没有世纪信息

%Y

The year as a decimal number including the century.

年份信息,显示信息为十进制,并且包含世纪信息

%H

The hour as a decimal number using a 24-hour clock (range 00 to 23).

小时信息,显示信息为十进制,使用 24小时制(范围 00-23 )

说明:以上信息可以通过 man strftime信息获取

1.5.6.1 修改输出的日期格式
[root@nfs01 ~]# inotifywait -mrq  /data --timefmt "%d/%m/%y %H:%M" --format "%T %w%f"
17/10/17 11:12 /data/test1.txt

1.5.7 -e[参数] 重要监控事件参数汇总表:

重要事件

包含事件

备注说明

close

close_write  

close_nowrite

文件或目录关闭,不管读或是写模式

即包含写关闭与读关闭

close_write

create

包含文件创建事件,但不包含目录创建事件

move

moved_to  

moved_from

文件或目录不管移动到或是移动出监控目录都触发事件

即包含信息移入或移出监控目录事件

重要参数汇总:根据以上说明,在实际使用时,只要监控以下事件即可

create 创建、 delete 删除、 movedjto 移入、 close_write 修 改

inotifywait -mrq /data --format "%w%f"  -e create,delete,moved_to,close_write

1.6 对inotifywait命令的测试

对inotifywait命令测试的说明:

   需要打开两个连接窗口

1窗口运行inotifywait

2窗口对文件夹进行操作,可在一窗口中查看出inotifywait的监控记录

1.6.1 、创建文件的逻辑↓

[root@nfs01 ~]# inotifywait /data
Setting up watches.
Watches established.
/data/ CREATE test1.txt
/data/ OPEN test1.txt
/data/ ATTRIB test1.txt
/data/ CLOSE_WRITE,CLOSE test1.txt
创建文件,inotifywait显示创建文件的过程↑
[root@nfs01 data]# touch test1.txt

1.6.2 创建目录逻辑↓

[root@nfs01 data]# mkdir testdir
[root@nfs01 ~]#
/data/ CREATE,ISDIR testdir

1.6.3 监控子目录下的文件↓

[root@nfs01 data]# touch  testdir/test01.txt
[root@nfs01 ~]# inotifywait -mrq  /data
/data/testdir/ OPEN test01.txt
/data/testdir/ ATTRIB test01.txt
/data/testdir/ CLOSE_WRITE,CLOSE test01.txt

1.6.4 sed命令修改逻辑

[root@nfs01 data]# sed 's#132#123#g' test.txt -i
 
[root@nfs01 ~]# inotifywait -mrq  /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e moved_from
 /data/test.txt 事件信息: OPEN
 /data/sedDh5R8v 事件信息: CREATE
 /data/sedDh5R8v 事件信息: OPEN
 /data/test.txt 事件信息: ACCESS
 /data/sedDh5R8v 事件信息: MODIFY
 /data/sedDh5R8v 事件信息: ATTRIB
 /data/sedDh5R8v 事件信息: ATTRIB
 /data/test.txt 事件信息: CLOSE_NOWRITE,CLOSE
 /data/sedDh5R8v 事件信息: CLOSE_WRITE,CLOSE
 /data/sedDh5R8v 事件信息: MOVED_FROM
 /data/test.txt 事件信息: MOVED_TO

sed命令替换逻辑 :

01. 创建临时文件

02. 将原文件内容放置到临时文件中,修改替换临时文件中的内容,原有文件不做改动

03. 重命名临时文件,覆盖原文件

1.6.5 inotifywait监控中 -e 的参数使用

inotifywait -mrq /data --timefmt "%d/%m/%y %H:%M" --format "%T %w%f 事件信息: %e" -e create

    说明:表示只监听create事件

inotifywait -mrq /data --timefmt "%d/%m/%y %H:%M" --format "%T %w%f 事件信息: %e"

    说明:不指定-e参数,表示监听所有事件

02. 删除事件delete

    # inotifywait -mrq /data --timefmt "%F %H:%M" --format "%T %w%f 事件信息: %@e" -e delete
    2017-10-17 11:28 /data/02.txt 事件信息: DELETE
    2017-10-17 11:28 /data/03.txt 事件信息: DELETE
    2017-10-17 11:28 /data/04.txt 事件信息: DELETE

    03. 修改事件close_write

  # inotifywait -mrq /data --timefmt "%F %H:%M" --format "%T %w%f 事件信息: %@e" -e delete,close_write
    2017-10-17 11:30 /data/oldgirl.txt 事件信息: CLOSE_WRITE@CLOSE
    2017-10-17 11:30 /data/.oldgirl.txt.swx 事件信息: CLOSE_WRITE@CLOSE
    2017-10-17 11:30 /data/.oldgirl.txt.swx 事件信息: DELETE
    2017-10-17 11:30 /data/.oldgirl.txt.swp 事件信息: CLOSE_WRITE@CLOSE
    2017-10-17 11:30 /data/.oldgirl.txt.swp 事件信息: DELETE
    2017-10-17 11:30 /data/.oldgirl.txt.swp 事件信息: CLOSE_WRITE@CLOSE
    2017-10-17 11:30 /data/.oldgirl.txt.swp 事件信息: DELETE

    04. 移动事件moved_to

    inotifywait -mrq /data --timefmt "%F %H:%M" --format "%T %w%f 事件信息: %@e" -e delete,close_write,moved_to
    2017-10-17 11:34 /data/hosts 事件信息: MOVED_TO

1.7 实时同步命令参数示意图

第2章 inotify+rsync实时同步服务部署

2.1 第一个里程碑:部署rsync服务

2.1.1 rsync服务端部署

1)软件是否存在

[root@backup ~]# rpm -qa |grep rsync
rsync-3.0.6-12.el6.x86_64

需求:查询到某个命令非常有用。但是不知道属于哪个软件包

    yum provides rysnc 

    provides   Find what package provides the given value

2)进行软件服务配置

[root@backup ~]# vim /etc/rsyncd.conf
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password

[backup]
comment = "backup dir by oldboy"
path = /backup

[nfsbackup]
comment = "nfsbackup dir by hzs"
path = /nfsbackup

3)创建rsync管理用户

[root@backup ~]# useradd -s /sbin/nologin -M rsync

4)创建数据备份储存目录,目录修改属主

[root@backup ~]# mkdir /nfsbackup/
[root@backup ~]# chown -R rsync.rsync /nfsbackup/

5)创建认证用户密码文件并进行授权600

echo "rsync_backup:oldboy123" >>/etc/rsync.password
chmod 600 /etc/rsync.password

6)启动rsync服务

rsync --daemon

至此服务端配置完成

[root@backup ~]# ps -ef |grep rsync
root       2076      1  0 17:05 ?        00:00:00 rsync --daemon
root       2163   1817  0 17:38 pts/1    00:00:00 grep --color=auto rsync

2.1.2 rsync客户端配置

1)软件是否存在

[root@backup ~]# rpm -qa |grep rsync
rsync-3.0.6-12.el6.x86_64

2)创建安全认证文件,并进行修改权限600

echo "oldboy123" >>/etc/rsync.password
chmod 600 /etc/rsync.password

3) 测试数据传输

[root@nfs01 sersync]# rsync -avz /data  rsync_backup@172.16.1.41::nfsbackup  --password-file=/etc/rsync.password
sending incremental file list
data/
data/.hzs
data/.tar.gz
data/.txt

2.2 第二个里程碑:部署inotify服务

首先先确认是否有epel源用来安装inotify-tools软件

[root@nfs01 ~]# yum repolist
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id  repo name                                       status
base     CentOS-6 - Base - mirrors.aliyun.com             6,706
epel     Extra Packages for Enterprise Linux 6 - x86_64  12,401
extras   CentOS-6 - Extras - mirrors.aliyun.com              46
updates  CentOS-6 - Updates - mirrors.aliyun.com            722
repolist: 19,875

2.2.1 安装inotify软件

两种安装方式

1) yum install -y inotify-tools

2) 手工编译安装

注:

手工编译安装方式需要到github上进行下载软件包

    inotify软件的参考资料链接:

https://github.com/rvoicilas/inotify-tools/wiki

2.2.2 查看inotify安装上的两个命令(inotifywait,inotifywatch)

[root@nfs01 ~]# rpm -ql inotify-tools
/usr/bin/inotifywait      #主要
/usr/bin/inotifywatch
2.2.2.1 inotifywait和inotifywatch的作用:
一共安装了2个工具(命令),即inotifywait和inotifywatch
inotifywait : 在被监控的文件或目录上等待特定文件系统事件(open close delete等)发生,
执行后处于阻塞状态,适合在shell脚本中使用
inotifywatch :收集被监控的文件系统使用的统计数据,指文件系统事件发生的次数统计。
说明:yum安装后可以直接使用,如果编译安装需要进入到相应软件目录的bin目录下使用
 
#命令 man手册说明
# man inotifywait
inotifywait - wait for changes to files using inotify

使用inotify进行监控,等待产生变化的文件信息
# man inotifywatch
inotifywatch - gather filesystem access statistics using inotify
使用inotify进行监控,收集文件系统访问统计佶息

2.3 第三个里程碑:编写脚本,实现rsync+inotify软件功能结合

2.3.1 rsync服务命令:

rsync -avz --delete /data/ rsync_backup@172.16.1.41::nfsbackup --password-file=/etc/rsync.password

2.3.2 inotify服务命令:

inotifywait -mrq /data -format "%w%f"  -e create,delete,move_to,close_write

2.3.3 编写脚本:

[root@nfs01 sersync]# vim /server/scripts/inotify.sh
#!/bin/bash
inotifywait -mrq /data --format "%w%f" -e create,delete,moved_to,close_write|\
while read line
do
        rsync -az --delete /data/ rsync_backup@172.16.1.41::nfsbackup --password-
file=/etc/rsync.password
done

脚本说明:

for循环会定义一个条件,当条件不满足时停止循环

while循环:只要条件满足就一直循环下去

2.3.4 对脚本进行优化

#!/bin/bash
Path=/data
backup_Server=172.16.1.41
/usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data  | while read line  
do
    if [ -f $line ];then
        rsync -az $line --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password
    else
        cd $Path &&\
        rsync -az ./ --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password
    fi
done

2.4 第四个里程碑:测试编写的脚本

2.4.1 让脚本在后台运行

在/data 目录先创建6个文件

[root@nfs01 data]# sh  /server/scripts/inotify.sh &
[root@nfs01 data]# touch {1..6}.txt

在backup服务器上,已经时候同步过去了6个文件。

[root@backup ~]# ll /nfsbackup/
total 8
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 1.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 2.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 3.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 4.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 5.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 6.txt

2.5 利用while循环语句编写的脚本停止方法(kill)

01. ctrl+z暂停程序运行,kill -9杀死
02. 不要暂停程序,直接利用杀手三剑客进行杀进程

 说明:kill三个杀手不是万能的,在进程暂停时,无法杀死;kill -9 (危险)

2.5.1 查看后台都要哪些程序在运行

[root@nfs01 data]# jobs
[1]+  Running                 sh /server/scripts/inotify.sh &

2.5.2 fg将后台的程序调到前台来

[root@nfs01 data]# fg 1
sh /server/scripts/inotify.sh

2.6 进程的前台和后台运行方法:

    fg    -- 前台

    bg    -- 后台

2.6.1 脚本后台运行方法

    01. sh inotify.sh &
    02. nohup sh inotify.sh &
    03. screen实现脚本程序后台运行

sh /server/scripts/inotify.sh &

nohup

nohup sh inotify.sh &

2.7 screen实现脚本程序后台运行

2.7.1 经过yum查找发现screen命令属于screen包

[root@test ~]# yum provides screen
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                      | 3.7 kB     00:00    
epel                                                      | 4.3 kB     00:00    
extras                                                    | 3.4 kB     00:00    
updates                                                   | 3.4 kB     00:00    
screen-4.0.3-19.el6.x86_64 : A screen manager that supports multiple logins on
                           : one terminal
Repo        : base
Matched from:

2.7.2 安装screen软件

[root@test ~]# yum install -y  screen

2.7.3 screen命令的参数

在shell中输入 screen即可进入screen 视图

[root@test ~]# screen

Screen实现后台运行程序的简单步骤:

  screen -ls :可看screen会话

  screen -r ID :指定进入哪个screen会话

Screen命令中用到的快捷键

  Ctrl+a c :创建窗口

  Ctrl+a w :窗口列表

  Ctrl+a n :下一个窗口

  Ctrl+a p :上一个窗口

  Ctrl+a 0-9 :在第0个窗口和第9个窗口之间切换

  Ctrl+a K(大写) :关闭当前窗口,并且切换到下一个窗口 ,

(当退出最后一个窗口时,该终端自动终止,并且退回到原始shell状态)

  exit :关闭当前窗口,并且切换到下一个窗口

(当退出最后一个窗口时,该终端自动终止,并且退回到原始shell状态)

  Ctrl+a d :退出当前终端,返回加载screen前的shell命令状态

  Ctrl+a " : 窗口列表不同于w

2.8 sersync软件实现实时同步

http://www.cnblogs.com/znix/p/7707828.html

rsync + inotify 实现文件实时双向自动同步(1) g :保持文件属组-o :保持文件属主-D :和–devices --specials一样,保持设备文件和特殊文件-z :发送数据前,先压缩再传输-H :保持硬链接-n :进行试运行,不作任何更改–partial :支持断点续传–progress :展示传输的进度–delete :如果源文件消失,目标文件也会被删除–delete-excluded :指定要在目的端删除的文件–delete-after :默认情况下,rsync是先清理目的端的文件再开始数据同步; 阅读详情

相关推荐

rsync+inotify实现实时单向同步

rsync+inotify实现实时单向同步 相关原理 1. Rsync man一下sync,就会发现:sync-flush file system buffers,它是一个把缓冲区中的数据同步到文件系统中的一个命令;而rsync其实就是remote rsync,它是一个远程同步工具,兼具cp和scp的功能,rsync命令的使用几乎和scp是一样一样的。Rsync是通过超级守护进程xinet

iie_libi的博客 1954

安装inotify-tools,用inotifywait命令监听文件或目录的访问信息

再使用Jnotify监控系统文件改名的过程中,高并发下会有遗漏,改用Inotify, 以下为使用方法 Inotify一种强大的、细粒度的、异步文件系统监控机制,它满足各种各样的文件监控需要,可以监控文件系统的访问属性、读写属性、权限属性、删除创建、移动等操作,也就是可以监控文件发生的一切变化。。 inotify-tools是一个C库和一组命令行的工作提供Linux下inotify的简单接口。i...

weixin_30566063的博客 482

Nuclei漏洞扫描:从零到精通的Windows实战指南

本文详细介绍了Nuclei漏洞扫描工具在Windows平台上的安装与使用教程,从基础安装到高级实战技巧全面覆盖。通过具体案例展示如何利用Nuclei的模板库快速检测常见漏洞,并提供自定义POC开发指南,帮助安全从业者高效开展漏洞扫描工作。

weixin_28683689的博客 250

CentOS 6.5上inotify-tools使用方法

Linux内核从2.6.13开始,引入了inotify机制。通过intofity机制,能够对文件系统的变化进行监控,如对文件进行创建、删除、修改等操作,可以及时通知应用程序进行相关事件的处理。这种响应处理机制,避免了频繁的文件轮询任务,提高了任务的处理效率。 一、检查系统内核版本 [root@iZ25w1kdi5zZ ~]# uname -a Linux iZ25w1kdi5zZ 2.6.

god_wot的专栏 1万+

华为鸿蒙系统也能用!5分钟搞定谷歌三件套安装(附最新APK下载链接)

本文为华为鸿蒙系统用户提供了一份详尽的谷歌三件套(Google Play服务、商店及框架)手动安装指南。文章核心在于无需Root,通过ADB命令获取设备信息,并从可靠来源下载匹配版本的APK,按照正确顺序安装,从而解决海外应用依赖问题,实现5分钟快速部署。

c7d8e9的博客 6499

帆软 finereport FCRA 考试 题库+答案,共收录561题,大部分有答案

帆软 finereport FCRA 考试 题库+答案,共收录561题,大部分有答案 入门基础 11.多选题 以下方式中属于FineReport中预览模式的有( ) 分页预览、填报预览、新填报预览、数据分析、移动端预览 16.判断题 FineReport报表工具必须购买激活码后才能使用。 错误,可以免费获取激活码。 29.单选题 FineReport是一款利用( )语言开发的报表工具。java 41.多选题 访问帮助文档的方式有哪些?设计器中社区菜单下-帮助文档;直接访问http://help.finere

qq_37485720的博客 2万+

Linux下inotify的基本使用及注意事项

最近在写一个云备份的项目,其中有一个模块是要监控计算机本地的文件,于是我翻了翻linux/unix系统编程手册发现了inotify这个用于文件监控的框架 1.概述 1)inotify机制可用于监控文件或目录。当监控目录时,与该目录自身以及该目录下面的文件都会被监控,其上有事件发生时都会通知给应用程序 2)inotify监控机制为非递归,若应用程序有意监控整个目录子树内的事件,则需对该树中的每

Shreck66的专栏 2万+

linux安装IBM Webshere MQ以及配置

一 、安装 登录root用户登录(必须使用root用户) 1.上传MQ安装包 命令:cd /tmp/ 上传本地MQ安装包到该目录下 2.解压安装包 命令:mkdir MQ 命令:cd MQ 命令:tar -zxvf WS_MQ_V8.0.0.9_LINUX_ON_X86_64_IM.tar.gz 3.执行接受许可脚本 命令:./mqlicense.sh -accept .........

weixin_37539417的博客 1万+

计算机视觉——SIFT特征匹配

文章目录一、SIFT特征检测原理1.1基本思想1.2二、SIFT特征检测图片兴趣点三、SIFT特征检测描述子匹配四、输入图片检测与之 一、SIFT特征检测原理 1.1基本思想 1.2 二、SIFT特征检测图片兴趣点 代码: 检测结果: 三、SIFT特征检测描述子匹配 四、输入图片检测与之 ...

weixin_43869874的博客 3855

MSP430项目设计:2020年TI杯大学生电子设计竞赛 坡道行驶电动小车(C题)循迹小车(分享项目展示视频与源码)

文章目录题目要求一、硬件设计二、理论分析与计算三、电路与程序设计四、测试方案与测试结果五、项目展示 哔哩哔哩项目展示视频:https://www.bilibili.com/video/BV1oz4y1d7mH/ 百度网盘资料链接:https://pan.baidu.com/s/1PC-lkSORH_XCgIG-u3HCog 提取码:c7zz 取走记得点赞啊! 题目要求 1.任务 利用TI的MSP430/MSP432平台,设计制作一个四轮电动小车。要求小车能沿着指定路线在坡道上自动循迹骑线行驶。小车必须独立

mbs706的博客 4万+

FTP文件定时自动传输

文件定时自动传输  新版CuteFTP内置计划任务表模块,能够按用户预先指定的日期和时间,自动拨号、上传文件并自动断线(总之就是“全自动”)。如果你也象我一样懒的话,这个功能就让你我享福啦。具体操作分两个方面:  一、进行自动拨号上网设定(局域网用户就免了,真正享福^_^)  1、在CuteFTP主窗口中,点击菜单“FTP/Settings/Options/Connection”。

sunxuns 4487

Allan方差这个工具,怎么把它用的更顺手?(附Allan方差、动态Allan方差代码)

本文详细说明了Allan方差和动态Allan方差的计算过程,并通过递归运算和时间序列选择两种算法提高动态Allan方差的计算效率。文末提供了快速动态Allan方差计算代码。

victoryqian528的博客 374

rsync+inotify实现文件的实时同步

一、rsync工具介绍 rsync(remote sync)即远程同步。rsync不仅可以远程同步数据(类似于scp),而且可以本地同步数据(类似于cp),但不同于cp或scp的是,它不会覆盖以前的数据,而是先判断已经存在的数据和新数据的差异,只有数据不同时才会把不相同的部分覆盖。 rsync安装:yum install -y rsync rsync的命令格式: rsync [选项] ... SRC DEST rsync [选项] ... SRC [ USER@ ]HOST:DEST rsync [选

Shallow的博客 9748

DA14531之搭建开发环境

DA14531之搭建开发环境

hejinwu1314的博客 1778

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

rsync结合inotify实现文件实时同步

1.创建配置文件2.创建密码文件,修改权限为6003.创建系统用户4.创建模块对应的目录,修改目录的属主属组为系统用户5.启动daemon模式sersync(也称为rsync inotify)是一个基于rsync和inotify的文件同步工具。它可以在文件发生更改时实时同步文件或目录。

qiao2458的博客 1602

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

数据实时同步:inotify + rsync 实现数据实时同步

在生产环境中,数据实时同步是确保不同节点间数据一致性的关键。数据同步主要有两种方式:PULL(周期性定时同步)和PUSH(数据更新后立即推送)。实时同步的实现方式包括inotify+rsync和sersync。 inotify+rsync通过内核的inotify监控指定目录,当文件或数据发生变化时,调用rsync服务将数据推送到远程主机。inotify是Linux内核的功能,用于通知用户空间程序文件系统的变化,如文件增加、修改、删除等。rsync则是一种常用的数据镜像备份工具,支持增量备份和远程同步。 se

https://ophome.blog.youkuaiyun.com,在IT行业有多年的工作经验,尤其是在Python、Linux、负载均衡、Nginx和服务器运维等领域。 1578

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

rsync+inotify 实现数据实时同步

性能方面:对于首次同步或文件较小的情况,scp可能会更快,因为它不需要进行额外的压缩或计算差异;但对于重复同步或文件较大的情况,rsync由于采用了增量同步机制,效率更高。安全性方面scp自动通过 SSH 提供加密传输,而rsync需要通过-e ssh参数来实现相同的安全级别。灵活性方面rsync提供了更多的配置选项,使其更加灵活,适用于更多复杂的同步场景。应用场景cp适用于简单的本地文件复制;scp适用于需要安全传输的场合;rsync。

m0_54563444的博客 1558

【Linux】企业实战项目rsync+inotify实现实时同步(inotify安装及介绍、rsync + inotify 实现实时同步、rsync + inotify实现开机自启 )

Inotify 监控文件系统操作,比如读取、写入和创建,基于事件驱动,可以做到对事件的实时响应,高效,而且没有轮询造成的系统资源消耗。

Linux小白一只~正处于学习阶段,觉得我写的还好的请多多给我点赞呀,谢谢大家!!(๑>ڡ<)☆ 2502

rsync+inotify实现远程实时同步

rsync + inotify 实现远程实时同步。

RAB 1794

使用rsync+inotify简单实现文件实时双机双向同步

rsync+inotify实现文件实时双机双向同步,整理了ssh和rsync-daemon两种传输方案

handsomestWei的博客 1870

Linux 实时同步服务实现(Rsync 结合 Inotify)

本文探讨了 Linux 实时同步服务,先介绍实时同步服务原理与常见数据备份方案,着重阐述 Inotify 机制工作流程。实践部分,详细展示 Inotify-tools 结合 Rsync 实现数据实时同步的步骤,包括服务部署确认、系统支持检查、工具安装、命令测试等。最后对比了 Sersync 与 inotify - tools 的优势,并介绍 Sersync 工具使用。

不屈的铝合金的博客 1110

如何实现rsync远程同步和inotify实时同步

目录一:rsync介绍1.1:rsync 服务的模式1.2:rsync服务原理1.3:配置rsync源思路二、搭建rsync服务2.1:建立rsync配置文件2.2:客户机服务器B测试三、rsync实时同步配置3.1:实时同步介绍3.2:配置rsync源服务器A4.4:客户机服务器B配置 一:rsync介绍 Remote Sync,远程同步,它是一个开源的快速增量备份工具,可以在不同主机之间镜像同步整个目录树。 支持增量备份、保持连接和权限,且采用优化的同步算法,传输前执行压缩,因此非常适用于异地备份、镜像

chenchen的博客 616

Linux CentOS 通过rsync+inotify实现文件实时同步

inotify是一种强大的、细粒度的、异步的文件系统事件监听机制,可以监听文件系统中添加、删除,修改、移动等各种细微事件,做到对事件的实时响应,高效并且没有轮询造成的系统资源消耗。

云计算课代表 1475

rsync+inotify 实现双向实时同步

安装rsync #yum install  -y xinetd#yum install -y rsync #vim /etc/xinetd.d/rsync 启动XINETD#service xinetd startStarting xinetd:                                           [  OK  ]#chkconfig xinetd on #nets...

qq_29871605的博客 3758
上一篇: FTP&samba 服务简单部署
下一篇: Zabbix 3.0 从入门到精通(zabbix使用详解)
惨绿少年
博客等级 码龄10年 173粉丝 236原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值