inotify+rsync實時同步服務部署

環境:服務端 192.168.6.30(安裝 rsync) /data/sharehtml

  :客戶端 192.168.6.38(安裝 inotufy+rsync)/nfsbackupc++

主流程:http://www.javashuo.com/article/p-xvbayoao-ht.htmlgit

    

客戶端安裝 inotifygithub

下面開始安裝inotify-tools
[root@static-img ~]# yum install make gcc gcc-c++                          #安裝編譯工具
[root@static-img ~]# cd /usr/local/src
[root@static-img src]# wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
[root@static-img src]# tar zxvf inotify-tools-3.14.tar.gz
[root@static-img src]# cd inotify-tools-3.14
[root@static-img inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify
[root@static-img inotify-tools-3.14]# make && make installvim

發現已經成功安裝inotify-tools了
[root@static-img inotify-tools-3.14]# ll -d /usr/local/inotify/
drwxr-xr-x 6 root root 4096 Oct 26 12:01 /usr/local/inotify/bash

設置系統環境變量
[root@static-img ~]# vim /etc/profile
......
export PATH=$PATH:/usr/local/inotify/bin
[root@static-img ~]# source /etc/profile工具

添加庫文件
[root@static-img ~]# vim /etc/ld.so.conf
/usr/local/inotify/lib
[root@static-img ~]# ldconfigspa

修改inotify默認參數(inotify默認內核參數值過小)
查看系統默認參數值
[root@static-img ~]# sysctl -a | grep max_queued_events
fs.inotify.max_queued_events = 16384
[root@static-img ~]# sysctl -a | grep max_user_watches
fs.inotify.max_user_watches = 8192
[root@static-img ~]# sysctl -a | grep max_user_instances
fs.inotify.max_user_instances = 128code

修改參數:
[root@static-img ~]# sysctl -w fs.inotify.max_queued_events="99999999"
[root@static-img ~]# sysctl -w fs.inotify.max_user_watches="99999999"
[root@static-img ~]# sysctl -w fs.inotify.max_user_instances="65535"orm

腳本

#!/bin/bash
Path=/data/share
backup_Server=192.168.6.30
/usr/local/inotify/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data/share  | while read line  
do
    if [ -f $line ];then
        rsync -az $line --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password
    else
        cd $Path &&\
        rsync -az ./ --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password
    fi
done
相關文章
相關標籤/搜索