欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

redis-sentinel基礎(chǔ)概念及部署流程

 更新時(shí)間:2025年08月20日 10:38:03   作者:運(yùn)維經(jīng)緯(公眾號(hào))  
Redis Sentinel是Redis的高可用解決方案,通過監(jiān)控主從節(jié)點(diǎn)、自動(dòng)故障轉(zhuǎn)移、通知機(jī)制及配置提供,實(shí)現(xiàn)集群故障恢復(fù)與服務(wù)持續(xù)可用,核心組件包括Sentinel節(jié)點(diǎn)、主節(jié)點(diǎn)和從節(jié)點(diǎn),部署需配置參數(shù),驗(yàn)證主節(jié)點(diǎn)變化即成功

一. 引言

 Redis Sentinel 是 redis 官方提供的高可用解決方案,主要用于監(jiān)控 Redis 主從集群,在主節(jié)點(diǎn)故障時(shí)自動(dòng)完成故障轉(zhuǎn)移,確保服務(wù)持續(xù)可用。

二. 核心功能

  • 1. 監(jiān)控(monitoring):持續(xù)檢查主節(jié)點(diǎn)(master)和從節(jié)點(diǎn)(slave)是否正常運(yùn)行。
  • 2. 自動(dòng)故障轉(zhuǎn)移(automatic failover):當(dāng)主節(jié)點(diǎn)故障時(shí),自動(dòng)將一個(gè)從節(jié)點(diǎn)晉升為新主節(jié)點(diǎn),并讓其他從節(jié)點(diǎn)指向新主節(jié)點(diǎn)。
  • 3. 通知(notification):通過 API 向管理員或其他應(yīng)用程序發(fā)送故障通知。
  • 4. 配置提供者(configuration provider):客戶端可通過 Sentinel 獲取當(dāng)前主節(jié)點(diǎn)地址(無需硬編碼)。

三. 核心組件

  • 1. sentinel 節(jié)點(diǎn):特殊的 Redis 進(jìn)程(非數(shù)據(jù)存儲(chǔ)節(jié)點(diǎn)),通常部署 3 個(gè)及以上以保證自身高可用。
  • 2. 主節(jié)點(diǎn)(master):負(fù)責(zé)處理寫操作的 redis 節(jié)點(diǎn)。
  • 3. 從節(jié)點(diǎn)(slave):同步主節(jié)點(diǎn)數(shù)據(jù),提供讀服務(wù),主節(jié)點(diǎn)故障時(shí)可被晉升。

四. 故障轉(zhuǎn)移流程

  • 1. 多個(gè) sentinel 檢測(cè)到主節(jié)點(diǎn)故障。
  • 2. 選舉一個(gè) sentinel 作為領(lǐng)導(dǎo)者,負(fù)責(zé)執(zhí)行故障轉(zhuǎn)移。
  • 3. 從合格的從節(jié)點(diǎn)中選擇一個(gè)晉升為新主節(jié)點(diǎn)。
  • 4. 其他從節(jié)點(diǎn)切換到新主節(jié)點(diǎn)同步數(shù)據(jù)。
  • 5. 原主節(jié)點(diǎn)恢復(fù)后,作為從節(jié)點(diǎn)加入新主節(jié)點(diǎn)。

五. 服務(wù)部署

#安裝依賴
yum install make gcc

#下載安裝
wget https://download.redis.io/releases/redis-7.4.3.tar.gz
tar fxvz redis-7.4.3.tar.gz
cd redis-7.4.3
make
make install
mkdir /etc/redis-server
mkdir /etc/redis-sentinel

mkdir -p /opt/redis-log


cp redis-7.4.3/redis.conf /etc/redis-server/redis.conf

配置文件: 

################################## NETWORK #####################################
bind 127.0.0.1 10.0.43.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300

################################# GENERAL #####################################
daemonize yes
pidfile "/var/run/redis.pid"
loglevel notice
logfile "/data/redis-log/redis.log"
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
locale-collate ""

################################ SNAPSHOTTING  ################################
save 3600 1
save 300 100
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
rdb-del-sync-files no
dir "/data/redis-data"

################################# REPLICATION #################################
masterauth "rCzxxxxsN5"
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync yes
repl-diskless-sync-delay 5
repl-diskless-sync-max-replicas 0
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100

################################## SECURITY ###################################
acllog-max-len 128
requirepass "rCzxxxxsN5"

################################### CLIENTS ####################################
maxclients 10000

############################## MEMORY MANAGEMENT ################################

maxmemory 5gb
maxmemory-policy volatile-lru
maxmemory-samples 5
maxmemory-eviction-tenacity 10
replica-ignore-maxmemory yes
active-expire-effort 1

############################# LAZY FREEING ####################################
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no

################################ THREADED I/O #################################
io-threads 1
io-threads-do-reads no
############################ KERNEL OOM CONTROL ##############################
oom-score-adj no
oom-score-adj-values 0 200 800

#################### KERNEL transparent hugepage CONTROL ######################
disable-thp yes

############################## APPEND ONLY MODE ###############################
appendonly yes
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
aof-timestamp-enabled no

################################ SHUTDOWN #####################################
shutdown-timeout 10
shutdown-on-sigint default
shutdown-on-sigterm default

################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128

################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0

################################ LATENCY TRACKING ##############################
latency-tracking-info-percentiles 50 99 99.9

############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""

hz 10

dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

########################### ACTIVE DEFRAGMENTATION #######################
activedefrag no
active-defrag-ignore-bytes 100mb
active-defrag-threshold-lower 10
active-defrag-threshold-upper 100
active-defrag-cycle-min 1
active-defrag-cycle-max 25
active-defrag-max-scan-fields 1000

jemalloc-bg-thread yes



#如果是從節(jié)點(diǎn),新增replicaof ${masterip} 6379

啟動(dòng)服務(wù):

redis-server redis.conf

可通過以下指令,查看主從信息:

redis-cli -h ${masterip} -p 6379 -a ${password} info replication

六. sentinel部署配置

cp /opt/redis-7.4.3/sentinel.conf /etc/redis-sentinel/sentinel.conf

cd /etc/redis-sentinel/



#vim sentinel-26379.conf

protected-mode no
port 26379
daemonize yes
pidfile "/var/run/redis-sentinel.pid"
loglevel notice
logfile "/opt/redis-log/redis-sentinel.log"
dir "/opt/redis-sentinel"

sentinel monitor mymaster 10.0.43.1 6379 2

sentinel auth-pass mymaster rCzxxxxsN5  #master 密碼

sentinel down-after-milliseconds mymaster 30000 
acllog-max-len 128

sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

sentinel resolve-hostnames no

sentinel announce-hostnames no



#其他節(jié)點(diǎn),參考以上配置。

啟動(dòng)服務(wù):

redis-sentinel sentinel.conf

查看sentinel的狀態(tài):

redis-cli -h 172.88.19.102 -p 26379 info Sentinel

七. 驗(yàn)證

驗(yàn)證自動(dòng)切換主從:   

kill 掉master: 6379 

 

發(fā)現(xiàn)master發(fā)生變化,即成功。 延遲生效時(shí)間,取決于: sentinel down-after-milliseconds mymaster 30000 。

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Redis中序列化的兩種實(shí)現(xiàn)

    Redis中序列化的兩種實(shí)現(xiàn)

    本文主要介紹了Redis中序列化的兩種實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-07-07
  • Redis對(duì)批量數(shù)據(jù)實(shí)現(xiàn)分布式鎖的實(shí)現(xiàn)代碼

    Redis對(duì)批量數(shù)據(jù)實(shí)現(xiàn)分布式鎖的實(shí)現(xiàn)代碼

    為了防止多人多電腦同時(shí)操作一條數(shù)據(jù),我們自己開發(fā)了一個(gè)簡(jiǎn)單的基于Redis實(shí)現(xiàn)的分布式鎖,Redis對(duì)批量數(shù)據(jù)實(shí)現(xiàn)分布式鎖相關(guān)知識(shí)感興趣的朋友一起看看吧
    2022-03-03
  • RedisTemplate 實(shí)現(xiàn)基于Value 操作的簡(jiǎn)易鎖機(jī)制(示例代碼)

    RedisTemplate 實(shí)現(xiàn)基于Value 操作的簡(jiǎn)易鎖機(jī)制(示例代碼)

    本文將介紹如何使用 RedisTemplate 的 opsForValue().setIfAbsent() 方法來實(shí)現(xiàn)一種簡(jiǎn)單的鎖機(jī)制,并提供一個(gè)示例代碼,展示如何在 Java 應(yīng)用中利用這一機(jī)制來保護(hù)共享資源的訪問,感興趣的朋友跟隨小編一起看看吧
    2024-05-05
  • Redis Set 集合的實(shí)例詳解

    Redis Set 集合的實(shí)例詳解

    這篇文章主要介紹了 Redis Set 集合的實(shí)例詳解的相關(guān)資料,Redis的Set是string類型的無序集合。集合成員是唯一的,并且不重復(fù),需要的朋友可以參考下
    2017-08-08
  • redis中Could not get a resource from the pool異常及解決方案

    redis中Could not get a resource from

    這篇文章主要介紹了redis中Could not get a resource from the pool異常及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 詳解Centos7下配置Redis并開機(jī)自啟動(dòng)

    詳解Centos7下配置Redis并開機(jī)自啟動(dòng)

    本篇文章主要介紹了Centos7下配置Redis并開機(jī)自啟動(dòng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2016-11-11
  • Redis的數(shù)據(jù)過期策略和數(shù)據(jù)淘汰策略

    Redis的數(shù)據(jù)過期策略和數(shù)據(jù)淘汰策略

    本文主要介紹了Redis的數(shù)據(jù)過期策略和數(shù)據(jù)淘汰策略,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-02-02
  • Redis處理MQ消費(fèi)冪等的實(shí)現(xiàn)示例

    Redis處理MQ消費(fèi)冪等的實(shí)現(xiàn)示例

    本文主要介紹了Redis處理MQ消費(fèi)冪等的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-05-05
  • Redis緩存常用4種策略原理詳解

    Redis緩存常用4種策略原理詳解

    這篇文章主要介紹了Redis緩存常用4種策略原理詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Centos7下Redis3.2.8最新版本安裝教程

    Centos7下Redis3.2.8最新版本安裝教程

    這篇文章主要為大家詳細(xì)介紹了Centos7下Redis3.2.8最新版本的安裝教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04

最新評(píng)論