zoukankan      html  css  js  c++  java
  • SERSYNC服务

    inotiry图片参考

    sersync图片参考

     

     

    inotify文字教程

    该软件对系统有要求,内核2.6以上,并且有如下目录,后面会讲解三个文件用途

      [root@jokerpro ~]# uname -r
      3.10.0-693.2.2.el7.x86_64

    [root@jokerpro ~]# ls -l /proc/sys/fs/inotify/
    -rw-r--r-- 1 root root 0 May 31 10:32 max_queued_events
    -rw-r--r-- 1 root root 0 May 31 10:32 max_user_instances
    -rw-r--r-- 1 root root 0 May 31 10:32 max_user_watches

    安装该软件

    1,安装inotify-tools
    yum install inotify-tools -y
    2,命令集工具,即inotifywait和inotifywatch
    inotifywait:在被监控的文件或目录上等待特定文件系统事件 (open,close,delete等)发生,执行后处于阻塞状态,适合在shell脚本中使用
    inotifywatch:收集被监控的文件系统使用度统计数据,指文件系统事件发生的次数统计
    3,简单测试
    inotifywait -mqr --excludei=a.txt --timefmt '%d/%m/%y%H:%M' --format '%T %w%f' -e create,close_write /backup3

    附赠参数说明

    inotifywait 参数说明

    参数名称参数说明
    -m,–monitor 始终保持事件监听状态
    -r,–recursive 递归查询目录
    -q,–quiet 只打印监控事件的信息
    –excludei 排除文件或目录时,不区分大小写
    -t,–timeout 超时时间
    –timefmt 指定时间输出格式
    –format 指定时间输出格式
    -e,–event 后面指定删、增、改等事件
    --format : 自定义inotifywait的输出格式,如--format '%T %w%f',格式解释如下
    %w :显示被监控目录的名字
    %f : 发生变化的文件名
    %T: 使用--timefmt选项中自定义的时间格式

    inotifywait events事件说明

    事件名称事件说明
    access 读取文件或目录内容
    modify 修改文件或目录内容
    attrib 文件或目录的属性改变
    close_write 修改真实文件内容
    close_nowrite  
    close  
    open 文件或目录被打开
    moved_to 文件或目录移动到
    moved_from 文件或目录从移动
    move 移动文件或目录移动到监视目录
    create 在监视目录下创建文件或目录
    delete 删除监视目录下的文件或目录
    delete_self  
    unmount 卸载文件系统

    优化 Inotify

    #默认情况下不需要优化

    在/proc/sys/fs/inotify目录下有三个文件,对inotify机制有一定的限制

    #文件说明
    max_user_watches #设置inotifywait或inotifywatch命令可以监视的文件数量(单进程)
    max_user_instances #设置每个用户可以运行的inotifywait或inotifywatch命令的进程数
    max_queued_events #设置inotify实例事件(event)队列可容纳的事件数量

    附赠一个监控脚本,rsync+inotify都应该装在逻辑服上,推送到备份服务器上

    #!/bin/bash
    # The author is joker, which is used to listen to directories and synchronize files.
    # 判软件安装
    inotify_order=`which inotifywait 1>/dev/null 2>&1`
    inotify_state=`echo $?`
    rsync_order=`which rsync 1>/dev/null 2>&1`
    rsync_state=`echo $?`
    if [ $inotify_state -eq 1 -a $rsync_state -eq 1 ];then
        yum install inotify-tools rsync -y
        sleep1
        sh $0
    else
    # 脚本是时刻监控path目录发生的变化,应该存放于rsync的客户端,即逻辑服务器
    # 被监控目录
    localpath=/joker/
    # rsync验证用户,密码
    auth_user=rsync_backup
    cat >/etc/rsync.passwd<<EOF
    woshimima
    EOF
    passwd_file=/etc/rsync.passwd
    chmod 600 /etc/rsync.passwd
    # 备份服务器IP
    ip="60.205.188.107"
    # 备份服务器备份目录,匹配rsync模块
    backupdir=gameserver1
    # m保持监听状态,r递归查询目录,q打印监控事件信息,w显示被监控目录名字,f发生变化的文件名
    inotifywait -mrq --format '%w%f' -e close_write,delete $localpath 
    |while read file
    do
        if [ -f $file ];then
            rsync -az $file --delete $auth_user@$ip::$backupdir --password-file=$passwd_file
        else
            cd $localpath
            rsync -az ./ --delete $auth_user@$ip::$backupdir --password-file=$passwd_file
        fi
    done
    fi

    sersync文字教程

    包在自己的云服务器目录上/joker,读者如果没有该目录,请从网上查找

    1,想同步什么文件 6-11
    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>
    2,inotify监控属性 12-21
    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>
    3,sersync配置 23-44
    其中
    24-28 目录
    24          <localpath watch="/opt/tongbu">  # 本地推送目录
    25              <remote ip="127.0.0.1" name="tongbu1"/> #rsync服务器ip和模块
    26              <!--<remote ip="192.168.8.39" name="tongbu"/>-->
    27              <!--<remote ip="192.168.8.40" name="tongbu"/>-->
    28          </localpath>
    29-35 rsync命令
    29          <rsync>
    30              <commonParams params="-artuz"/> # 默认avz
    31              <auth start="true" users="root" passwordfile="/etc/rsync.pas"/> # 开启验证,用户,密码
    32              <userDefinedPort start="false" port="874"/<!port=874 --> # 端口
    33              <timeout start="true" time="100"/><!-- timeout=100 --> # 客户端超时
    34              <ssh start="false"/>
    35          </rsync>
    4,日志 36
    36    <failLogpath="/tmp/rsync_fail_log.sh"timeToExecute="60"/><!--default every 60mins execute once-->

    启动执行

     /mnt/sersync/bin/sersync -d -r -o /mnt/sersync/conf/confxml.xml

    附赠启动参数

    [root@jokerpro bin]# /service/script/sersync/bin/sersync -h
    set the system param
    execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
    execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
    parse the command param
    _______________________________________________________
    参数-d:启用守护进程模式
    参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
    参数-n: 指定开启守护线程的数量,默认为10个
    参数-o:指定配置文件,默认使用confxml.xml文件
    参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
    参数-m:单独启用其他模块,使用 -m socket 开启socket模块
    参数-m:单独启用其他模块,使用 -m http 开启http模块
    不加-m参数,则默认执行同步程序

    注意与事项

    逻辑服务器安装inotify+sersync+rsync命令
    
    备份服务器安装rsync的daemon模式
    
    逻辑服务器数据产生目录发生数据变化,就会推送到备份服务器上
    
    一般错误还是发生在rsync上,请看上一篇文章,搞懂rsync,虚拟账号,rsync账号,目录权限

    附赠sersync脚本,执行于逻辑服上

    #!/bin/bash
    # The author is joker, applied to file synchronization.
    # rsync 验证用户,密码
    author=rsync_backup
    password=woshimima
    # 判软件安装
    inotify_order=`which inotifywait 1>/dev/null 2>&1`
    inotify_state=`echo $?`
    rsync_order=`which rsync 1>/dev/null 2>&1`
    rsync_state=`echo $?`
    if [ $inotify_state -eq 1 -a $rsync_state -eq 1 ];then
        echo -e "33[31m 红色字,正在安装inotify,rsync 33[0m" 
        yum install inotify-tools rsync -y
        sleep1
        sh $0
    else
        # 只需要密码
    cat>/etc/rsync.passwd<<EOF    
    $password
    EOF
        chmod 600 /etc/rsync.passwd
        # 查找xml文件位置
        sersync_path=`pwd`
        confxml_path=`cd ..&&pwd`
        # -d 守护进程模式,-r如果是第一次监控,将全量推送一次,后续增量,-o,指定配置文件
        $sersync_path/sersync -d -r -o $confxml_path/conf/confxml.xml
        sersync_process=`ps -ef|grep sersync|grep -v grep|wc -l`
        if [ $sersync_process -ge 1 ];then
            echo -e "33[32m 绿色字,sersync 启动成功 33[0m"
        else
            echo -e "33[31m 红色字,启动失败,检查inotify,rsync是否安装与正常启动 33[0m" 
        fi
    fi
  • 相关阅读:
    C语言格式化字符串细节 --- %*s %*c %*.*s
    ROC曲线与AUC计算总结
    python 数字列表排序,输出对应的索引 | 转载
    python 类间的有趣调用
    Linux下以16进制形式显示文件内容的方法
    一些书签
    椭圆曲线算数原理与实现
    中国剩余定理来解密RSA密文
    在GridView控件内文本框实现TextChanged事件,勾选复选框时 :textbox文本框可编辑,编辑文本框的数字后 总金额会重新计算并统计
    关于RDLC子报表添加参数 错误“本地报表处理期间出错 。值不能为空。 参数名:value” 错误解决方法
  • 原文地址:https://www.cnblogs.com/jokerbj/p/9115164.html
Copyright © 2011-2022 走看看