首頁 > 運維 > linux運維 > 主體

linux如何實現網頁自動同步

PHPz
發布: 2023-05-15 16:58:21
轉載
922 人瀏覽過

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

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

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

vim /etc/rsyncd.conf
uid = nginx
#gid = nginx
port = 873
host all = 192.168.6.205
use chroot = on
max connections = 4
timeout = yes
[wordpress]
path = /usr/local/ nginx/html/wordpress
comment = rsync files
ignore errors
read only = no
list = yes
auth users = rsync
secrets file = /etc/rsync.passwd

建立/etc/rsync.passwd密碼設定檔
vim /etc/rsync.passwd
#使用者:密碼
rsync:rsync

#2、在主伺服器上安裝inotify-tools

tar -zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure –prefix=/usr/local /inotify
make && make install

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

建立腳本
vim inotifyrsync.sh

##!/bin/bash
host=192.168.6.36
src=/usr/local/nginx/html/ wordpress/
dst=wordpress
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/rsync.passwd $src $user@$host::$dst
        echo "${files} was rsynced" >>/tmp/rsync.log 2> &1
   done

以上是linux如何實現網頁自動同步的詳細內容。更多資訊請關注PHP中文網其他相關文章!

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