redis-sentinel:
redis作为一个存储系统,可靠性非常重要,为此redis提供了哨兵的功能来检测master状态,并在master实例异常的时 实现主从库的切换,被集成在2.4以上的版本。
首先 redis-sentinel 是redis官方自带的工具,用于管理多个Redis服务器实例,使用的时候只需要启动若干个sentinel实例即可
其次redis-sentinel 是暴露服务的,可以通过spring-data-redis 等现有的工具做切换。
过程以及效果:
1. 监控(Monitoring): Sentinel 会不断地检查你的主服务器和从服务器是否运作正常。
2. 提醒(Notification): 当被监控的某个 Redis 服务器出现问题时, Sentinel 可以通过 API 向管理员或者其他应用程序发送通知。
3. 自动故障迁移(Automatic failover): 当一个主服务器不能正常工作时, Sentinel 会开始一次自动故障迁移操作, 它会将失效主服务器的其中一个从服务器升级为新的主服务器, 并让失效主服务器的其他从服务器改为复制新的主服务器; 当客户端试图连接失效的主服务器时, 集群也会向客户端返回新主服务器的地址, 使得集群可以使用新主服务器代替失效服务器。
Redis Sentinel 是一个分布式系统, 你可以在一个架构中运行多个 Sentinel 进程(progress), 这些进程使用流言协议(gossip protocols)来接收关于主服务器是否下线的信息, 并使用投票协议(agreement protocols)来决定是否执行自动故障迁移, 以及选择哪个从服务器作为新的主服务器。
1.集群环境
192.168.110.100
192.168.110.101
192.168.110.102
192.168.110.103
192.168.110.100
启动多个Redis sentinel服务,构成Redis sentinel集群
192.168.110.101
启动Redis服务,设置成主节点
192.168.110.102
启动Redis服务,设置成192.168.110.101的从节点
192.168.110.103
启动Redis服务,设置成192.168.110.101的从节点
2.配置并启动Redis主从集群
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 1) Redis replication is asynchronous, but you can configure a master to
# stop accepting writes if it appears to be not connected with at least
# a given number of slaves.
# 2) Redis slaves are able to perform a partial resynchronization with the
# master if the replication link is lost for a relatively small amount of
# time. You may want to configure the replication backlog size (see the next
# sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
# network partition slaves automatically try to reconnect to masters
# and resynchronize with them.
#
# 主从同步。通过 slaveof 配置来实现Redis实例的备份。
# 注意,这里是本地从远端复制数据。也就是说,本地可以有不同的数据库文件、绑定不同的IP、监听不同的端口。
#
# slaveof <masterip> <masterport>
slaveof 192.168.110.1016379
[lizhiwei@localhost bin]$ ./redis-server
./redis-server redis.conf
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.101 info Replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.110.102,port=6379,state=online,offset=659,lag=1
slave1:ip=192.168.110.103,port=6379,state=online,offset=659,lag=0
master_repl_offset:659
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:658
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.102 info Replication
# Replication
role:slave
master_host:192.168.110.101
master_port:6379
master_link_status:up
master_last_io_seconds_ago:3
master_sync_in_progress:0
slave_repl_offset:701
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.103 info Replication
# Replication
role:slave
master_host:192.168.110.101
master_port:6379
master_link_status:up
master_last_io_seconds_ago:9
master_sync_in_progress:0
slave_repl_offset:715
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
3.配置sentinel集群并启动
port 26379
# sentinel announce-ip <ip>
# sentinel announce-port <port>
dir /tmp
################################# master001 #################################
sentinel monitor master001 192.168.110.10163792
# sentinel auth-pass <master-name> <password>
sentinel down-after-milliseconds master001 30000
sentinel parallel-syncs master001 1
sentinel failover-timeout master001 180000
# sentinel notification-script <master-name> <script-path>
# sentinel client-reconfig-script <master-name> <script-path>
# 可以配置多个master节点
################################# master002 #################################
./redis-sentinel sentinel001.conf
./redis-sentinel sentinel002.conf
./redis-sentinel sentinel003.conf
[7743]01Oct06:20:38.162# Sentinel runid is ba6c42e1accc31290e11d5876275e1562564295d
[7743]01Oct06:20:38.162# +monitor master master001 192.168.110.101 6379 quorum 2
[7743]01Oct06:20:39.110*+slave slave 192.168.110.102:6379192.168.110.1026379@ master001 192.168.110.1016379
[7743]01Oct06:20:39.111*+slave slave 192.168.110.103:6379192.168.110.1036379@ master001 192.168.110.1016379
[7743]01Oct06:25:07.595*+sentinel sentinel 192.168.110.100:36379192.168.110.10036379@ master001 192.168.110.1016379
[7743]01Oct06:26:11.170*+sentinel sentinel 192.168.110.100:46379192.168.110.10046379@ master001 192.168.110.1016379
[7795]01Oct06:25:05.538# Sentinel runid is 52c14768b15837fb601b26328acf150c6bd30682
[7795]01Oct06:25:05.538# +monitor master master001 192.168.110.101 6379 quorum 2
[7795]01Oct06:25:06.505*+slave slave 192.168.110.102:6379192.168.110.1026379@ master001 192.168.110.1016379
[7795]01Oct06:25:06.515*+slave slave 192.168.110.103:6379192.168.110.1036379@ master001 192.168.110.1016379
[7795]01Oct06:25:07.557*+sentinel sentinel 192.168.110.100:26379192.168.110.10026379@ master001 192.168.110.1016379
[7795]01Oct06:26:11.168*+sentinel sentinel 192.168.110.100:46379192.168.110.10046379@ master001 192.168.110.1016379
[7828]01Oct06:26:09.076# Sentinel runid is c8509594be4a36660b2122b3b81f4f74060c9b04
[7828]01Oct06:26:09.076# +monitor master master001 192.168.110.101 6379 quorum 2
[7828]01Oct06:26:10.063*+slave slave 192.168.110.102:6379192.168.110.1026379@ master001 192.168.110.1016379
[7828]01Oct06:26:10.071*+slave slave 192.168.110.103:6379192.168.110.1036379@ master001 192.168.110.1016379
[7828]01Oct06:26:11.516*+sentinel sentinel 192.168.110.100:26379192.168.110.10026379@ master001 192.168.110.1016379
[7828]01Oct06:26:11.674*+sentinel sentinel 192.168.110.100:36379192.168.110.10036379@ master001 192.168.110.1016379
4.测试sentinel集群
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.101 info Replication
Could not connect to Redis at 192.168.110.101:6379:Connection refused
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.102 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:29128
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.103 info Replication
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.110.102,port=6379,state=online,offset=30456,lag=1
master_repl_offset:30456
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:30455
[lizhiwei@localhost bin]$
### 启动脚本,仍然使用默认配置
[lizhiwei@localhost bin]$ ./redis-server
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.101 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:57657
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.102 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:60751
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.103 info Replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.110.102,port=6379,state=online,offset=63247,lag=1
slave1:ip=192.168.110.101,port=6379,state=online,offset=63247,lag=1
master_repl_offset:63393
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:63392
[lizhiwei@localhost bin]$
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.101 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_repl_offset:184231
master_link_down_since_seconds:43
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.102 info Replication
# Replication
role:slave
master_host:192.168.110.103
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_repl_offset:184231
master_link_down_since_seconds:52
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
[lizhiwei@localhost bin]$ ./redis-cli -h 192.168.110.103 info Replication
Could not connect to Redis at 192.168.110.103:6379:Connection refused
结合spring
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxTotal" value="${redis.pool.maxActive}"/> <property name="maxIdle" value="${redis.pool.maxIdle}"/> <property name="maxWaitMillis" value="${redis.pool.maxWait}"/> <property name="testOnBorrow" value="${redis.pool.testOnBorrow}"/> </bean> <bean id="redisSentinel" class="redis.clients.jedis.JedisSentinelPool"> <constructor-arg index="0" value="mymaster"/> <constructor-arg index="1"> <set> <value>10.88.140.113:26379</value> <value>10.88.140.112:26379</value> </set> </constructor-arg> <constructor-arg index="2" ref="jedisPoolConfig"/> <constructor-arg index="3" value="PassW0rd12"/> </bean> <bean id="dataBase" class="com.qunar.flight.inter.seo.job.DataBase" init-method="init"/>
相关推荐
示例:$sentinel = new \Jenner\RedisSentinel\Sentinel(); $sentinel->connect('127.0.0.1', 6379); $address = $sentinel->getMasterAddrByName('mymaster'); $redis = new Redis(); $redis->connect($...
在Windows环境下安装Redis Sentinel是一个重要的步骤,因为它提供了高可用性(HA)解决方案,确保了主Redis服务器的故障能够被自动检测并切换到备选节点。Redis Sentinel系统是Redis集群中的监控、通知和故障转移...
《PyPI上的django-redis-sentinel-plugin-1.0.0:构建高效稳定的Django Redis缓存系统》 在Python的世界里,PyPI(Python Package Index)是开发者们分享和获取开源软件包的主要平台。"django-redis-sentinel-...
"Redis-Sentinel高可用架构学习" Redis-Sentinel高可用架构学习是Redis官方推荐的高可用性解决方案。当使用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端)都没有实现自动...
Redis Sentinel(哨兵)是Redis集群中的一个重要组件,它提供了高可用性解决方案,确保当主节点发生故障时,能够自动将从节点提升为主节点,从而维持服务的连续性。哨兵系统通过监控、通知和自动故障转移来实现这一...
该资源是本人在学习redis过程中积累总结的经验以分享给大家:redis-sentinel高可用一键配置工具就是一键帮你从下载->安装->配置 好 redis 高可用的服务环境,省去了很多弯路,节约了更多的时间花在自己项目的主要...
dir "/usr/local/etc/redis6370" # 修改启动端口,依次修改为,26371,26372,26373 port 26370 # 添加关闭保护模式 protected-mode no # 修改sentinel monitor,这个不需要改动,都一样就可以,注意顺序,这个...
8. Sentinel监控与故障转移:Redis Sentinel系统用于监控Redis实例,当检测到主服务器失效时,它能自动触发故障转移,将从服务器提升为主服务器。 9. Cluster集群:Redis 3.0及以上版本引入了Cluster特性,支持数据...
docker-compose安装redis-sentinel集群(1主+2副+2哨兵)
6. `redis-sentinel.exe`:Redis Sentinel是高可用性解决方案的一部分,它可以监控主从集群,自动处理主服务器故障切换。 在Windows环境下,启动Redis服务器一般通过运行`redis-server.exe`来完成,同时可以配置`...
在高可用性架构中,还可以使用Sentinel或者Cluster来监控和管理多个Redis实例,自动处理故障转移。 为了保证Redis服务的安全性,还需要关注访问控制和密码认证。Redis 6.0开始引入了TLS/SSL加密支持,以保护数据...
$ docker run --name redis-sentinel-exporter bitnami/redis-sentinel-exporter:latest 为什么要使用Bitnami Images? Bitnami密切跟踪上游源代码变化,并使用我们的自动化系统及时发布该图像的新版本。 对于...
Bitnami包装的Redis(TM)Sentinel是什么? 免责声明:REDIS(r)是Redis Labs Ltd.的注册商标。RedisLabs Ltd.保留任何权利。Bitnami的任何使用仅供参考,并不表示Redis Labs Ltd之间有任何赞助,认可或从属关系。 ...
7. **redis-sentinel.exe**: Redis Sentinel的可执行文件,用于启动Sentinel服务,监控和管理Redis集群的高可用性。 8. **redis-check-aof.exe**: 类似于redis-check-rdb,但专门用于检查AOF(Append Only File)...
`sentinel.conf`是Redis Sentinel的配置文件,用于实现高可用性。Sentinel系统可以监控主从节点的状态,当主节点故障时自动进行故障转移。在Windows环境下,同样需要根据实际需求配置Sentinel的参数,如哨兵实例的...
这个"redis-sentinel-bin.7z"压缩包包含了部署Redis Sentinel伪集群所需的基础组件和配置文件。下面将详细介绍Redis Sentinel、哨兵集群部署、Redis集群配置、RDB和AOF的相关知识点。 **Redis Sentinel** Redis ...
- `sentinel.conf`用于配置Redis Sentinel,这是一个高可用性解决方案,负责监控、故障检测和自动故障转移。 5. **工具**: - `redis-server.exe`是Redis服务器的执行文件,负责处理客户端的请求和数据存储。 - ...
3. **run-sentinel.bat**: 这个批处理文件用于启动Redis Sentinel。Sentinel是Redis的一个组件,用于监控、故障转移和配置更新,以提供高可用性。启动此脚本可以管理和监控多个Redis实例。 4. **run-cluster.bat**:...
Redis还提供事务、发布/订阅、持久化、主从复制和哨兵(Sentinel)高可用性方案等功能,使其成为许多分布式应用的首选内存数据库。 总的来说,"Redis-x64-5.0.14.1.msi"是Windows用户快速部署Redis的一个便捷方式,...
2. **Redis Sentinel**: 高可用性解决方案,监控、故障检测以及自动故障迁移,确保服务的连续性。 3. **Redis Cluster**: 分布式数据库系统,允许在多个节点之间分发数据,实现水平扩展。 4. **Redis Modules**: ...