日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

redis主從配置+sentinel哨兵模式

作者:楊壯壯666 更新時間: 2022-07-10 編程語言

redis版本:redis-2.8.19.tar.gz

架構(gòu):2個節(jié)點

節(jié)點1: 10.10.10.10

節(jié)點2: 10.10.10.20

節(jié)點1部署redis實例,角色master,部署sentinel實例,監(jiān)控redis-master節(jié)點

節(jié)點2部署redis實例,角色slave ,部署sentinel實例,監(jiān)控redis-master節(jié)點

一.配置redis主從

節(jié)點1:redis-master配置

1.編譯安裝redis

Copy安裝文件到/usr目錄下:

tar zxvf redis-2.8.19.tar.gz

cd redis-2.8.19

Make

2.更改redis.conf配置文件

daemonize no 改為 yes #后臺運行

節(jié)點2:redis-slave配置

1.編譯安裝redis

Copy安裝文件到/usr目錄下:

tar zxvf redis-2.8.19.tar.gz

cd redis-2.8.19

Make

2.更改redis.conf配置文件

daemonize no 改為 yes #后臺運行

slaveof 10.10.10.10 6379 #指向master服務(wù)器IP、端口

啟動redis-master

# src/redis-server -p 6379 redis.conf -h 10.10.10.10

啟動redis-slave

# src/redis-server -p 6379 redis.conf -h 10.10.10.20

查看redis-master運行信息

# src/redis-cli -h 10.10.10.10 -p 6379 info replication

# Replication

role:master

connected_slaves:1

slave0:ip=10.10.10.20,port=6379,state=online,offset=69298006,lag=0

master_repl_offset:69298143

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:68249568

repl_backlog_histlen:1048576

查看redis-slave運行信息

# src/redis-cli -h 10.10.10.20 -p 6379 info replication

# Replication

role:slave

master_host:10.10.10.10

master_port:6379

master_link_status:up

master_last_io_seconds_ago:0

master_sync_in_progress:0

slave_repl_offset:69302158

slave_priority:100

slave_read_only:1

connected_slaves:0

master_repl_offset:0

repl_backlog_active:0

repl_backlog_size:1048576

repl_backlog_first_byte_offset:0

repl_backlog_histlen:0

測試主從復(fù)制

redis-master

# src/redis-cli -p 6379 -h 10.10.10.10

10.10.10.10:6379> set name 123

OK

10.10.10.10:6379> get name "123"

Redis-slave

# src/redis-cli -p 6379 -h 10.10.10.20

10.10.10.20:6379> get name "123"

二.配置sentinel哨兵模式

1.配置sentinel.conf配置文件

2個sentinel實例配置相同mastername mymaster

port 26379

sentinel monitor mymaster 10.10.10.10 6379 1

啟動redis-master上的sentinel

src/redis-sentinel sentinel.conf -h 10.10.10.10 &

啟動redis-slave上的sentinel

src/redis-sentinel sentinel.conf -h 10.10.10.20 &

查看redis-master上的sentinel運行信息,端口不可省略

# src/redis-cli ?-h 10.10.10.10 -p 26379 info sentinel

# Sentinel

sentinel_masters:1

sentinel_tilt:0

sentinel_running_scripts:0

sentinel_scripts_queue_length:0

master0:name=mymaster,status=ok,address=10.10.10.10:6379,slaves=1,sentinels=2

查看redis-slave上的sentinel運行信息,端口不可省略

# src/redis-cli ?-h 10.10.10.20 -p 26379 info sentinel

# Sentinel

sentinel_masters:1

sentinel_tilt:0

sentinel_running_scripts:0

sentinel_scripts_queue_length:0

master0:name=mymaster,status=ok,address=10.10.10.10:6379,slaves=1,sentinels=2?

2.驗證sentinel切換主從

# src/redis-cli ?-h 10.10.10.10 shutdown

查看redis-master上的sentinel運行信息

# src/redis-cli ?-h 10.10.10.10 -p 26379 info sentinel

# Sentinel

sentinel_masters:1

sentinel_tilt:0

sentinel_running_scripts:0

sentinel_scripts_queue_length:0

master0:name=mymaster,status=ok,address=10.10.10.20:6379,slaves=1,sentinels=2?

查看redis-slave上的sentinel運行信息

?# # src/redis-cli ?-h 10.10.10.20 -p 26379 info sentinel

# Sentinel

sentinel_masters:1

sentinel_tilt:0

sentinel_running_scripts:0

sentinel_scripts_queue_length:0

master0:name=mymaster,status=ok,address=10.10.10.20:6379,slaves=1,sentinels=2

原文鏈接:https://blog.csdn.net/weixin_49889731/article/details/125688679

欄目分類
最近更新