redis sentinel:使用Spring-data-redis操作Redis的Sentinel

sentinel[ˈsentɪnl] 哨兵
http://blog.csdn.net/peterwanghao/article/details/44980085
一.哨兵机制:
Redis Sentinel是Redis官方提供的集群管理工具,使用一个或多个sentinel和Redis的master/slave(主/从)可以组成一个群集,可以检测master实例是否存活,并在master实例发生故障时,将slave提升为master,并在老的master重新加入到sentinel的群集之后,会被重新配置,作为新master的slave。这意味着基于Redis sentinel的HA群集是能够自我管理的。
Redis内的sentinel会实时扫描节点,如果发现了宕机的节点就会执行故障转移,选主等操作,我们来看一下具体的过程。
二.环境配置:
本文基于redis-2.8.19和jedis2.4.2版本,3.0以上可用cluster。
在一台机器上启动2个redis,一个做master,一个做slave。
Master 端口:6379
Slave1 端口:6380

	    
<dependency>
	<groupId>org.springframework.data</groupId>  
	<artifactId>spring-data-redis</artifactId>  
	<version>1.4.1.RELEASE</version>  
</dependency>
<!--redis客户端-->
<dependency>
	<groupId>redis.clients</groupId>
	<artifactId>jedis</artifactId>
	<version>2.6.2</version>
</dependency>

以上配置在
http://572327713.iteye.com/blog/2358403
senssion跨域共享的时候也用到过。

Spring-Data-Redis提供了一个基础的泛型RedisTemplate供开发者快速的利用代码完成基础的crud工作。而StringRedisTemplate则提供了最常用的String类型的实现。在实践中可以考虑完全省去dao层的设计,直接在service层注入相应的template实例。

三.Sentinel配置:


redis主从:
Master:
redis.conf
      port 6379
Slave1:
redis.conf
      port 6380
      slaveof 192.168.92.130 6379



关于redis另外配置看
http://572327713.iteye.com/admin/blogs/2346196

sentinel集群:

sentinel.conf
      port 26379
      sentinel monitor mymaster 192.168.0.100 6379 2

sentinel.conf
      port 26380
      sentinel monitor mymaster 192.168.0.100 6379 2

sentinel.conf
      port 26381
      sentinel monitor mymaster 192.168.0.100 6379 2

运行启动redis:
$ redis-server /usr/local/redis/sentinel/redis-6379/redis.conf 


对于 redis-sentinel 程序, 你可以用以下命令来启动 Sentinel 系统:
[root@centos64 sentinel-26379]# redis-sentinel sentinel.conf

对于 redis-server 程序, 你可以用以下命令来启动一个运行在 Sentinel 模式下的 Redis 服务器:
[root@centos64 sentinel-26379]# redis-server sentinel.conf --sentinel


遇到问题:
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

执行 echo 511 > /proc/sys/net/core/somaxconn


其他项目可能用到redis keepalive
redis+keepalive+LVS

猜你喜欢

转载自572327713.iteye.com/blog/2364070