本文主要介紹Redis replication 主從復制原理和配置及基本操作 等
成都創(chuàng)新互聯(lián)服務項目包括元寶山網(wǎng)站建設、元寶山網(wǎng)站制作、元寶山網(wǎng)頁制作以及元寶山網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,元寶山網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到元寶山省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!主要參考官方文檔:
/tupian/20230521/
/tupian/20230521/replication.html
一.原理
This system works using three main mechanisms:
系統(tǒng)工作的三個主要機制:
1. When a master and a slave instances are well-connected, the master keeps the slave updated by sending a stream of commands to the slave, in order to replicate the effects on the dataset happening in the master side due to: client writes, keys expired or evicted, any other action changing the master dataset.
當master和slave實例連接良好時,master通過從slave發(fā)送命令流來更新slave
2. When the link between the master and the slave breaks, for network issues or because a timeout is sensed in the master or the slave, the slave reconnects and attempts to proceed with a partial resynchronization: it means that it will try to just obtain the part of the stream of commands it missed during the disconnection.
當master和slave連接中斷時,因為網(wǎng)絡故障或者感知到master或者slave超時。Slave重連并試圖進行重新同步:意味著獲取失去連接時丟失的命令流
3. When a partial resynchronization is not possible, the slave will ask for a full resynchronization. This will involve a more complex process in which the master needs to create a snapshot of all its data, send it to the slave, and then continue sending the stream of commands as the dataset changes.
當無法重新部分同步(partial resynchronization)時,slave將要求完全重新同步(full resynchronization)。它將包含一個復雜過程,這過程中master需要為所有數(shù)據(jù)創(chuàng)建一個快照,發(fā)送到slave,再繼續(xù)對變化的數(shù)據(jù)發(fā)送命令流
數(shù)據(jù)安全性概念
Redis的持久化存儲主要提供兩種方式:RDB與AOF
/tupian/20230521/persistence.html
1. RDB(Snapshot)模式
是默認的,即保存某一時刻的數(shù)據(jù)到硬盤,在下一次觸發(fā)snapshot前如果服務器crash,在上次snapshot之后修改的數(shù)據(jù)會丟失。
主要配置redis.conf參數(shù):
save <seconds> <changes>
stop-writes-on-bgsave-error yes
rdbcompression yes
dbfilename dump.rdb
dir ./
參數(shù)說明:
save <seconds> <changes>:在X秒內(nèi)如果key有至少X次改變就觸發(fā)持久化,例如save 900 1的話就是在900秒如果key有至少1次改變就觸發(fā)持久化。如果想關閉此功能的話,可以把全部save行都注釋或刪除或者使用save ""。
stop-writes-on-bgsave-error:在bgsave遇到error的時候是否停止持久化,默認是yes代表是,no代表不是
rdbcompression:是否壓縮,默認是yes代表是,no代表不是,如果想節(jié)省CPU的話就設為no,但rdb文件會比較大
dbfilename:持久化的文件名字,默認是dump.rdb
dir:持久化的目錄名字,默認是redis.conf所在的目錄./
2.AOF(append-only file)模式
需要手動開啟,開啟后以追加的方式默認每秒鐘將記錄的修改操作保存到硬盤
主要配置redis.conf參數(shù):
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
dir ./
### 以下rewrite參數(shù),AOF模式以追加方式記錄所有寫操作命令到硬盤,文件會越來越大,為緩解這種問題,redis使用了BGREWRITEAOF用于刪除重復多余的寫命令,類似BGSAVE,rewrite的時候會刪除舊的AOF文件
###
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
參數(shù)說明:
appendonly:是否啟動aof,默認是no代表不啟用
appendfilename:aof的文件名,默認是appendonly.aof
appendfsync:觸發(fā)的間隔,默認是everysec代表每秒,還可使用always代表有改變都觸發(fā),性能差些但數(shù)據(jù)最安全,no代表讓OS自己決定什么時候執(zhí)行,性能最好但數(shù)據(jù)不安全
dir:持久化的目錄名字,默認是redis.conf所在的目錄./
no-appendfsync-on-rewrite:執(zhí)行rewrite時appendfsync是否暫停,默認no代表不暫停
auto-aof-rewrite-percentage:aof rewrite觸發(fā)時機,當前aof文件大小超過上一次rewrite后aof文件的百分比后觸發(fā)rewrite。如200,即當前的aof文件超過上一次重寫后aof文件的2倍時才會再次rewrite
auto-aof-rewrite-min-size aof文件重寫最小文件大小,即最開始aof文件必須要達到這個文件時才觸發(fā),后面的每次重寫就不會根據(jù)這個變量了(根據(jù)上一次重寫完成之后的大小).此變量僅初始化啟動redis有效.如果是redis恢復時,則lastSize等于初始aof文件大小.
當前題目:Redisreplication主從復制原理及配置-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://www.rwnh.cn/article2/dcieoc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、App開發(fā)、標簽優(yōu)化、微信小程序、企業(yè)建站、網(wǎng)站維護
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容