環境:redhat 6.4-64
主機:10.1.1.2
鏡像機:10.1.1.3
目標:將主機上的更新問題及時同步到鏡像機上
在主機上安裝inotify-tools-3.13.tar.gz
tar -xvf inotify-tools-3.13.tar.gz
cd inotify-tools-3.13
./configure
make && make install
在主機上新建同步腳本
vim /opt/shells/rsync.sh
內容爲:
#!/bin/sh
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib /home/aaa/appData/ | while read file
do
rsync -vzrtopg --progress /home/aaa/appData/appData.txt 10.1.1.3::image/
echo $file >> /var/log/langfang_rsync.txt
done
上邊是檢查/home/aaa/appData/ 目錄下的變動
下邊是將/home/aaa/appData/ 目錄的內容同步至10.1.1.3機器上的image模塊,中間的::是規定格式,image模塊將在鏡像機定義,
在主機上啓動
/etc/init.d/xinetd start
在備機上新建文件
vim /etc/rsyncd.conf
內容:
port = 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
[image]
uid = root
gid = root
path = /data/inth/
read only = no
[config]
uid = root
gid = root
path = /
read only = no
incoming chmod = Du=rwx,Dog=rx,Fu=rwx,Fgo=rx
[backup]
uid = root
gid = root
path = /
read only = no
incoming chmod = Du=rwx,Dog=rx,Fu=rwx,Fgo=rx
啓動
/etc/init.d/xinetd start
在主機上執行後臺腳本
nohup /opt/shells/rsync.sh &
在鏡像機修改文件
vim /etc/xinetd.d/rsync
將:disable = yes 修改爲 disable = no
重啓xined
/etc/init.d/xinetd restart
在主機上執行
rsync -vzrtopg --progress /test/appData.txt 10.1.1.204::image/
如果出現如下表示成功:
這次修改主機上的文件應該就能同步成功了