IT小栈

  • 主页
  • Java基础
  • RocketMQ
  • Kafka
  • Redis
  • Shiro
  • Spring
  • Spring Boot
  • Spring Cloud
  • 资料链接
  • 关于
所有文章 友链

IT小栈

  • 主页
  • Java基础
  • RocketMQ
  • Kafka
  • Redis
  • Shiro
  • Spring
  • Spring Boot
  • Spring Cloud
  • 资料链接
  • 关于

Redis哨兵模式安装部署

2020-04-09

Redis的部署方式有和多种,一般有单节点模式、主从模式、哨兵模式、集群模式等,一般生产环境中以哨兵模式和集群模式为主,哨兵模式是对主从模式的一种优化升级Redis在2.8版本中提供Sentinel。Redis Sentinel是Redis高可用(HA)的实现方案。

1、环境准备

下载地址:http://download.redis.io/releases/

版本:redis-5.0.5.tar.gz

IP 端口 角色
192.168.115.243 6379 主节点
192.168.115.243 6380 从节点
192.168.115.243 6381 从节点
192.168.115.243 26379 哨兵节点-1
192.168.115.243 26380 哨兵节点-2
192.168.115.243 26381 哨兵节点-3

2、主从数据节点

2.1、安装Redis

创建安装目录

1
mkdir /usr/local/redis-sentinel

上传redis-5.0.5.tar.gz安装包到新创建的目录下,解压安装包到当前目录

1
tar -zxvf redis-5.0.5.tar.gz

编译、安装到/usr/local/redis-sentinel目录下

1
2
3
cd /usr/local/redis-sentinel/redis-5.0.5
make
make PREFIX=/usr/local/redis-sentinel install

2.2、配置主节点

创建配置文件目录

1
2
3
4
mkdir -p /usr/local/redis-sentinel/conf
mkdir -p /usr/local/redis-sentinel/data
mkdir -p /usr/local/redis-sentinel/logs
cp redis.conf /usr/local/redis-sentinel/conf/redis-6379.conf

修改主节点的配置文件

1
2
cd /usr/local/redis-sentinel/conf
vi redis-6379.conf
1
2
3
4
5
6
7
bind 0.0.0.0
port 6379
daemonize yes
pidfile /var/run/redis_6379.pid
logfile "/usr/local/redis-sentinel/logs/redis_6379.log"
dbfilename "dump-6379.rdb"
dir "/usr/local/redis-sentinel/data"

2.3、配置两个从节点

修改从节点的配置文件

1
2
3
cd /usr/local/redis-sentinel/conf/
cp redis-6379.conf redis-6380.conf
cp redis-6379.conf redis-6381.conf

6380从节点配置

1
2
3
4
5
6
7
8
bind 0.0.0.0
port 6380
daemonize yes
pidfile /var/run/redis_6380.pid
logfile "/usr/local/redis-sentinel/logs/redis_6380.log"
dbfilename "dump-6380.rdb"
dir "/usr/local/redis-sentinel/data"
slaveof 192.168.115.243 6379

6381从节点配置

1
2
3
4
5
6
7
8
bind 0.0.0.0
port 6381
daemonize yes
pidfile /var/run/redis_6381.pid
logfile "/usr/local/redis-sentinel/logs/redis_6381.log"
dbfilename "dump-6381.rdb"
dir "/usr/local/redis-sentinel/data"
slaveof 192.168.115.243 6379

2.4、启动三个节点

1
2
3
4
cd /usr/local/redis-sentinel/bin/
./redis-server ../conf/redis-6379.conf
./redis-server ../conf/redis-6380.conf
./redis-server ../conf/redis-6381.conf

查看主从关系

1
./redis-cli -h 192.168.115.243 -p 6379 info replication

至此redis的主从模式就已经部署成功

3、哨兵节点部署

三个哨兵节点的配置是一样的

1
2
3
4
[root@node3 redis-5.0.5]# cd /usr/local/redis-sentinel/redis-5.0.5
[root@node3 redis-5.0.5]# cp sentinel.conf ../conf/sentinel-26379.conf
[root@node3 redis-5.0.5]# cp sentinel.conf ../conf/sentinel-26380.conf
[root@node3 redis-5.0.5]# cp sentinel.conf ../conf/sentinel-26381.conf

配置26379

1
2
3
4
5
6
7
port 26379
daemonize yes
pidfile /var/run/redis-sentinel-26379.pid
logfile "/usr/local/redis-sentinel/logs/sentinel-26379.log"
sentinel monitor mymaster 192.168.115.243 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster sentinel failover-timeout mymaster 180000

配置26380

1
2
3
4
5
6
7
port 26380
daemonize yes
pidfile /var/run/redis-sentinel-26380.pid
logfile "/usr/local/redis-sentinel/logs/sentinel-26380.log"
sentinel monitor mymaster 192.168.115.243 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster sentinel failover-timeout mymaster 180000

配置26381

1
2
3
4
5
6
7
port 26381
daemonize yes
pidfile /var/run/redis-sentinel-26381.pid
logfile "/usr/local/redis-sentinel/logs/sentinel-26381.log"
sentinel monitor mymaster 192.168.115.243 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster sentinel failover-timeout mymaster 180000

启动三个哨兵节点

1
2
3
4
cd /usr/local/redis-sentinel/bin/
./redis-sentinel ../conf/sentinel-26379.conf
./redis-sentinel ../conf/sentinel-26380.conf
./redis-sentinel ../conf/sentinel-26381.conf

查看状态

1
./redis-cli -h 192.168.115.243 -p 26379 info Sentinel

我们看到一主2从3个哨兵节点

4、验证

故障转移,模拟master端自动down掉,为此,这边直接使用kill命令演示

杀掉master节点

查看6380节点的日志信息

查看6381节点的日志信息

本文作者: 顾 明 训
本文链接: https://www.itzones.cn/2020/04/09/Redis哨兵模式安装部署/
版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!
  • redis
  • redis

扫一扫,分享到微信

微信分享二维码
Redis集群模式安装部署
Kafka认证授权
  1. 1. 1、环境准备
  2. 2. 2、主从数据节点
    1. 2.1. 2.1、安装Redis
    2. 2.2. 2.2、配置主节点
    3. 2.3. 2.3、配置两个从节点
    4. 2.4. 2.4、启动三个节点
  3. 3. 3、哨兵节点部署
  4. 4. 4、验证
© 2020 IT小栈
载入天数...载入时分秒... || 本站总访问量次 || 本站访客数人次
Hexo Theme Yilia by Litten
  • 所有文章
  • 友链

tag:

  • jvm
  • Java基础
  • kafka HW
  • kafka Leader Epoch
  • kafka
  • kafka位移主题
  • kafka位移提交
  • kafka副本机制
  • kafka ISR
  • zookeeper
  • kafka消息丢失
  • kafka日志存储
  • kafka Log Clean
  • kafka Log Compaction
  • kafka消费位移设置
  • kafka Rebalance
  • kafka分区算法
  • kafka生产者拦截器
  • kafka SASL/SCRAM
  • kafka ACL
  • redis
  • redis Ziplist
  • redis Hashtable
  • redis LinkedList
  • redis QuickList
  • redis intset
  • redis String
  • redis SDS
  • redis SkipList
  • redisDb
  • redisServer
  • redis 简介
  • Redis Cluster
  • 主从同步
  • RocketMQ高可用HA
  • 事务消息
  • 内存映射
  • MMAP
  • 同步刷盘
  • 异步刷盘
  • 消息存储文件
  • RocketMQ安装
  • 延迟消息
  • RocketMQ入门
  • 推拉模式
  • PushConsumer
  • 消费结果处理
  • rebalance
  • RocketMQ权限控制
  • RocketMQ ACL
  • 消息过滤
  • 消息重试
  • 消费位置
  • 集群消费
  • 广播消费
  • 运维命令
  • shiro源码分析
  • shiro入门
  • IOC和DI
  • Spring创建Bean
  • Bean生命周期
  • Sping属性注入
  • 异常
  • SpringMVC
  • springCloud
  • Eureka

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • 我的OSCHINA
  • 我的CSDN
  • 我的GITHUB
  • 一生太水