<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # inotify安裝和部署 [TOC] ## 1 介紹和說明 ### 1.1 軟件簡介 inofify是一種強大的、細粒度的、異步的文件系統時間監控機制,內置在linux內核2.6.13以上. inotify-tools工具實現的具體原理是,開啟inotify進程,進程會實時監控目標目錄的變化情況,然后按要求將變化情況通過rsync命令立即同步至服務器 inotify實時的前提,是成功配置并驗證rsync服務的推送功能,然后才能配置inotify服務 ### 1.2 安裝軟件 1) 系統信息 ```sh cat /etc/redhat-release CentOS release 6.9 (Final) ip addr show eth1|awk 'NR==3{print $2}' 172.16.1.31/24 hostname nfs01 ``` 2) 查看當前是否支持inotify ``` uname -r 2.6.32-696.el6.x86_64 ls /proc/sys/fs/inotify/ max_queued_events max_user_instances max_user_watches ``` 內核版本高于2.6.13并且/proc/sys/fs/inotify/目錄中存在上述三個文件才行 ## 2 部署程序 ### 2.1 安裝inotify程序 ```sh yum install inotify-tools -y rpm -qa |grep inotify-tools inotify-tools-3.14-1.el6.x86_64 inotify-tools工具包不再默認yum源中,如果電腦沒有安裝epel源,用下面命令安裝 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo ``` 重要命令 ```sh rpm -ql inotify-tools|head -2 /usr/bin/inotifywait <--實現對數據目錄信息變化監控 /usr/bin/inotifywatch <--監控數據信息變化,對變化的數據進行統計 ``` ### 2.2 部署rsync服務 略:參見rsync部署文檔<<rsync操作和部署文檔>> ### 2.3 編寫腳本 ```sh cat >/server/scripts/inotify_rsync.sh <<"EOF" #!/bin/bash Path=/data Ip=172.16.1.41 Pass_File=/etc/rsync.password inotifywait -mqr --format '%w%f' -e create,delete,moved_to,close_write $Path |\ while read file do if [ -f $file ];then rsync -az $file --delete rsync_backup@$Ip::backup $Pass_File else cd $Path &&\ rsync -az ./ --delete rsync_backup@$Ip::backup $Pass_File done EOF ``` ### 2.4 編寫自啟動腳本 1) 腳本編寫 ```sh cat >/etc/init.d/syncd <<"EOF" #!/bin/bash #chkconfig:2345 38 46 . /etc/init.d/functions if [ $# -ne 1 ];then usage: $0 {start|stop} exit 1 fi case "$1" in start) /bin/bash /server/scripts/inotify_rsync.sh & echo $$ >/var/run/inotify.pid if [ `ps -ef|grep inotify|wc -l` -gt 2 ];then action "inotify service is started" /bin/true else action "inotify service is started" /bin/false fi ;; stop) kill -9 `cat /var/run/inotify.pid` >/dev/null 2>&1 pkill inotifywait sleep 2 if [ `ps -ef|grep inotify|grep -v grep|wc -l` -eq 0 ];then action "inotify service is stopped" /bin/true else action "inotify service is stopped" /bin/false fi ;; *) usage: $0 {start|stop} exit 1 esac EOF ``` 2) 設置開機啟動 ```sh chkconfig --list syncd on chmod +x /etc/init.d/syncd /etc/init.d/syncd start ps -ef|grep inotify ``` 通過編寫啟動腳本,將實時同步做成隨機啟動 ## 3 inofity命令介紹 ### 3.1 inotifywait重要參數說明[紅色]: ```sh -m 始終保持事件監聽狀態 -r 進行遞歸監控 -q 簡化打印信息,只打印監控時間的信息 -d 后臺運行 -e 監控的事件,例如增加、修改、刪除等 access 訪問 modify 修改 attrib 屬性變化 close_write 關閉并有寫入 close_nowrite 關閉并沒有寫入 close 關閉(不管是否寫入) open 打開 moved_to 移動(到哪里) moved_from 移動(從哪來) move 移動(所有) create 創建 delete 刪除 delete_self 自身目錄被刪除 unmount 卸載 --format 輸出格式,常用'%w%f' --timefmt 輸出時間格式,常用'%d%m%y %H:%M' ``` ### 3.2 常用命令組合 ```sh inotifywait -mrq --format "%w%f" -e create,delete,moved_to,close_write /data ``` ## 4 inotify調優和總結 ### 4.1 參數文件說明 ```sh ls /proc/sys/fs/inotify/ max_queued_events max_user_instances max_user_watches max_user_watches: 單用戶最大可監視的文件數量(默認8192) max_user_instances: 單用戶最大進程數(默認128) max_queued_events: 最大的時間隊列(默認16384) ``` ### 4.2 調優方法 調優就是在同步數據量很大時(大并發),調大后兩個參數的值 ```sh echo 655350 >/proc/sys/fs/inotify/max_user_watches echo 655350 >/proc/sys/fs/inotify/max_queued_events ``` 并將以上數據寫入rc.local中,實現重啟不失效(注意規范,要寫注釋) ### 4.2 inotify優缺點 經過壓力測試,每秒200個(10-100K)文件并發,數據同步幾乎無延遲(小于1秒) * 優點: 監控文件系統時間變化,通過同步工具實現實時數據同步 * 缺點: 并發量大于200個文件(10-100k),同步會有延遲 單線程模式,并發效率低
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看