Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >LINUX运维学习之综合架构篇——综合架构实时同步服务

LINUX运维学习之综合架构篇——综合架构实时同步服务

作者头像
云计算小黑
发布于 2021-06-16 03:24:19
发布于 2021-06-16 03:24:19
5240
举报
文章被收录于专栏:小黑博客小黑博客

1、实时同步服务原理/概念

1)需要部署好rsync守护进程服务,实现数据传输 2)需要部署好inotify服务,实现目录中数据变化监控 3)将rsync服务和inotify服务建立联系,将变化的数据进行实时备份传输

2、实时同步服务部署

1)部署rsync守护进程(之前已配置过:点击送达服务器端配置操作 客户端配置操作 2)配置inotify监控服务 a、安装软件(在备份服务器的客户端安装(我是在NFS服务器安装的,web服务器也可以))

代码语言:javascript
AI代码解释
复制
    yum install -y inotify-tools

b、熟悉命令的使用 我们先查看以下命令

代码语言:javascript
AI代码解释
复制
    rpm -ql inotify-tools
代码语言:javascript
AI代码解释
复制
    /usr/bin/inotifywait   #监控目录数据信息变化
    /usr/bin/inotifywatch  #对监控的变化信息进行统计

inotifywait命令使用

代码语言:javascript
AI代码解释
复制
    inotifywait 3.14
    Wait for a particular event on a file or set of files.
    Usage: inotifywait [ options ] file1 [ file2 ] [ file3 ] [ ... ]
    Options:
        -h|--help         Show this help text.
        @<file>           Exclude the specified file from being watched.
        --exclude <pattern>
                          Exclude all events on files matching the
                          extended regular expression <pattern>.
        --excludei <pattern>
                          Like --exclude but case insensitive.
        -m|--monitor      Keep listening for events forever.  Without
                          this option, inotifywait will exit after one
                          event is received.
        -d|--daemon       Same as --monitor, except run in the background
                          logging events to a file specified by --outfile.
                          Implies --syslog.
        -r|--recursive    Watch directories recursively.
        --fromfile <file>
                          Read files to watch from <file> or `-' for stdin.
        -o|--outfile <file>
                          Print events to <file> rather than stdout.
        -s|--syslog       Send errors to syslog rather than stderr.
        -q|--quiet        Print less (only print events).
        -qq               Print nothing (not even events).
        --format <fmt>    Print using a specified printf-like format
                          string; read the man page for more details.
        --timefmt <fmt>    strftime-compatible format string for use with
                          %T in --format string.
        -c|--csv          Print events in CSV format.
        -t|--timeout <seconds>
                          When listening for a single event, time out after
                          waiting for an event for <seconds> seconds.
                          If <seconds> is 0, inotifywait will never time out.
        -e|--event <event1> [ -e|--event <event2> ... ]
            Listen for specific event(s).  If omitted, all events are 
            listened for.
    
    Exit status:
        0  -  An event you asked to watch for was received.
        1  -  An event you did not ask to watch for was received
              (usually delete_self or unmount), or some error occurred.
        2  -  The --timeout option was given and no events occurred
              in the specified interval of time.
    
    Events:
        access        file or directory contents were read
        modify        file or directory contents were written
        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 [参数]  监控的目录
    -m|--monitor   --- 实现一直监控目录的数据变化
    -r|--recursive --- 进行递归监控
    -q|--quiet     --- 尽量减少信息的输出
    --format <fmt> --- 指定输出信息的格式 
    --timefmt      --- 指定输出的时间信息格式 
    -e|--event     --- 指定监控的事件信息

创建文件监控信息输出

代码语言:javascript
AI代码解释
复制
    /test/ CREATE user1    --- 一个文件被创建
    /test/ OPEN user1      --- 打开创建的文件
    /test/ ATTRIB user1    --- 修改文件的属性信息
    /test/ CLOSE_WRITE,CLOSE user1    --- 保存关闭一个文件

删除文件监控信息输出

修改文件监控信息输出

sed命令修改文件原理

代码语言:javascript
AI代码解释
复制
    /test/ OPEN user1                     打开文件
    /test/ CREATE sedioUSRr               创建一个临时文件(内存)
    /test/ OPEN sedioUSRr                 临时文件打开
    /test/ ACCESS user1                   读取源文件内容
    /test/ MODIFY sedioUSRr               修改临时文件
    /test/ ATTRIB sedioUSRr               临时文件属性变化
    /test/ CLOSE_NOWRITE,CLOSE user1      不编辑直接关闭源文件
    /test/ CLOSE_WRITE,CLOSE sedioUSRr    写入关闭临时文件
    /test/ MOVED_FROM sedioUSRr           将临时文件移除
    /test/ MOVED_TO user1                 移入一个新的user1源文件

inotify参数事件说明:

inotify监控命令格式:

代码语言:javascript
AI代码解释
复制
    inotifywait -mrq --timefmt "%F" --format "%T %w %f 事件信息:%e" /data -e CREATE

主要监控 create创建、delete删除、moved_to移入、close_write修改

企业应用:防止系统重要文件被破坏 需要用到inotify进行实时一直监控 /etc passwd /var/spool/cron/root

3、sersync同步服务

a、下载软件,保留上传到linux服务器中 sersync 或者下载我用的sersync 上传linux服务器 rz -y --- 选择需要上传的数据信息 PS:软件尽量都统一保存在/server/tools目录中 b、解压软件压缩包,将解压的数据进行保存

代码语言:javascript
AI代码解释
复制
    unzip sersync-master.zip

解压之后把sersync目录移动的 /usr/local/

代码语言:javascript
AI代码解释
复制
    mv sersync /usr/local/

c、编写配置文件:

代码语言:javascript
AI代码解释
复制
vim conf/confxml.xml
代码语言:javascript
AI代码解释
复制
    6     <filter start="false">
    7         <exclude expression="(.*)\.svn"></exclude>
    8         <exclude expression="(.*)\.gz"></exclude>
    9         <exclude expression="^info/*"></exclude>
    10         <exclude expression="^static/*"></exclude>
    11     </filter>
    说明:排除指定数据信息不要进行实时传输同步
    12     <inotify>
    13         <delete start="true"/>
    14         <createFolder start="true"/>
    15         <createFile start="false"/>
    16         <closeWrite start="true"/>
    17         <moveFrom start="true"/>
    18         <moveTo start="true"/>
    19         <attrib start="false"/>
    20         <modify start="false"/>
    21     </inotify>
    说明:定义inotify程序需要监控的事件
      
    24         <localpath watch="/opt/tongbu">
    25             <remote ip="127.0.0.1" name="tongbu1"/>
    26             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
    27             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
    28         </localpath>
    29         <rsync>
    30             <commonParams params="-artuz"/>
    31             <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
    32             <userDefinedPort start="false" port="874"/><!-- port=874 -->

修改24到32行内容

代码语言:javascript
AI代码解释
复制
     <localpath watch="/test">
     25             <remote ip="172.16.1.41" name="backup"/>
     26             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
     27             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
     28         </localpath>
     29         <rsync>
     30             <commonParams params="-az"/>
     31             <auth start="true" users="rsync_backup" passwordfil
     32             <userDefinedPort start="false" port="874"/><!-- por=874 -->

d、启动sersync服务程序 由于这边服务不是通过yum安装的所有不能用systemctl restart xxx 命令启动,要到它的命令目录中(bin)启动服务 先赋予目录执行权限

代码语言:javascript
AI代码解释
复制
    cd bin/
    chmod a+x sersync
    export PATH="$PATH:/usr/local/sersync/bin"
    echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/sersync/bin

查看命令文档

代码语言:javascript
AI代码解释
复制
    sersync -dro  /usr/local/sersync/conf/confxml.xml    启动实时同步服务
代码语言:javascript
AI代码解释
复制
    yum install -y psmisc
    killall sersync                                     停止实时同步服务
    /etc/rc.local <-- sersync -dro  /usr/local/sersync/conf/confxml.xml   开机自动启动  

4、实时同步服务概念总结

1) 实现实时同步的原理 监控目录数据变化 --- inotify 将数据进行传输 --- rsync 将监控和传输进行整合 --- sersync 2) 实现实时同步部署方法

  1. 部署rsync守护进程
  2. 部署inotify软件
  3. 部署sersync软件
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-01-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
javascript异步编程之generator(生成器函数)与asnyc/await语法糖
相比于传统回调函数的方式处理异步调用,Promise最大的优势就是可以链式调用解决回调嵌套的问题。但是这样写依然会有大量的回调函数,虽然他们之间没有嵌套,但是还是没有达到传统同步代码的可读性。如果以下面的方式写异步代码,它是很简洁,也更容易阅读的。
开水泡饭
2022/12/26
4460
面试官: 说说你对async的理解
async是generator和promise的语法糖,利用迭代器的状态机和promise来进行自更新!
用户8200753
2023/10/22
2950
async/await 源码实现
如果你有一个这样的场景,b依赖于a,c依赖于b,那么我们只能通过promise then的方式实现。这样的的可读性就会变得很差,而且不利于流程控制,比如我想在某个条件下只走到 b 就不往下执行 c 了,这种时候就变得不是很好控制!
用户4131414
2020/03/19
1.4K0
字节前端高频手写面试题(持续更新中)1
观察者需要放到被观察者中,被观察者的状态变化需要通知观察者 我变化了 内部也是基于发布订阅模式,收集观察者,状态变化后要主动通知观察者
helloworld1024
2023/01/03
8440
Promise/async/Generator实现原理解析
笔者刚接触async/await时,就被其暂停执行的特性吸引了,心想在没有原生API支持的情况下,await居然能挂起当前方法,实现暂停执行,我感到十分好奇。好奇心驱使我一层一层剥开有关JS异步编程的一切。阅读完本文,读者应该能够了解:
Nealyang
2020/03/25
2K0
async/await 原理及执行顺序分析
之前写了篇文章《这一次,彻底理解Promise原理》,剖析了Promise的相关原理。我们都知道,Promise解决了回调地狱的问题,但是如果遇到复杂的业务,代码里面会包含大量的 then 函数,使得代码依然不是太容易阅读。
桃翁
2019/11/08
2.1K0
JavaScript 的 async/await : async 和 await 在干什么
async 是“异步”的简写,而 await 可以认为是 async wait 的简写。 async 用于申明一个 function 是异步的,而 await 用于等待一个异步方法执行完成。 await 只能出现在 async 函数中。
一个会写诗的程序员
2018/08/17
1.1K0
JavaScript 的 async/await : async 和 await 在干什么
如何写出一个惊艳面试官的 Promise【近 1W字】 前言源码1.Promise2.Generator3.async 和 await4.Pro
1.高级 WEB 面试会让你手写一个Promise,Generator 的 PolyFill(一段代码); 2.在写之前我们简单回顾下他们的作用; 3.手写模块见PolyFill.
火狼1
2020/05/09
8270
如何写出一个惊艳面试官的 Promise【近 1W字】
                            前言源码1.Promise2.Generator3.async 和 await4.Pro
async与await的原理揭秘
async和await是es7语法,在babel中会被转译,我们看一下专一前和转译后的源码:
挥刀北上
2021/12/10
9300
async与await的原理揭秘
async/await剖析
JavaScript是单线程的,为了避免同步阻塞可能会带来的一些负面影响,引入了异步非阻塞机制,而对于异步执行的解决方案从最早的回调函数,到ES6的Promise对象以及Generator函数,每次都有所改进,但是却又美中不足,他们都有额外的复杂性,都需要理解抽象的底层运行机制,直到在ES7中引入了async/await,他可以简化使用多个Promise时的同步行为,在编程的时候甚至都不需要关心这个操作是否为异步操作。
WindRunnerMax
2020/08/27
3910
理解 ES6 generator
与 promise 对象类似,这里运用鸭子模型进行判断,如果对象中有 next 与 throw 两个方法,那么就认为这个对象是一个生成器对象。
翼德张
2022/01/13
3240
Promise 向左,Async/Await 向右?
1. 前言 从事前端开发至今,异步问题经历了 Callback Hell 的绝望,Promise/Deffered 的规范混战,到 Generator 的所向披靡,到如今 Async/Await 为大众所接受,这其中 Promise 和 Async/Await 依然活跃代码中,对他们的认识和评价也经历多次反转,也有各自的拥趸,形成了一直延续至今的爱恨情仇,其背后的思考和启发,依旧值得我们深思。 预先声明: 本文的目标并不是引发大家的论战,也不想去推崇其中任何一种方式来作为前端异步的唯一最佳实践,想在介绍下
用户1097444
2022/06/29
6250
Promise 向左,Async/Await 向右?
面试官问 async、await 函数原理是在问什么?
这周看的是 co 的源码,我对 co 比较陌生,没有了解和使用过。因此在看源码之前,我希望能大概了解 co 是什么,解决了什么问题。
若川
2021/09/27
7770
Generator函数
JavaScript是单线程的,异步编程对于 JavaScript语言非常重要。如果没有异步编程,根本没法用,得卡死不可。
木子星兮
2020/07/16
1.2K0
ES6读书笔记(三)
前段时间整理了ES6的读书笔记:《ES6读书笔记(一)》,《ES6读书笔记(二)》,现在为第三篇,本篇内容包括:
全栈程序员站长
2021/07/06
1.3K0
【ECMAScript6】es6 要点(二)Promise | 自个写一个Promise | Generator | Async/Await
但是,我们不能无限制地调用next从Generator实例中获取值。否则最后会返回undefined。原因:Generator犹如一种序列,一旦序列中的值被消费,你就不能再次消费它。即,序列为空后,再次调用就会返回undefined!。
前端修罗场
2023/10/07
5150
【ECMAScript6】es6 要点(二)Promise | 自个写一个Promise | Generator | Async/Await
手写async,await 理解内部原理
async await 底层并不是新东西,只是用起来比Generator函数更舒服的api...
心念
2023/01/11
8990
原生JS灵魂之问(下), 冲刺进阶最后一公里(附个人成长经验分享)
笔者最近在对原生JS的知识做系统梳理,因为我觉得JS作为前端工程师的根本技术,学再多遍都不为过。打算来做一个系列,一共分三次发,以一系列的问题为驱动,当然也会有追问和扩展,内容系统且完整,对初中级选手会有很好的提升,高级选手也会得到复习和巩固。这是本系列的第三篇。
用户4131414
2020/03/19
2.2K0
co 函数库的含义和用法
======================================== 以下是《深入掌握 ECMAScript 6 异步编程》系列文章的第三篇。 Generator函数的含义与用法 Th
ruanyf
2018/04/12
1.1K0
co 函数库的含义和用法
前端异步代码解决方案实践(二)
早前有针对 Promise 的语法写过博文,不过仅限入门级别,浅尝辄止食而无味。后面一直想写 Promise 实现,碍于理解程度有限,多次下笔未能满意。一拖再拖,时至今日。
前朝楚水
2018/07/26
3.6K0
推荐阅读
相关推荐
javascript异步编程之generator(生成器函数)与asnyc/await语法糖
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
首页
学习
活动
专区
圈层
工具
MCP广场
首页
学习
活动
专区
圈层
工具
MCP广场