Inotify同步web服务器
一.Ssh生成密钥。
1. 执行ssh-keygen -t rsa命令,然后一路回车。
2.rsync -av ~/.ssh/id_rsa.pub   root@192.168.2.7:~/.ssh/authorized_keys #web真实机
3. rsync -av ~/.ssh/id_rsa.pub   root@192.168.2.6:~/.ssh/authorized_keys #web真实机
4.实现本机ssh登录web真实机不用密码。
二.安装inotify
1.yum install inotify-tools-3.13-1.i386.rpm
2.vim inotify.sh
#!/bin/sh
src=/var/www/html/ 
des=/var/www/html/  
dip1=192.168.2.6 
dip2=192.168.2.7      
/usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib ${src} | while read file
        do
            echo "${file} was rsynced to ${dip1}"
            rsync -avz --delete --progress ${src} root@${dip1}:${des} &&
            echo "${file} was rsynced to ${dip1}" >> /tmp/rsync.log 2>&1
            echo "------------------------------------" >> /tmp/rsync.log 2>&1
           
            echo "${file} was rsynced to ${dip2}"
           rsync -avz --delete --progress ${src} root@${dip2}:${des} &&
            echo "${file} was rsynced to ${dip2}" >> /tmp/rsync.log 2>&1
            echo "------------------------------------" >> /tmp/rsync.log 2>&1
        done
exit
                   3.sh inotify.sh &
三.测试,在本机的/var/www/html/中执行 echo “inotify test !” > index.html,然后在需要同步的两台主机的该目录下查看index.html是否有写入 “inotify test !”