微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ubuntu 14.04 配置 rsync + inotify 文件双向实时同步

一、安装配置

1. 安装rsync,inotify-tools

sudo apt-get install rsync inotify-tools

2. 拷贝rsync配置文件

mkdir /etc/rsync
cp /usr/share/doc/rsync/examples/rsyncd.conf   /etc/rsync/

3. 服务端配置/etc/rsync/rsyncd.conf

#secrets file=/etc/rsync/rsyncd.secrets
#motd file=/etc/rsync/rsyncd.motd
[linuxsirhome]

#path=/usr/share/Nginx/html
path=/usr/share/Nginx/html

log file=/var/log/rsyncd.log
pid file=/var/log/rsyncd.pid
lock file=/var/run/rsync.lock

read only=no
list=yes
uid=root
gid=root
use chroot=no
max connections=5
comment=share file
#ignore errors

4. 创建同步目录

mkdir /opt/rsyncdate

5. 创建认证文件修改权限600

vim /etc/rsync/rsync.secrets
user:passwd
chmod 600  /etc/rsync/rsync.secrets

6. 修改 /etc/default/rsync,设置为true

RSYNC_ENABLE=true
RSYNC_CONfig_FILE= "/etc/rsync/rsyncd.conf"

7. 服务端启动rsync服务

/etc/init.d/rsync start

8. 客户端创建密码认证文件

mkdir /etc/rsync
vim /etc/rsync/rsync.secrets
passwd
chmod 600 /etc/rsync/rsync.secrets

9. 监控需要同步的目录

#!/bin/bash
path='/opt/rsyncdate/'  #远程目录
mod1=rsyncdate  #远程模块
host1='192.168.1.200'  #远程主机ip
user1=www  #远程用户
/usr/bin/inotifywait -mrq --timefmt '%y/%m/%d %H:%M' --format '%T %w %f' -e modify,delete,create,attrib $path | while read file 
do
/usr/bin/rsync -avzP --delete --progress $path $user1@$host1::$mod1 --password-file=/etc/rsync/rsync.secrets
echo "${file} was rsyncd " >> /var/log/rsync.log 2 >&1
done

二、附加脚本

1. 重写 rsync 服务启动脚本:

#!/bin/bash 
#this script for start|stop rsync daemon service 

status1=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')
pidfile="/etc/rsync/rsyncd.pid"
start_rsync="rsync --daemon --config=/etc/rsync/rsyncd.conf"

function rsyncstart() {

    if [ "${status1}X" == "X" ];then

        rm -f $pidfile

        ${start_rsync}

        status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')

        if [  "${status2}X" != "X"  ];then

            echo "rsync service start.......OK" 

        fi

    else

        echo "rsync service is running !"    

    fi
}

function rsyncrestart() {

    if [ "${status1}X" == "X" ];then

               echo "rsync service is not running..." 

               rsyncstart
        else

               rsyncstop

               rsyncstart

        fi
}

case $1 in

        "start")
               rsyncstart
                ;;

        "stop")
               rsyncstop
                ;;

        "status")
               rsyncstatus
               ;;

        "restart")
               rsyncrestart
               ;;

        *)
          echo 
                echo  "Usage: $0 start|stop|restart|status" 
          echo 
esac

2. 启动监控脚本(实时监控):rsync_do.sh

#!/bin/bash 
#src='/usr/share/Nginx/html'
src='/usr/share/Nginx/html'
#src='/tmp/Nginx/html'
user='ubuntu'
host='34.192.231.27'
rsync_module='linuxsirhome'

/usr/bin/inotifywait -mrq --exclude=html/App/Runtime --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e modify,attrib ${src} \
        | while read DATE TIME DIR file
        do
                # /usr/bin/rsync -vzrtopg --delete --progress /usr/share/Nginx/html ubuntu@34.192.231.27::linuxsirhome
                #/usr/bin/rsync -vzrtopg --exclude-from=/etc/rsync/exclude.rule --include-from=/etc/rsync/include.rule --delete --progress ${src} ${user}@${host}::${rsync_module}
                /usr/bin/rsync -vzrtopg --include-from=/etc/rsync/include.rule --exclude-from=/etc/rsync/exclude.rule --exclude=/* --delete --progress ${src} ${user}@${host}::${rsync_module}
                echo "${file} was rsynced at ${DATE}_${TIME} in ${DIR}" >> /var/log/rsync.log 2>&1
        done

3. include.rule

# cat /etc/rsync/include.rule
html

三、目录大量文件错误处理:

在对一个大磁盘进行inotify监听时,爆出如下错误
Failed to watch /mnt/;
upper limit on inotify watches reached!
Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches’.

cat  /proc/sys/fs/inotify/max_user_watches

临时生效:修改 max_user_watches

max_user_watches 这个文件认值是8192

echo 99999999 > /proc/sys/fs/inotify/max_user_watches

永久生效:修改 max_user_watches

Linux系统重启inotify配置max_user_watches无效被恢复认值8192的正确修改方法为:

sudo vim /etc/sysctl.conf

注意添加一行内容

fs.inotify.max_user_watches=99999999  #(你想设置的值)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、安装SSH和配置SSH无密码登录四、安装Java环境1. 安装JDK2. 配置JDK环境3. 检验安装五、安装单机Hadoop1. 下载安装Hadoop2. 运行示例总结前言本文安装的 Hadoop 及 Java 环境基于林子雨老师的《大数据技术原理与应用(第3版)》中所要求,其中Java 版本为1.8.0_301,Hadoop 版本为3.3.1,其他版本的安装请参考其他博客。..
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html  运行django出现错误信息:[2016-02-16 14:33:24,476 pyinotify ERROR] add_watch: cannot watch /usr/local/lib/python2.7/dist-packages/django/contrib/sessio...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失了,如下:别着急,以下教你如何找回之前的虚拟机:1、点击控制,然后选择注册,找到虚拟机的安装目录,比如:C:UserstxVirtualBox VMs,然后选择需要找回的虚拟机vbox,点击打开按钮即可:2、如果打开后报错,则执行第三步:3、删除ubuntu.vbox,然后将ubuntu.vbox-prev重命名为ubuntu.vbox,然后再执行第二步即可...
参见:https://blog.csdn.net/weixin_38883338/article/details/82153933 https://blog.csdn.net/github_39533414/article/details/85211012
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netplan 基于 YAML 的配置系统,使得配置过程非常简单。Netplan 替换了我们之前在 Ubuntu 中用于配置网络接口的旧配置文件/etc/network/interfaces。在本文中,我们将学习如何使用 Netplan 在 Ubuntu 中配置网络。我们将看到静态和动态 IP 配置。我将使用 Ubuntu 18.04 LTS 来描述本文中提到的过程。使用 Netplan 配置网络您可以在/etc
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问,该 URL 代表一种“替代名称”,用于标识提供该服务的服务器的 IP 地址和端口。同一台机器可以同时在不同的端口上提供不同的服务。出于安全原因,可能需要屏蔽 Web 服务的端口号,从而在外部显示与服务实际侦听的端口号不对应的端口号。感谢本教程,您将能够管理您的服务器端口,配置集成在 Ubuntu 中的 UFW 防火墙。特别是,按照指南的说明,您将学习将来自某个端口的请求转发到另一个端口(端口转发),同时使用后者提供的.
Observium 是一个免费和开源的 sa 网络管理和监控系统工具。我们可以使用 SNMP 收集数据,它允许监控所有网络设备。它提供了一个简单易用的 Web 界面。它基于 PHP 并使用 MySQL 数据库来存储数据。在 ubuntu 上设置 Observium 有几个步骤:第 1 步:更新系统。apt-get update第 2 步:安装 PHP 和模块。apt install wget apache2 php php-{pear,cgi,common,curl,mbstring,g
从 20.04 开始,Ubuntu 决定更新实时服务器安装程序以实现自动安装规范,以便能够仅使用 Subiquity 完全自动化安装过程。Subiquity 是新的服务器安装程序(又名“服务器无处不在”),旨在取代之前基于 debian-installer 的经典系统。本文说明了如何使用 Packer 和 Proxmox 上的 Subiquity 生成 Ubuntu Server 20.04 图像模板。介绍Subiquity 仅在live图像文件版本中可用(例如ubuntu-20.0...
Ubuntu 将停止支持 Debian 安装程序(预置)。Ubuntu Server 20.04 附带了一种新的自动化操作系统安装方法,称为带有 subiquity 服务器安装程序的自动安装。这篇文章展示了使用新安装程序构建的打包程序。此设置仅适用于 Ubuntu-20.04 live-server 而不是旧版。SubiquitySubiquity 是 Ubuntu 服务器的新自动安装程序,它是在 18.04 中引入的。自动安装的设置由 cloud-init 配置提供。如果设置,将从配置文件.
此页面的目的是提供在您机器上的 VM 中执行自动安装的简单说明。此页面假设您使用的是 amd64 架构。s390x也有一个版本。通过网络提供自动安装数据这种方法是最容易推广到完全基于网络的安装的方法,在这种安装中,机器会进行网络引导,然后自动安装。下载 ISO转到20.04 ISO 下载页面并下载最新的 Ubuntu 20.04 实时服务器 ISO。挂载 ISOsudo mount -r ~/Downloads/ubuntu-20.04-live-server-amd64...