linux系統中透過rsync+inotify實現網頁自動同步

高洛峰
發布: 2023-03-05 14:40:01
原創
996 人瀏覽過

使用多個web伺服器實現負載平衡,為了保持前端web伺服器上資源的一致性可以透過rsync在主伺服器上(可寫入資料)將更新過的檔案同步到其他從伺服器(只讀伺服器),但是無法自動的進行即時同步,使用inotify可以實現即時同步

主伺服器:192.168.6.205 inotify
從伺服器:192.168.6.36 rsync

1、在從伺服器上設定rsync,並開啟主服務,讓主服務將開啟主服務將資源同步到該伺服器上

vim /etc/rsyncd.conf
uid = nginx
gid = nginx
port = 873
host all = 192.168.6.205
use wordpress]
path = /usr/local/nginx/html/wordpress
comment = rsync files
ignore errors
read only = no
list = yes
auth users = rsyncal
sec /etc/rsync.passwd密碼設定檔
vim /etc/rsync.passwd 
#使用者:密碼
rsync:rsync

2、在主伺服器上安裝inotify-tools
.gz
cd inotify-tools-3.14
./configure –prefix=/usr/local/inotify

make && make install

在主伺服器上設定rsync密碼文件,用於將資料同步到從install


在主伺服器上設定rsync密碼文件,用於將資料同步到從install
vim//et /rsync.passwd
#密碼

rsync


建立腳本
vim inotifyrsync.sh

#!/bin/bash

host=192.168.6.36
s/bash

host=192.168.6.36

s/>>p/whic/whiw/whiw/whist
user=rsync
inotifywait=/usr/local/inotify/bin/inotifywait
rsync=/usr/bin/rsync
$inotifywait -mrq –timefmt '%d/%m/%y %H:%M'format '%T %w%f' -e modify,delete,create,attrib  $src  | while read files
do
       $rsync -vzrtopg –delete –progress –password-file=/etc/r. $host::$dst
        echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
   done

更多linux系統中透過中文PH+inotify請實現追蹤相關文章網!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!