文档章节

redis集群--多哨兵模式搭建

码上青天
 码上青天
发布于 02/26 16:16
字数 1541
阅读 53
收藏 5
  • 本文目标

本文记录redis集群多哨兵的搭建和测试。

  • 安装准备

centos版本:6.7

redis版本:3.2.3

安装方式:源码安装

  • 操作步骤

    6379为主节点,6389和6399为从节点; 26379,26479,26579为哨兵节点。

1、redis.conf配置

主的保持默认的不变

二个从的分别打开配置文件

找到设置端口的地方

分别设置为 6389 和6399

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6389
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6399
然后都在

# slaveof <masterip> <masterport>
一行的下面增加

slaveof 127.0.0.1 6379
这样主从的配置就ok了

2、sentinel.conf

分别打开sentinel.conf配置文件

修改他们的端口为

 26379 26479 26579

sentinel monitor mymaster 127.0.0.1 6379 2
配置中的这一行表示 我们要监视的主的ip和端口,mymaster是主的名称,因为我们的主是127.0.0.1:6379,所以三个哨兵中的这个地方都不用修改。

3、启动每个服务

redis-server /usr/local/redis_cluster/6379.conf
redis-server /usr/local/redis_cluster/6389.conf
redis-server /usr/local/redis_cluster/6399.conf
redis-sentinel /usr/local/redis_cluster/26379.conf
redis-sentinel /usr/local/redis_cluster/26479.conf
redis-sentinel /usr/local/redis_cluster/26579.conf

4、测试

4.1 正常情况

哨兵26379

[root@itsecond src]# redis-sentinel /usr/local/redis_cluster/26379.conf
3259:X 26 Feb 22:40:12.836 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379
 |    `-._   `._    /     _.-'    |     PID: 3259
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

3259:X 26 Feb 22:40:12.838 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
3259:X 26 Feb 22:40:12.847 # Sentinel ID is 7d47930e60e1fcdc5099efdd614472372ae3ffad
3259:X 26 Feb 22:40:12.847 # +monitor master mymaster 127.0.0.1 6379 quorum 2
3259:X 26 Feb 22:40:12.847 * +slave slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6379
3259:X 26 Feb 22:40:12.848 * +slave slave 127.0.0.1:6399 127.0.0.1 6399 @ mymaster 127.0.0.1 6379
3259:X 26 Feb 22:40:18.897 * +sentinel sentinel 297ee9394b66ca80fae2d6605311d346765a9901 127.0.0.1 26479 @ mymaster 127.0.0.1 6379
3259:X 26 Feb 22:40:21.280 * +sentinel sentinel 337468c9cc89e34a76519a7a370946f2c7529ff3 127.0.0.1 26579 @ mymaster 127.0.0.1 6379

哨兵26479

[root@itsecond src]# redis-sentinel /usr/local/redis_cluster/26479.conf
3262:X 26 Feb 22:40:16.820 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26479
 |    `-._   `._    /     _.-'    |     PID: 3262
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

3262:X 26 Feb 22:40:16.821 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
3262:X 26 Feb 22:40:16.830 # Sentinel ID is 297ee9394b66ca80fae2d6605311d346765a9901
3262:X 26 Feb 22:40:16.830 # +monitor master mymaster 127.0.0.1 6379 quorum 2
3262:X 26 Feb 22:40:16.831 * +slave slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6379
3262:X 26 Feb 22:40:16.832 * +slave slave 127.0.0.1:6399 127.0.0.1 6399 @ mymaster 127.0.0.1 6379
3262:X 26 Feb 22:40:16.951 * +sentinel sentinel 7d47930e60e1fcdc5099efdd614472372ae3ffad 127.0.0.1 26379 @ mymaster 127.0.0.1 6379
3262:X 26 Feb 22:40:21.280 * +sentinel sentinel 337468c9cc89e34a76519a7a370946f2c7529ff3 127.0.0.1 26579 @ mymaster 127.0.0.1 6379

哨兵26579

[root@itsecond src]# redis-sentinel /usr/local/redis_cluster/26579.conf
3265:X 26 Feb 22:40:19.276 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26579
 |    `-._   `._    /     _.-'    |     PID: 3265
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

3265:X 26 Feb 22:40:19.277 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
3265:X 26 Feb 22:40:19.287 # Sentinel ID is 337468c9cc89e34a76519a7a370946f2c7529ff3
3265:X 26 Feb 22:40:19.287 # +monitor master mymaster 127.0.0.1 6379 quorum 2
3265:X 26 Feb 22:40:19.288 * +slave slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 22:40:19.288 * +slave slave 127.0.0.1:6399 127.0.0.1 6399 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 22:40:20.928 * +sentinel sentinel 297ee9394b66ca80fae2d6605311d346765a9901 127.0.0.1 26479 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 22:40:21.058 * +sentinel sentinel 7d47930e60e1fcdc5099efdd614472372ae3ffad 127.0.0.1 26379 @ mymaster 127.0.0.1 6379

4.2 从机宕机与恢复

哨兵的反应

#宕机
3259:X 26 Feb 22:59:34.700 # +sdown slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6379
#恢复
3259:X 26 Feb 23:02:40.808 * +reboot slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6379
3259:X 26 Feb 23:02:40.867 # -sdown slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6379

4.3主机宕机

哨兵26379

3259:X 26 Feb 23:03:44.035 # +sdown master mymaster 127.0.0.1 6379
3259:X 26 Feb 23:03:44.072 # +new-epoch 1
3259:X 26 Feb 23:03:44.074 # +vote-for-leader 337468c9cc89e34a76519a7a370946f2c7529ff3 1
3259:X 26 Feb 23:03:44.125 # +odown master mymaster 127.0.0.1 6379 #quorum 3/2
3259:X 26 Feb 23:03:44.125 # Next failover delay: I will not start a failover before Mon Feb 26 23:09:44 2018
3259:X 26 Feb 23:03:44.382 # +config-update-from sentinel 337468c9cc89e34a76519a7a370946f2c7529ff3 127.0.0.1 26579 @ mymaster 127.0.0.1 6379
3259:X 26 Feb 23:03:44.382 # +switch-master mymaster 127.0.0.1 6379 127.0.0.1 6399
3259:X 26 Feb 23:03:44.383 * +slave slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6399
3259:X 26 Feb 23:03:44.383 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6399
3259:X 26 Feb 23:04:14.402 # +sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6399

哨兵26479

3262:X 26 Feb 23:03:43.949 # +sdown master mymaster 127.0.0.1 6379
3262:X 26 Feb 23:03:44.071 # +new-epoch 1
3262:X 26 Feb 23:03:44.072 # +vote-for-leader 337468c9cc89e34a76519a7a370946f2c7529ff3 1
3262:X 26 Feb 23:03:44.385 # +config-update-from sentinel 337468c9cc89e34a76519a7a370946f2c7529ff3 127.0.0.1 26579 @ mymaster 127.0.0.1 6379
3262:X 26 Feb 23:03:44.385 # +switch-master mymaster 127.0.0.1 6379 127.0.0.1 6399
3262:X 26 Feb 23:03:44.385 * +slave slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6399
3262:X 26 Feb 23:03:44.385 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6399
3262:X 26 Feb 23:04:14.432 # +sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6399

哨兵26579

3265:X 26 Feb 23:03:43.995 # +sdown master mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:44.068 # +odown master mymaster 127.0.0.1 6379 #quorum 2/2
3265:X 26 Feb 23:03:44.068 # +new-epoch 1
3265:X 26 Feb 23:03:44.068 # +try-failover master mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:44.070 # +vote-for-leader 337468c9cc89e34a76519a7a370946f2c7529ff3 1
3265:X 26 Feb 23:03:44.073 # 297ee9394b66ca80fae2d6605311d346765a9901 voted for 337468c9cc89e34a76519a7a370946f2c7529ff3 1
3265:X 26 Feb 23:03:44.074 # 7d47930e60e1fcdc5099efdd614472372ae3ffad voted for 337468c9cc89e34a76519a7a370946f2c7529ff3 1
3265:X 26 Feb 23:03:44.170 # +elected-leader master mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:44.170 # +failover-state-select-slave master mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:44.223 # +selected-slave slave 127.0.0.1:6399 127.0.0.1 6399 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:44.223 * +failover-state-send-slaveof-noone slave 127.0.0.1:6399 127.0.0.1 6399 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:44.282 * +failover-state-wait-promotion slave 127.0.0.1:6399 127.0.0.1 6399 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:44.286 # +promoted-slave slave 127.0.0.1:6399 127.0.0.1 6399 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:44.286 # +failover-state-reconf-slaves master mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:44.382 * +slave-reconf-sent slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:45.193 # -odown master mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:45.330 * +slave-reconf-inprog slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:45.330 * +slave-reconf-done slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:45.412 # +failover-end master mymaster 127.0.0.1 6379
3265:X 26 Feb 23:03:45.412 # +switch-master mymaster 127.0.0.1 6379 127.0.0.1 6399
3265:X 26 Feb 23:03:45.413 * +slave slave 127.0.0.1:6389 127.0.0.1 6389 @ mymaster 127.0.0.1 6399
3265:X 26 Feb 23:03:45.413 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6399
3265:X 26 Feb 23:04:15.473 # +sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6399

4.4主机恢复

哨兵26379的反应

3259:X 26 Feb 23:35:29.084 # -sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6399
3259:X 26 Feb 23:35:39.082 * +convert-to-slave slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6399

哨兵26479和26579的反应

3262:X 26 Feb 23:35:29.358 # -sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6399

 

© 著作权归作者所有

共有 人打赏支持
码上青天
粉丝 14
博文 29
码字总数 21602
作品 0
杭州
程序员
redis集群--单哨兵模式搭建

本文目标 本文记录redis集群单哨兵的搭建和测试。 安装准备 centos版本:6.7 redis版本:3.2.3 安装方式:源码安装 操作步骤 6379为主节点,6479和6579为从节点; 26379为哨兵节点。 1、创建...

码上青天
02/24
10
0
通用Redis架构+实用辅助工具,逐一攻破DBA痛难点!

今天将和大家介绍常见的Redis架构、以往我在陌陌、去哪儿网做Redis时的一些经验,主要包括DBA日常维护MySQL或Redis时需要做的工作、如何根据日常工作和业务的需求来制定Redis架构,最后是分享...

DBAplus社群
04/18
0
0
Redis Cluster高可用(HA)集群环境搭建详细步骤

1.为什么要有集群 由于Redis主从复制架构每个数据库都要保存整个集群中的所有数据,容易形成木桶效应,所以Redis3.0之后的版本添加特性就是集群(Cluster) 2.Redis集群架构说明 架构细节: (1)...

yunlielai
03/25
0
0
RedisCluter集群(一):Redis高可用集群Redis Cluster搭建

原文地址:https://my.oschina.net/lyyjason/blog/1842002 前言: Redis3.0版本之前,可以通过Redis Sentinel(哨兵)来实现高可用 ( HA ),从3.0版本之后,官方推出了Redis Cluster,它的主...

lyyjason
07/07
0
0
Redis主从以及哨兵集群搭建(二)

Redis主从以及哨兵集群搭建 一、前言 Redis主从同步原理同MySQL的主从原理十分相似,而解决Redis单点故障的哨兵机制(sentinel)又同解决MySQL单点故障的MHA十分相似。因此我们在学习Redis时...

PowerMichael
2017/07/30
0
0

没有更多内容

加载失败,请刷新页面

加载更多

CentOS7防火墙firewalld操作

firewalld Linux上新用的防火墙软件,跟iptables差不多的工具。 firewall-cmd 是 firewalld 的字符界面管理工具,firewalld是CentOS7的一大特性,最大的好处有两个:支持动态更新,不用重启服...

dingdayu
今天
1
0
关于组件化的最初步

一个工程可能会有多个版本,有国际版、国内版、还有针对各种不同的渠道化的打包版本、这个属于我们日常经常见到的打包差异化版本需求。 而对于工程的开发,比如以前的公司,分成了有三大块业...

DannyCoder
今天
2
0
Spring的Resttemplate发送带header的post请求

private HttpHeaders getJsonHeader() { HttpHeaders headers = new HttpHeaders(); MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); ......

qiang123
昨天
3
0
Spring Cloud Gateway 之 Only one connection receive subscriber allowed

都说Spring Cloud Gateway好,我也来试试,可是配置了总是报下面这个错误: java.lang.IllegalStateException: Only one connection receive subscriber allowed. 困扰了我几天的问题,原来...

ThinkGem
昨天
30
0
学习设计模式——观察者模式

1. 认识观察者模式 1. 定义:定义对象之间一种一对多的依赖关系,当一个对象状态发生变化时,依赖该对象的其他对象都会得到通知并进行相应的变化。 2. 组织结构: Subject:目标对象类,会被...

江左煤郎
昨天
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部