安裝Inotify-tools

Inotify-tools 能夠幫助Liunx快速實現文件同步。git

1. 安裝Inotify-toolsgithub

mkdir /soft

chmod 775 /soft

cd /soft

wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

tar zxvf inotify-tools-3.14.tar.gz

cd inotify-tools-3.14 

./configure --prefix=/usr && make && su -c 'make install'

2. 設置系統環境變量,添加軟鏈接vim

echo "PATH=/usr/local/inotify/bin:$PATH" >>/etc/profile.d/inotify.sh

source /etc/profile.d/inotify.sh  #使設置當即生效

echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf

ln -s /usr/local/inotify/include  /usr/include/inotify

3. 修改系統參數,提升隊列性能性能

sysctl -a | grep max_queued_events

結果是:fs.inotify.max_queued_events = 16384

sysctl -a | grep max_user_watches

結果是:fs.inotify.max_user_watches = 8192

sysctl -a | grep max_user_instances

結果是:fs.inotify.max_user_instances = 128

修改參數:

sysctl -w fs.inotify.max_queued_events="99999999"

sysctl -w fs.inotify.max_user_watches="99999999"

sysctl -w fs.inotify.max_user_instances="65535"

4 建立Shell腳本spa

rsync -az --delete /data/ test@172.16.120.252::ftp --password-file=/etc/passwd.txt


/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move /data | while read file

do

rsync -az --delete /data/ test@172.16.120.252::ftp --password-file=/etc/passwd.txt

echo "  ${file} was rsynced" >> /tmp/rsync.log 2>&1

done
~      

5 設置同步密碼:日誌

vim /etc/passwd.tx

#寫入同步密碼

6 設置同步日誌code

vim /tmp/rsync.log
chmod 775 rsync.log

7 設置系統啓動執行腳本orm

vim /etc/rc.d/rc.local  #編輯,在最後添加一行

sh /usr/local/inotify/rsync.sh & #設置開機自動在後臺運行腳本

:wq!  #保存退出
相關文章
相關標籤/搜索