自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Redis哨兵模式(Sentinel)的搭建與配置

數(shù)據(jù)庫(kù) Redis
創(chuàng)建三個(gè)Redis實(shí)例所需的目錄,生產(chǎn)環(huán)境需獨(dú)立部署在不同主機(jī)上,提高穩(wěn)定性。

Redis 哨兵模式(Sentinel)是一個(gè)自動(dòng)監(jiān)控處理 redis 間故障節(jié)點(diǎn)轉(zhuǎn)移工作的一個(gè)redis服務(wù)端實(shí)例,它不提供數(shù)據(jù)存儲(chǔ)服務(wù),只進(jìn)行普通 redis 節(jié)點(diǎn)監(jiān)控管理,使用redis哨兵模式可以實(shí)現(xiàn)redis服務(wù)端故障的自動(dòng)化轉(zhuǎn)移。

一、搭建redis主從集群

1、創(chuàng)建3個(gè)redis實(shí)例

關(guān)于redis的搭建,可以參考?xì)v史文章。

?https://mp.weixin.qq.com/s/RaWy0sqRxcAti1qbv-GbZQ?

如果有編譯好的二進(jìn)制文件,則直接部署redis實(shí)例即可。

創(chuàng)建三個(gè)redis實(shí)例所需的目錄,生產(chǎn)環(huán)境需獨(dú)立部署在不同主機(jī)上,提高穩(wěn)定性。

mkdir   -p /data/redis
cd /data/redis/
mkdir redis6379 redis6380 redis6381
cd redis6379
vim redis.conf
# 添加如下配置
bind 0.0.0.0
protected-mode no
port 6379
tcp-backlog 511
timeout 30
tcp-keepalive 300
daemonize yes
supervised no
pidfile /data/redis/redis6379/redis_6379.pid
loglevel notice
logfile "/data/redis/redis6379/redis6379.log"
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis/redis6379
masterauth 123456
slave-serve-stale-data yes
slave-read-only yes
# 將配置文件拷貝到其他2個(gè)實(shí)例的目錄下
cp redis.conf ../redis6380.conf
cp redis.conf ../redis6381.conf
sed -i "s#6379#6380#g" ../redis6380/redis.conf
sed -i "s#6379#6381#g" ../redis6381/redis.conf
# redis實(shí)例不建議使用root賬號(hào)啟動(dòng),單獨(dú)創(chuàng)建一個(gè)redis用戶,并修改redis相關(guān)目錄的權(quán)限
useradd redis
chown -R redis:redis /data/redis
su - redis
# 啟動(dòng)三個(gè)redis實(shí)例
redis-server /data/redis/redis6379/redis.conf
redis-server /data/redis/redis6380/redis.conf
redis-server /data/redis/redis6381/redis.conf

2、配置主從同步

進(jìn)入2個(gè)實(shí)例,配置同步,配置完成后去主節(jié)點(diǎn)檢查一下是否正常。

[redis@test redis6379]$ redis-cli -p 6380 -a "123456"
Warning: Using a password with '-a' option on the command line interface may not be safe.
127.0.0.1:6380> slaveof 127.0.0.1 6379
OK
127.0.0.1:6380> exit
[redis@test redis6379]$ redis-cli -p 6381 -a "123456"
Warning: Using a password with '-a' option on the command line interface may not be safe.
127.0.0.1:6381> slaveof 127.0.0.1 6379
OK
127.0.0.1:6381> exit
[redis@test redis6379]$ redis-cli -p 6379 -a "123456"
Warning: Using a password with '-a' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=6380,state=online,offset=42,lag=0
slave1:ip=127.0.0.1,port=6381,state=online,offset=42,lag=1
master_replid:b8a19f5afae13d3da38b359244dc0f560df03176
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:42
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:42
127.0.0.1:6379>

可見(jiàn) 當(dāng)前主從同步已建立。

二、哨兵模式搭建

1、創(chuàng)建3個(gè)哨兵實(shí)例

mkdir -p   /data/redis/redis_sentinel/
cd /data/redis/redis_sentinel/
mkdir sentinel26379 sentinel26380 sentinel26381
cd sentinel26379
# 初始化配置文件如下
vim redis_sentinel_26379.conf
bind 0.0.0.0
port 26379
daemonize yes
dir "/data/redis/redis_sentinel/sentinel26379"
pidfile "/data/redis/redis_sentinel/sentinel26379/redis_sentinel26379.pid"
logfile "/data/redis/redis_sentinel/sentinel26379/redis_sentinel26379.log"
# Generated by CONFIG REWRITE
sentinel deny-scripts-reconfig yes
sentinel monitor testdb 127.0.0.1 6379 2
sentinel down-after-milliseconds testdb 5000
sentinel auth-pass testdb 123456
# 配置文件拷貝至另2個(gè)實(shí)例
cp redis_sentinel_26379.conf ../sentinel26380/redis_sentinel_26380.conf
sed -i "s#26379#26380#g" ../sentinel26380/redis_sentinel_26380.conf
cp redis_sentinel_26379.conf ../sentinel26381/redis_sentinel_26381.conf
sed -i "s#26379#26381#g" ../sentinel26381/redis_sentinel_26381.conf

配置文件主要參數(shù)說(shuō)明:

參數(shù)名

說(shuō)明

bind

綁定的可以訪問(wèn)的主機(jī)IP,0.0.0.0 代表不限制

port

哨兵實(shí)例的端口

sentinel monitor testdb 127.0.0.1 6379 1

testdb任意定義,哨兵集群名稱,127.0.0.1 6379 redis實(shí)例主節(jié)點(diǎn) ;1 代表當(dāng)1個(gè)哨兵實(shí)例判斷主庫(kù)不可用則進(jìn)行轉(zhuǎn)移,生產(chǎn)環(huán)境節(jié)點(diǎn)數(shù)要配置多一點(diǎn)

sentinel down-after-milliseconds testdb 5000

testdb同上,down-after-milliseconds代表 master 最長(zhǎng)響應(yīng)時(shí)間,超過(guò)這個(gè)時(shí)間就主觀判斷它下線,5000 代表5000ms,即5s

sentinel auth-pass testdb 123456

123456 是redis實(shí)例的登錄密碼

2、啟動(dòng)哨兵實(shí)例

redis-sentinel  /data/redis/redis_sentinel/sentinel26379/redis_sentinel_26379.conf 
redis-sentinel /data/redis/redis_sentinel/sentinel26380/redis_sentinel_26380.conf
redis-sentinel /data/redis/redis_sentinel/sentinel26381/redis_sentinel_26381.conf

啟動(dòng)后配置文件會(huì)自動(dòng)新增如下紅框中的內(nèi)容。

登錄哨兵實(shí)例查看。

redis-cli -p  26379

3、測(cè)試

測(cè)試將主節(jié)點(diǎn)down機(jī)。

redis-cli -p 6379 -a 123456  shutdown

再查看哨兵找那個(gè)的master結(jié)果,如下:

日志信息如下:

1895:X 29 Apr 23:57:31.778 # +sdown master testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:31.779 # +odown master testdb 127.0.0.1 6379 #quorum 1/1
1895:X 29 Apr 23:57:31.779 # +new-epoch 1
1895:X 29 Apr 23:57:31.779 # +try-failover master testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:31.795 # +vote-for-leader 4928b4d4dfd762cd50fa540b7a0903d2be3b0f95 1
1895:X 29 Apr 23:57:31.796 # +elected-leader master testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:31.796 # +failover-state-select-slave master testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:31.862 # +selected-slave slave 127.0.0.1:6380 127.0.0.1 6380 @ testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:31.862 * +failover-state-send-slaveof-noone slave 127.0.0.1:6380 127.0.0.1 6380 @ testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:31.991 * +failover-state-wait-promotion slave 127.0.0.1:6380 127.0.0.1 6380 @ testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:32.223 # +promoted-slave slave 127.0.0.1:6380 127.0.0.1 6380 @ testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:32.223 # +failover-state-reconf-slaves master testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:32.273 * +slave-reconf-sent slave 127.0.0.1:6381 127.0.0.1 6381 @ testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:33.231 * +slave-reconf-inprog slave 127.0.0.1:6381 127.0.0.1 6381 @ testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:33.231 * +slave-reconf-done slave 127.0.0.1:6381 127.0.0.1 6381 @ testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:33.296 # +failover-end master testdb 127.0.0.1 6379
1895:X 29 Apr 23:57:33.296 # +switch-master testdb 127.0.0.1 6379 127.0.0.1 6380
1895:X 29 Apr 23:57:33.297 * +slave slave 127.0.0.1:6381 127.0.0.1 6381 @ testdb 127.0.0.1 6380
1895:X 29 Apr 23:57:33.297 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ testdb 127.0.0.1 6380
1895:X 29 Apr 23:57:38.356 # +sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ testdb 127.0.0.1 6380

再把6379端口啟動(dòng),可以看到節(jié)點(diǎn)自動(dòng)加入集群,且作為從節(jié)點(diǎn)。

責(zé)任編輯:姜華 來(lái)源: 今日頭條
相關(guān)推薦

2021-03-31 05:57:40

集群搭建哨兵集群Redis

2020-02-07 09:44:30

Redis哨兵數(shù)據(jù)庫(kù)

2022-06-28 07:31:11

哨兵模式redis

2019-09-16 16:05:13

Redis集群模式

2025-01-06 13:00:00

RedisSentinel高可用模式

2021-04-01 08:50:54

SentinelRedis 集群原理

2022-11-06 21:31:11

云原生Sentinel集群模式

2024-04-29 08:06:19

Redis分布式系統(tǒng)

2020-04-14 21:12:42

Redis集群Linux

2022-02-11 08:41:19

WindowsRedis集群

2024-12-19 17:09:55

Redis哨兵模式數(shù)據(jù)庫(kù)

2023-03-15 08:30:37

2022-12-05 08:41:39

Redis調(diào)試環(huán)境源碼

2025-02-19 10:27:48

哨兵Redis故障轉(zhuǎn)移

2023-07-31 21:56:54

哨兵系統(tǒng)redis

2024-07-16 08:38:06

2022-05-16 13:46:38

Redis高可用Sentinel

2023-09-27 06:26:07

2023-10-26 07:47:53

Redis哨兵集群

2022-05-17 22:20:41

哨兵Redis機(jī)制
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)