inotify+rsync实现实时同步

rsync数据同步+inotify实时同步 rsync数据同步+inotify实时同步 一.rsync 1.rsync概述 rsync(remote sync)远程同步; rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。已支持跨平台,可以在Windows与Linux间进行数据同步。 rsync监听端口:873 rsync运行模式:C/S 2.rsync优缺点 优点: 1,可以镜像保存整个目录树和文件系统。 2,可以做到保持原来文件的权限、时间 阅读详情

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

  1. 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化
  2. 发现目录中数据产生变化,就利用rsync服务推送到备份服务器上

1.2 实现实时同步的方法

   inotify+rsync 方式实现数据同步

   sersync 方式实现实时数据同步 详情参照:http://www.cnblogs.com/clsn/p/7707828.html

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.3 【官方说明】三个重要文件1.4.2 【服务优化】可以将三个文件的数值调大,监听更大的范围

[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

5、移动事件 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:clsn123" >>/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 "clsn123" >>/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 +a d  :退出当前的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

提示信息:

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

  本文出自“惨绿少年”,欢迎转载,转载请注明出处!http://blog.znix.top

我的博客即将同步至腾讯云+社区,邀请大家一同入驻。

rsync远程同步+inotify实时同步部署 Rsync(Remote Sync)是一个功能丰富、快速和灵活的文件复制和同步工具。它以增量复制的方式工作,能够仅复制源和目标之间发生变化的文件或部分文件,从而减少了数据传输的时间和网络带宽的消耗。Rsync 使用一个特殊的算法来识别文件的差异,并仅传输发生变化的部分,以实现高效的文件同步和备份。它还支持多种模式和选项,使其非常适应各种不同的应用场景。① rsync是一款开源的、快速的、多功能的、可实现全量及增量的本地或远程数据同步备份的优秀工具。 阅读详情

相关推荐

Rsync远程同步+inotify监控

rsync(Remote Sync,远程同步) 是一个开源的快速备份工具,可以在不同主机之间镜像同步整个目录树,支持增量备份,并保持链接和权限,且采用优化的同步算法,传输前执行压缩,因此非常适用于异地备份、镜像服务器等应用。在远程同步任务中,负责发起rsync同步操作的客户机称为发起端,而负责响应来自客户机的rsync同步操作的服务器称为同步源。在同步过程中,同步源负责提供文件的原始位置,发起端应对该位置具有读取权限。

pangdongqiqi的博客 1477

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

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

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

通过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/

zhanjianshinian的专栏 1468

rsync+inotify远程同步

在系统管理员的工作中备份无疑是一个重要的部分。当没有完整备份或者良好规划的备份和实施时,就可能或早或晚不可挽回地丢失重要的数据。rsync 无疑是一个很好的选择,下面将介绍rsync的工作过程。rsync(Remote Sync,远程同步)是一款开源的快速增量备份工具,可以在不同主机之间镜像同步整个目录树,支持增量备份,并保持链接和权限,且采用优化的同步算法,传输前执行压缩,因此非常适用于异地备份、镜像服务器等应用。rsync软件支持跨平台,适用于unix/ linux/windows等多种操作系统平台rs

WuDan_1112的博客 1737

rsync + inotify 实现文件实时双向自动同步(1)

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

2501_90245776的博客 778

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

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的博客 9749

【车辆仿真】从0开始建立dSPACE RT Simulink工程:输出模拟电平

0基础建议先看下前面的博文,补充基础知识。原来的博文太长太复杂,后续我会逐步梳理改进,去除操作层面的内容,仅关注知识层面,提升系列博文的系统性。【工程环境信息】:上位机:惠普台式PC(Windows 11专业版)下位机(实时机):SCALEXIO RTPC板卡:DS2680。

winnizap的博客 2055

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

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

qiao2458的博客 1602

告别CMake依赖!在Visual Studio 2022中直接配置VTK 9.4开发环境(附完整项目示例)

本文详细介绍了如何在Visual Studio 2022中直接配置VTK 9.4开发环境,无需依赖CMake。通过图文教程和完整项目示例,帮助C++开发者快速集成VTK库,简化开发流程,提升工作效率。特别适合科学可视化任务的开发者。

weixin_26804345的博客 416

OpenCLI入门:让任何网站变成你的命令行工具(超详细版)

最有用的工具,往往是最简单的。 opencli就是这样。 它不会帮你写代码,不会帮你做决策,但它能把200+个平台装进你的命令行。 让你用最简单的方式,获取最丰富的数据。

weixin_66295112的博客 2095

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

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

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

使用TensorFlow搭建FNN(全连接神经网络)的基本步骤

提示:转载请注明出处,若本文无意侵犯到您的合法权益,请及时与作者联系。 目录 一、定义神经网络的输入输出 二、搭建神经网络 1、定义一个神经层中的权重 2、定义一个神经层中的阈值 3、定义一个神经层中的激活函数 4、组合神经层为神经网络 三、搭建损失函数和优化器 1、搭建损失函数 首先介绍第一个函数这其中用到的共同的函数为 2、定义优化器 四、训练神经网络 全连接神经网络的网络结构如下: 一、定义神经网络的输入输出 神经网络最擅长的工作就是模拟非线性函数,即一个复杂的高..

qq_41959920的博客 4073

rsync+inotify 实现数据实时同步

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

m0_54563444的博客 1558

【麒麟桌面系统】企业微信提示当前副设备的企业微信版本较低

银河麒麟系统中登录企业微信时出现"副设备版本较低"的报错,可通过两种方案解决:1)更新最新版企业微信,需替换软件源并刷新软件商店安装8.0-50-4.1.26.6019kylin5版本;2)安装内测5.0版本企业微信,需下载deb包后使用sudo dpkg命令安装。文章还提供了常见问题解决表和长期维护建议,包括系统更新检查、软件源验证等维护项目及具体操作指南。

信创运维工程师 · 银河麒麟 & 容器实战 | 金融生产环境迁移·等保加固 | 142篇原创·17万+阅读 2280

【python基础】一文掌握 Jupyter Notebook 的使用(超级详细!)

是一个非营利组织,致力于为多种编程语言的交互式计算开发开源软件、开放标准和服务。Jupyter 于 2014 年由 Fernando Pérez 从IPython衍生出来,支持几十种编程语言的执行环境。Jupyter 项目主要开发并支持(.ipynb 文件格式)、JupyterHub和JupyterLab等交互式计算产品。

数据知道的博客 1万+

rsync+inotify实现远程实时同步

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

RAB 1795

Python 爬虫实战:爬取评论数据做情感分析

摘要:本文介绍基于Python的京东商品评论爬取与情感分析全流程实现。通过Requests库抓取评论数据接口,结合JSON解析获取结构化评论信息。利用SnowNLP进行中文文本情感分析,量化用户评价的情感倾向(正面/负面/中性)。结果显示正面评论占比66.3%,负面评论13.3%,关键词分析发现"卡顿""发热"是主要负面因素。该方法可应用于产品优化、品牌管理等场景,为决策提供数据支持。

2503_91057718的博客 1709

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

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

handsomestWei的博客 1871

【Simulink教程案例19】基于simulink的扩频通信系统建模与仿真

扩频是一种应用于数字调制信号的调制技术,可以提高传输信号的带宽。扩频通信具有抗干扰能力强,扩频增益越大,抗干扰能力越强。而且扩频通信具有很强的保密性,扩频后信号近似白噪声,功率谱密度也很低。扩频通信可用于多址通信。扩频调制有如下三个特点:① 扩频后信号的带宽远大于信号所需的带宽② 使用扩频码进行扩频调制,扩频码与信号中的数据相互独立③ 在接收端,通过将接收信号与扩频码的同步副本进行相关,实现解扩。

FPGA/MATLAB学习教程/源码/项目合作开发 2197

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

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

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

不屈的铝合金的博客 1110

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

如何实现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

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

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的博客 3760

rsync + inotify实现文件实时同步

rsync + inotify实现文件实时同步 服务端主机: 192.68219.132 客户端主机:192.168.219.140 端口:873 部署用户:root 或者 非root用户配有sudo权限用户 rsync 服务端部署及配置 创建同步用户:rsync [root@node132 ~]# useradd rsync [root@node132 ~]# passwd rsync 输入两次密码 创建备份目录 mkdir /data/rsync chown rsync:rsync /data/r

M:Yang 265
上一篇: 博客园博文爬虫案例效果
下一篇: inotify+rsync实现实时同步
惨绿少年
博客等级 码龄10年 173粉丝 236原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值