国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Linux > 正文

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

2020-06-13 12:15:55
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
由于無(wú)存儲(chǔ)共享設(shè)備,web集群中的代碼均存放在本地,最終導(dǎo)致web節(jié)點(diǎn)之間的數(shù)據(jù)無(wú)法一致所以采用rsync+inotify,實(shí)現(xiàn)多臺(tái)web數(shù)據(jù)動(dòng)態(tài)同步,需要的朋友可以了解下
 
 

*背景:由于無(wú)存儲(chǔ)共享設(shè)備,web集群中的代碼均存放在本地,最終導(dǎo)致web節(jié)點(diǎn)之間的數(shù)據(jù)無(wú)法一致。 
*解決辦法:采用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ù)器,我們?cè)贏服務(wù)器上安裝rsync+inotify,然后將一個(gè)二級(jí)域名指向A服務(wù)器,這樣以后網(wǎng)站編輯、開(kāi)發(fā)人員之間訪問(wèn)二級(jí)域名進(jìn)行日常網(wǎng)站更新,A服務(wù)器在檢測(cè)到本地有數(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來(lái)完成數(shù)據(jù)同步,選擇rsync+inotify的理由如下 
 

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

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

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

復(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 

*加入開(kāi)機(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 


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 绥芬河市| 波密县| 利川市| 嘉义县| 浦东新区| 沁阳市| 阳城县| 淮阳县| 北海市| 中西区| 台前县| 军事| 改则县| 霍山县| 荥经县| 桐梓县| 盐山县| 抚远县| 砚山县| 上饶县| 安国市| 靖西县| 甘孜县| 岑溪市| 汽车| 革吉县| 南靖县| 隆昌县| 清原| 汾阳市| 和林格尔县| 大城县| 文成县| 车致| 鲜城| 德惠市| 兰溪市| 分宜县| 湟源县| 保康县| 乌鲁木齐县|