//安裝inotify服務器
//在代碼發佈服務器上安裝inotify,執行以下命令 tar xzvf inotify-tools-3.14.tar.gz cd inotify-tools-3.14 ./configure make make install cd .. //在全部服務器上安裝rsync,命令以下: tar zxvf rsync-3.0.9.tar.gz cd rsync-3.0.9 ./configure make make install #------以上命令在每臺服務器上都須要執行---------
//配置ssh
//在代碼發佈服務器與須要同步的服務器之間配置ssh key信任,在代碼發佈服務器上生成公鑰和私鑰 ssh-keygen -t rsa //直接三次回車 //將公鑰添加到各個須要更新的主機authorized_keys 文件中,在代碼更新服務器上再執行 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.252#須要同步的服務器IP ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.254#須要同步的服務器IP //若是有提示 輸入yes //按提示輸入密碼回車
在代碼發佈服務器上以root身份建立inotify_rsync.sh腳本vi /root/inotify_rsync.sh 輸入 #!/bin/sh SRC=/data/www/ #代碼發佈服務器目錄 DST=/data/www/ #目標服務器目錄 IP="192.168.0.5 192.168.0.6" #目標服務器IP,多個以空格隔開 USER=root /usr/local/bin/inotifywait -mrq --timefmt '%Y-%m-%d %H:%M' --format '%T %w%f %e' --exclude "(.swp|.swx|.svn)" \ -e create,move,delete,close_write,attrib $SRC | while read files do for i in $IP do /usr/local/bin/rsync -ahqzt --exclude Runtime --delete $SRC $USER@$i:$DST echo $files >>/tmp/rsync.log 2>&1 done done
//賦權svn
//而後腳本可執行權限 chmod +x /root/inotify_rsync.sh //設置開機自啓動 ec賦予ho "/root/inotify_rsync.sh &" >> /etc/rc.local //執行腳本 /root/inotify_rsync.sh & //在代碼更新服務器的/data/www/目錄中建立文件,測試效果。 //若是調試過程出現相似libiconv.so.2的錯誤請嘗試執行以下命令: in -s/usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
// end 測試