zoukankan      html  css  js  c++  java
  • centos 7 安装 rsync 和 安装 rsync inotify

    rsync分为master 和 slave

    1)在master上

    mkdir -p /usr/local/shell/
    cd /usr/local/src
    wget http://download.zhufunin.com/rsync-3.1.2.tar.gz
    tar -zxf rsync-3.1.2.tar.gz
    cd rsync-3.1.2
    ./configure --prefix=/usr/local/rsync
    make && make install

    配置文件rsync.passwd

    cd /usr/local/rsync
    echo "fzz0aocKeJ" > /usr/local/rsync/rsync.passwd
    chmod 600 /usr/local/rsync/rsync.passwd

    下面是主动同步的脚本

    脚本用法/usr/local/rsync/rsync.sh 192.168.1.100

    cd /usr/local/rsync/
    touch rsync.sh
    chmod 755 rsync.sh

    #!/bin/sh
    #脚本路径 /usr/local/rsync/rsync.sh
    host=$1
    src=/usr/local/nginx/conf/autoconfig/
    desc=nginxconfig
    user=root
    /usr/local/rsync/bin/rsync -l --port 8730 --timeout 10 -vzrtopgP --delete --password-file=/usr/local/rsync/rsync.passwd $src $user@$host::$desc

    下面的是设置rsync inotify

    cd /usr/local/rsync/
    touch inotify_rsync.sh
    chmod 755 inotify_rsync.sh

    #!/bin/bash
    
    slavelist=(192.168.1.100 192.168.1.101 192.168.1.102 192.168.1.103)
    src=/usr/local/nginx/conf/autoconfig/
    des=nginxconfig
    user=root
    
    
    /usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files
    do
        for host in `echo ${slavelist[*]}`; do
            /usr/local/rsync/bin/rsync -l --port 8730 --timeout 10  -vzrtopgP --delete --password-file=/usr/local/rsync/rsync.passwd $src $user@$host::$des >/dev/null 2>&1
        done
    done

     后台运行rsync inotify

    nohup /usr/local/rsync/inotify_rsync.sh &

     2)在slave上

    安装rsync

    yum install gcc perl wget -y 
    cd /usr/local/src/
    wget http://download.zhufunin.com/rsync-3.1.2.tar.gz
    tar -zxf rsync-3.1.2.tar.gz
    cd rsync-3.1.2
    ./configure --prefix=/usr/local/rsync
    make && make install

    配置文件 rsyncd.passwd

    cd /usr/local/rsync
    echo "root:fzz0aocKeJ" > /usr/local/rsync/rsyncd.passwd
    chmod 600 /usr/local/rsync/rsyncd.passwd

    配置文件rsyncd.conf

    #文件路径/usr/local/rsync/rsyncd.conf
    uid = root
    gid = root
    use chroot = no
    max connections = 10
    strict modes = yes
    hosts allow = ##_masterIp_##
    port = 8730
    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
    auth users = root
    secrets file = /usr/local/rsync/rsyncd.passwd
    
    [nginxconfig]
    path = /usr/local/nginx/conf/autoconfig

    slave需要一直运行等待主控的rsync请求

    /usr/local/rsync/bin/rsync --port 8730 --daemon --config=/usr/local/rsync/rsyncd.conf
  • 相关阅读:
    Asp.net获取客户端的IP地址排除::1
    EF 筛选列包含NULL会报错
    layUI关于table编辑列支持方向键功能
    .NET CORE 发布IIS问题收集
    VS2019最新源代码管理工具+附下载地址
    关于Mysql可视化工具Navicat Premium12激活使用【亲测】
    经典SQL 语句
    事务的四种隔离级别 [转载]
    HTML 特殊符号编码对照表
    github本地文件Push到仓库
  • 原文地址:https://www.cnblogs.com/faberbeta/p/13138695.html
Copyright © 2011-2022 走看看