溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

linux系統(tǒng)中怎么實現(xiàn)網(wǎng)頁自動同步

發(fā)布時間:2022-03-23 16:44:02 來源:億速云 閱讀:218 作者:iii 欄目:web開發(fā)

這篇文章主要介紹了linux系統(tǒng)中怎么實現(xiàn)網(wǎng)頁自動同步的相關知識,內(nèi)容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇linux系統(tǒng)中怎么實現(xiàn)網(wǎng)頁自動同步文章都會有所收獲,下面我們一起來看看吧。

使用多個web服務器實現(xiàn)負載均衡,為了保持前端web服務器上資源的一致性可以通過rsync在主服務器上(可寫入數(shù)據(jù))將更新過的文件同步到其他從服務器(只讀服務器),但是不能自動的進行實時同步,使用inotify可以實現(xiàn)實時同步

主服務器: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

創(chuàng)建/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密碼文件,用于將數(shù)據(jù)同步到從服務器
vim /etc/rsync.passwd
#密碼
rsync

創(chuàng)建腳本
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

關于“l(fā)inux系統(tǒng)中怎么實現(xiàn)網(wǎng)頁自動同步”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“l(fā)inux系統(tǒng)中怎么實現(xiàn)網(wǎng)頁自動同步”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI