zoukankan      html  css  js  c++  java
  • rsync+inotify

     rsync+inotify实现文件时实同步  

                               
    由192.168.0.5上inotify服务监测文件是否有更新,如果有更新(修改,删除,新建)inotify就会通过rsync命令将更新的文件推向三台web服务器
     
    1、在三台web上配置rsync服务
       #mkdir -p /data/httpd/wwwroot       #创建web目录
     
       #vim /etc/rsyncd.conf               #配置文件
    1.  1 uid = root
       2 gid = root
       3 use chroot = no
       4 max connections =5
       5 pid file =/var/run/rsyncd.pid
       6 lock file =/var/run/rsync.lock
       7 log file =/var/log/rsyncd.log
       8 [www]
       9 path=/data/httpd/wwwroot/
      10 comment = update
      11 ignore errors
      12 read only = no
      13 list = no
      14 hosts allow =192.168.0.0/255.255.255.0
      15 auth users = root
      16 uid = root
      17 gid = root
      18 secrets file =/etc/rsyncd.secrets
       #vim /etc/rsyncd.secrets                   #创建rsync证文件
       123456
       root:123456
     
       #chmod 0600 /etc/rsyncd.secrets            #设置权限
       #rsync --daemon                                      #启动服务
       #echo "rsync --daemon"  >> /etc/rc.local   #开机自启动
     
     
    2、配置服务端(rsync+inotify)
       #mkdir -p /data/httpd/wwwroot   #创建目录存放代码
       (1)、安装inotify
       #cd /usr/local/src/
       #wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
       #tar xzvf inotify-tools-3.14.tar.gz
       #cd inotify-tools-3.14
       #./configure
       #make
       #make install
     
       (2)、编写同步更新脚本
    1.  1 #!/bin/bash
       2 src=/data/httpd/wwwroot/
       3 des=www
       4 host="192.168.0.6 192.168.0.7 192.168.0.8"
       5 /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M'--format '%T %w%f%e'-e close_write,delete,create,attrib $src |while read files
       6 do
       7 for hostip in $host
       8 do
       9 rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.secrets $src root@$hostip::$des
      10 done
      11 echo "${files} was rsynced">>/tmp/rsync.log 2>&1
      12 done
       (3)、创建rsync认证文件
       #scp from rsync server 
     
       (4)、启动inotify监控脚本
       #nohup /bin/bash /root/bin/rsync.sh &     
       #echo "nohup /bin/bash /root/bin/rsync.sh &" >> /etc/rc.local
     
       (5)、测试
       在192.168.0.5上进入目录/data/httpd/wwwroot/
       #touch a.txt
       在三台web机上/data/httpd/wwwroot/目录可以立马看a.txt。



    将来的你,一定会感谢现在拼命努力的你。
  • 相关阅读:
    动手开发自己的第一个 composer 包
    实现网易云视频直播播放器功能
    html文本标准模式,首行空两格,两端对齐,行高
    设置svg图片大小
    IntelliJ IDEA,代码行宽度超出限制时自动换行
    是什么时候开始学习gulp了
    Laravel 安装多国语言包后,phpstorm 还是报错
    解决Package illuminate/html is abandoned, you should avoid using it. Use laravelcollective/html instead.问题
    去掉悬浮框与点击框之间的线条问题
    解决实现注册功能点击注册的时候报错问题
  • 原文地址:https://www.cnblogs.com/51runsky/p/4572414.html
Copyright © 2011-2022 走看看