濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > rsync+inotify實(shí)現(xiàn)多臺(tái)web數(shù)據(jù)動(dòng)態(tài)同步操作步驟

rsync+inotify實(shí)現(xiàn)多臺(tái)web數(shù)據(jù)動(dòng)態(tài)同步操作步驟

熱門標(biāo)簽:地圖標(biāo)注小區(qū)項(xiàng)目入駐 曲阜地圖標(biāo)注app 哪個(gè)地圖標(biāo)注更清晰 漳州外呼系統(tǒng)怎么樣 內(nèi)蒙古電信外呼系統(tǒng) 天津人工電銷機(jī)器人費(fèi)用 凱立德劇院地圖標(biāo)注 4s店如何在百度地圖標(biāo)注 開封400電話辦理價(jià)格

*背景:由于無存儲(chǔ)共享設(shè)備,web集群中的代碼均存放在本地,最終導(dǎo)致web節(jié)點(diǎn)之間的數(shù)據(jù)無法一致。
*解決辦法:采用rsync+inotify,實(shí)現(xiàn)多臺(tái)web數(shù)據(jù)動(dòng)態(tài)同步
*解決思路:比如有a、b、c、d四臺(tái)web,為解決哪臺(tái)服務(wù)器為源數(shù)據(jù)服務(wù)器,我們在A服務(wù)器上安裝rsync+inotify,然后將一個(gè)二級域名指向A服務(wù)器,這樣以后網(wǎng)站編輯、開發(fā)人員之間訪問二級域名進(jìn)行日常網(wǎng)站更新,A服務(wù)器在檢測到本地有數(shù)據(jù)更新時(shí),便動(dòng)態(tài)(觸發(fā)式)向其它服務(wù)器發(fā)送更新數(shù)據(jù)。
*注意:一定要使用rsync相同的版本,否則會(huì)出現(xiàn)未知錯(cuò)誤。
*選擇rsync+inotify的理由:在常規(guī)的數(shù)據(jù)同步應(yīng)用案例中,大多數(shù)人會(huì)選擇使用rsync來完成數(shù)據(jù)同步,選擇rsync+inotify的理由如下

復(fù)制代碼
代碼如下:

1、服務(wù)器性能:rsync只能實(shí)現(xiàn)定時(shí)更新,無論網(wǎng)站有無文件更新,rsync都會(huì)按著定時(shí)任務(wù)去檢查文件是否有更新,當(dāng)數(shù)據(jù)文件較大時(shí)會(huì)使服務(wù)器性能下降;而rsync+inotify
為觸發(fā)式更新,也就是說只有當(dāng)某個(gè)文件發(fā)生改動(dòng)時(shí)才會(huì)更新,這樣一來對服務(wù)器性能影響較小。
2、數(shù)據(jù)實(shí)時(shí)性:如果選擇rsync,每隔多長時(shí)間同步一次數(shù)據(jù)是個(gè)問題,時(shí)間越短,對性能影響就越大。時(shí)間太長,用戶/編輯無法接受。采用rsync+inotify可實(shí)現(xiàn)實(shí)時(shí)更新,
當(dāng)A服務(wù)器文件有更新時(shí),其它服務(wù)器立即更新

*環(huán)境拓?fù)?

復(fù)制代碼
代碼如下:

A:192.168.1.101
B:192.168.1.102
C:192.168.1.103
D:192.168.1.104
注:數(shù)據(jù)源服務(wù)器為A,目標(biāo)服務(wù)器為B、C、D

*一、目標(biāo)服務(wù)器安裝rsync (在B、C、D服務(wù)器上操作,安裝配置均一樣)
*安裝rsync 下載地址:http://rsync.samba.org/

復(fù)制代碼
代碼如下:

cd /data/software
wget https://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz
tar zxvf rsync-3.0.9.tar.gz
cd rsync-3.0.9
./configure
make
make install

*安裝完成后顯示信息

復(fù)制代碼
代碼如下:

mkdir -p /usr/local/bin
/usr/bin/install -c -m 755 rsync /usr/local/bin
mkdir -p /usr/local/share/man/man1
mkdir -p /usr/local/share/man/man5
if test -f rsync.1; then /usr/bin/install -c -m 644 rsync.1 /usr/local/share/man/man1; fi
if test -f rsyncd.conf.5; then /usr/bin/install -c -m 644 rsyncd.conf.5 /usr/local/share/man/man5; fi

*配置rsync
*#vi /etc/rsync.conf 加入如下內(nèi)容

復(fù)制代碼
代碼如下:

uid = root
gid = root
use chroot = no
max connections = 20
strict modes = yes
log file = /data/logs/rsyncd/rsyncd.log
pid file = /data/logs/rsyncd/rsyncd.pid
lock file = /data/logs/rsyncd/rsync.lock
log format = %t %a %m %f %b
[web]
path = /data/vhosts/it121net/
auth users = username
read only = no
hosts allow = 192.168.1.0/24 #可以是IP段,也可以是IP地址
list = no
uid = root
gid = root
secrets file = /etc/rsync.passwd
ignore errors = yes

*創(chuàng)建目錄,用于存放日志。

復(fù)制代碼
代碼如下:

mkdir /data/logs/rsyncd

*創(chuàng)建認(rèn)證
*#vi /etc/rsync.passwd

復(fù)制代碼
代碼如下:

username:passwd

*#chmod 600 /etc/rsync.passwd
*啟動(dòng)rsync,啟動(dòng)后使用netstat查看,會(huì)發(fā)現(xiàn)系統(tǒng)已啟動(dòng)873端口

復(fù)制代碼
代碼如下:

# rsync --daemon --config=/etc/rsync.conf

*加入開機(jī)啟動(dòng)

復(fù)制代碼
代碼如下:

# echo "rsync --daemon --config=/etc/rsync.conf" >>/etc/rc.local

*關(guān)閉

復(fù)制代碼
代碼如下:

killall rsync

*二、源服務(wù)器安裝rsync+inotify (在a服務(wù)器上操作)
*安裝rsync(僅安裝即可,不需配置)

復(fù)制代碼
代碼如下:

cd /data/software
wget https://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz
tar zxvf rsync-3.0.9.tar.gz
cd rsync-3.0.9
./configure
make
make install

*echo "passwd" > /etc/rsync-client.passwd
*chmod 600 /etc/rsync-client.passwd
*安裝inotify 下載地址:https://github.com/rvoicilas/inotify-tools/wiki/

復(fù)制代碼
代碼如下:

cd /data/software
wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure
make
make install

*創(chuàng)建啟動(dòng)腳本
*#vi /etc/rsync-web.sh 加入如下內(nèi)容

復(fù)制代碼
代碼如下:

#!/bin/sh
SRC=/data/vhosts/it121net/
DES=web
WEB2=192.168.1.102
WEB3=192.168.1.103
WEB4=192.168.1.104
USER=username
/usr/local/bin/inotifywait -mrq -e create,move,delete,modify $SRC | while read D E F
do
rsync -ahqzt --password-file=/etc/rsync-client.passwd --delete $SRC $USER@$WEB2::$DES
rsync -ahqzt --password-file=/etc/rsync-client.passwd --delete $SRC $USER@$WEB3::$DES
rsync -ahqzt --password-file=/etc/rsync-client.passwd --delete $SRC $USER@$WEB4::$DES
done
#注意:網(wǎng)絡(luò)上面大部分都是顯示一個(gè)中杠,可能是編碼的事情,實(shí)際是應(yīng)該是兩個(gè)杠。

*增加權(quán)限

復(fù)制代碼
代碼如下:

#chmod +x /etc/rsync-web.sh

*啟動(dòng)腳本

復(fù)制代碼
代碼如下:

#nohup /etc/rsync-web.sh //必須使用nohup放入后臺(tái)執(zhí)行,否則關(guān)閉終端后此腳本進(jìn)程會(huì)自動(dòng)結(jié)束
/etc/rsync-web.sh

*關(guān)閉腳本

復(fù)制代碼
代碼如下:

sudo pkill rsync
sudo pkill inotifywait

*@ERROR: chdir failed rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]解決辦法

復(fù)制代碼
代碼如下:

setsebool -P rsync_disable_trans on

*rsync安裝路徑(注意查看)

復(fù)制代碼
代碼如下:

/usr/bin/rsync
/usr/local/bin/rsync
/etc/xinetd.d/rsync

標(biāo)簽:南京 陽泉 開封 綿陽 黔南 莆田 南陽 武漢

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《rsync+inotify實(shí)現(xiàn)多臺(tái)web數(shù)據(jù)動(dòng)態(tài)同步操作步驟》,本文關(guān)鍵詞  rsync+inotify,實(shí)現(xiàn),多臺(tái),web,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《rsync+inotify實(shí)現(xiàn)多臺(tái)web數(shù)據(jù)動(dòng)態(tài)同步操作步驟》相關(guān)的同類信息!
  • 本頁收集關(guān)于rsync+inotify實(shí)現(xiàn)多臺(tái)web數(shù)據(jù)動(dòng)態(tài)同步操作步驟的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    碌曲县| 临潭县| 许昌县| 商洛市| 裕民县| 井陉县| 焦作市| 宁强县| 新宁县| 安义县| 建德市| 莱西市| 惠州市| 新干县| 梨树县| 闵行区| 上犹县| 鞍山市| 满洲里市| 玉林市| 贞丰县| 千阳县| 垣曲县| 岳阳县| 治多县| 乌拉特中旗| 闽侯县| 翁牛特旗| 玉环县| 久治县| 阿鲁科尔沁旗| 崇文区| 湖口县| 许昌县| 资阳市| 温泉县| 河西区| 桓仁| 三河市| 交城县| 高清|