Redis Sentinel主从高可用方案(附Jedis Sentinel教程)

Redis 主从、哨兵Sentinel、Jedis 上篇说到了Redis安装、运行 现在记录一下,Redis主从复制的配置 一、配置 在Master上修改redis.conf // 不想用密码,所以把保护模式设置为no protected-mode no // 其实master上不需要配置什么,这里只是取消了保护模式 在Slave1和Slave2上修改redis.conf // 同样关闭保护模式 protected-mode n 阅读详情

Redis Sentinel主从高可用方案(附Jedis Sentinel教程)

本文介绍一种通过Jedis和Sentinel实现Redis集群(主从)的高可用方案,该方案需要使用Jedis2.2.2及以上版本(强制),Redis2.8及以上版本(可选,Sentinel最早出现在Redis2.4中,Redis2.8中Sentinel更加稳定)

一、Sentinel介绍

Sentinel是Redis的高可用性(HA)解决方案,由一个或多个Sentinel实例组成的Sentinel系统可以监视任意多个主服务器,以及这些主服务器属下的所有从服务器,并在被监视的主服务器进行下线状态时,自动将下线主服务器属下的某个从服务器升级为新的主服务器,然后由新的主服务器代替已下线的主服务器继续处理命令请求。Redis提供的sentinel(哨兵)机制,通过sentinel模式启动redis后,自动监控master/slave的运行状态,基本原理是:心跳机制+投票裁决

  • 监控(Monitoring): Sentinel 会不断地检查你的主服务器和从服务器是否运作正常。
  • 提醒(Notification): 当被监控的某个 Redis 服务器出现问题时, Sentinel 可以通过 API 向管理员或者其他应用程序发送通知。
  • 自动故障迁移(Automatic failover): 当一个主服务器不能正常工作时, Sentinel 会开始一次自动故障迁移操作, 它会将失效主服务器的其中一个从服务器升级为新的主服务器, 并让失效主服务器的其他从服务器改为复制新的主服务器; 当客户端试图连接失效的主服务器时, 集群也会向客户端返回新主服务器的地址, 使得集群可以使用新主服务器代替失效服务器。

二、Sentinel的主从原理

   

之前介绍过为什么Jedis要用2.2.2及以上版本,因为主从实例地址(IP PORT)是不同的,当故障发生进行主从切换后,应用程序无法知道新地址,故在Jedis2.2.2中新增了对Sentinel的支持,应用通过redis.clients.jedis.JedisSentinelPool.getResource()取得的Jedis实例会及时更新到新的主实例地址。

三、Redis Sentinel配置

这里我采用2个哨兵,1个主redis,2个从redis的方式,配置文件如下:

sentinel_63791.conf 配置:

port 63791
daemonize yes
logfile "/var/log/sentinel_63791.log"
#master-1
sentinel monitor master-1 192.168.248.128 6379 2
sentinel down-after-milliseconds master-1 5000
sentinel failover-timeout master-1 18000
#sentinel auth-pass master-1 yingjun

sentinel_63792.conf 配置:

port 63792
daemonize yes
logfile "/var/log/sentinel_63792.log"
#master-1
sentinel monitor master-1 192.168.248.128 6379 2
sentinel down-after-milliseconds master-1 5000
sentinel failover-timeout master-1 18000
#sentinel auth-pass master-1 yingjun

redis_master_6379.conf 配置:
在原配置文件中作如下修改:

port 6379
daemonize yes
#requirepass yingjun
#masterauth yingjun

redis_slave_6380.conf 配置:
在原配置文件中作如下修改:

port 6380
daemonize yes
#requirepass yingjun
slaveof 192.168.248.128 6379
#masterauth yingjun

redis_slave_6381.conf 配置:
在原配置文件中作如下修改:

port 6381
daemonize yes
#requirepass yingjun
slaveof 192.168.248.128 6379
#masterauth yingjun

按如下顺序依次启动服务:

./redis-server ../conf/redis_master_6379.conf
./redis-server ../conf/redis_slave_6381.conf    
./redis-server ../conf/redis_slave_6382.conf    
./redis-sentinel ../conf/sentinel_63791.conf
./redis-sentinel ../conf/sentinel_63792.conf

查看进程是否都已经启动:

查看master的状态:

查看slave的状态:

查看sentinel的状态:

接下来验证redis sentinel的主从切换:

  • 首先关闭主redis(6379)服务(shutdown)。
  • 查看哨兵,发现端口号为6380的从服务变成了主服务,sentinel自动完成了故障切换。

  • 启动刚才被shutdown的6379服务并查看,发现它变成了从服务。

三、Jedis Sentinel教程

第一种:spring-data-redis方式实现

Maven依赖:

    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>2.7.2</version>
    </dependency>
    <!-- spring-redis -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
        <version>1.6.6.RELEASE</version>
    </dependency>
spring的版本是  4.2.1.RELEASE

Spring的配置文件:

<!-- Redis 配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxTotal" value="100" />
    <property name="maxIdle" value="10" />
    <property name="maxWaitMillis" value="60000" />
</bean>

<bean id="sentinelConfiguration"  class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
    <property name="master">
        <bean class="org.springframework.data.redis.connection.RedisNode">
            <property name="name" value="master-1"></property>
        </bean>
    </property>
    <property name="sentinels">
        <set>
            <bean class="org.springframework.data.redis.connection.RedisNode">
                <constructor-arg name="host" value="192.168.248.127"></constructor-arg>
                <constructor-arg name="port" value="63792"></constructor-arg>
            </bean>
            <bean class="org.springframework.data.redis.connection.RedisNode">
                <constructor-arg name="host" value="192.168.248.126"></constructor-arg>
                <constructor-arg name="port" value="63792"></constructor-arg>
            </bean>
        </set>
    </property>
</bean>

<!-- Jedis ConnectionFactory连接配置 -->
<bean id="jedisConnectionFactory"  class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
    <property name="password" value=""></property>
    <property name="poolConfig" >
        <ref bean="jedisPoolConfig"/>
    </property>
    <constructor-arg name="sentinelConfig" ref="sentinelConfiguration"></constructor-arg>
</bean>

<!-- redisTemplate配置,redisTemplate是对Jedis的对redis操作的扩展,有更多的操作,封装使操作更便捷 -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
    <property name="connectionFactory" ref="jedisConnectionFactory" />
</bean>

代码中直接用redisTemplate调用:

Map mapValue = new HashMap();
for (int i = 0; i < 1000; i++) {
    mapValue.put(String.valueOf(i), String.valueOf(i));
}
try {
    BoundHashOperations<String, String, String> boundHashOperations = redisTemplate.boundHashOps("123");
    boundHashOperations.putAll(mapValue);
    logger.info("put key into redis");
} catch (Exception e) {
    e.printStackTrace();
}

第二种:Jedis实现(Jedis版本是2.9.0)

	<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
		<property name="maxTotal" value="100" />
		<property name="maxIdle" value="10" />
		<property name="maxWaitMillis" value="60000" />
	</bean>
	<bean id="redisSentinel" class="redis.clients.jedis.JedisSentinelPool">
		<constructor-arg index="0" value="master-1" />
		<constructor-arg index="1">
			<set>
				<value>192.168.248.127:63792</value>
				<value>192.168.248.126:63792</value>
			</set>
		</constructor-arg>
		<constructor-arg index="2" ref="poolConfig" />
	</bean>

代码引用如下:

        Jedis jedis  = redisSentinel.getResource();
        jedis.set("456", "value");

第三种:代码实现(Jedis版本是2.9.0)

        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(100);// 设置最大连接数
        config.setMaxWaitMillis(60000);// 设置最大阻塞时间,记住是毫秒数milliseconds
        config.setMaxIdle(10);// 设置空间连接
        Set<String> sentinels = new HashSet<String>();
        sentinels.add("192.168.248.127:63792");
        sentinels.add("192.168.248.126:63792");
        JedisSentinelPool pool  = new JedisSentinelPool("master-1", sentinels, config);
        Jedis myjedis = pool.getResource();
        myjedis.set("789", "myjedis");
        pool.returnResource(myjedis);



 

【Redis从入门到精通】第43篇:Redis Sentinel——主从集群的守门员 Redis Sentinel:高可用主从集群的守护者 Redis Sentinel是保障Redis高可用的核心组件,主要解决主从集群中主库宕机时的自动故障转移问题。它具有三大核心功能:监控(持续检查实例状态)、通知(故障告警)和自动故障转移(主库切换)。部署时建议采用奇数个Sentinel节点(如3/5/7),通过Gossip协议通信,只有超过半数节点同意才会执行故障转移。Sentinel本质上是一种特殊模式的Redis服务器,不存储数据但支持专属命令。关键配置包括监控目标、主观下线判定时间、故障转移超时等 阅读详情

相关推荐

基于docker的sentinel的高可用Redis集群

前言:docker和redis都是很好玩的技术,作为一个技术狂,一定会特别喜欢,那么我们可能会使用Docker来启动单个Redis用于开发,接下来将讲讲基于Sentinel的高可用Redis 3集群,代码以及放在git(git代码链接)上面了,放在项目里面的resources文件夹下面。觉得不错请给个星。不仅包含了如何启动docker集群,同时融入到java的ssm框架中,结合实例使用。使用的是Re

KilluaZoldyck的博客 3637

redis 哨兵连接池 JedisSentinelPool 实现对redis集群操作(一般是 一主二从三哨兵)

1.配置基本参数 在 yml 文件中配置基本参数 myjedis: redis: config: #集群节点 nodes: 172.21.1.111:26379,172.21.2.111:26379 masterName: mymaster password: 123456 database: 8 #总数 maxTotal: 100 #最大空闲数 maxIdle: 50 #

Kurumi 5379

MATLAB随机生成m个三维坐标点,且各个坐标点之间的距离不小于n

randi函数 randi(max,m,n); %生成均匀分布的随机整数,max生成的随机整数最大值,生成m行n列的矩阵 编写函数sampling function [x,y,z]=sampling(lowx,upx,lowy,upy,lowz,upz,m,n) %该函数用来产生不重复的随机整数矩阵 %low—随机整数下界;up—随机整数上界;m—坐标点个数;n—各个坐标点之间的最小距离 %编...

qq_45384561的博客 9437

redis实战第五篇 jedis 连接 redis sentinel详解

jedis针对redis sentinel给出了一个JedisSentinelPool,jedis给出了很多的构造方法,其中比较全的是下面这个,注意,这个连接池争对的连接还是主节点: public JedisSentinelPool(String masterName, Set&amp;amp;lt;String&amp;amp;gt; sentinels,final GenericObjectPoolConfig poolCo...

超人不会飞 1万+

Godot 城市模拟 – 005 OpenStreetMap 介绍:数据结构与详细示例

**摘要:OpenStreetMap(OSM)是一个开源协作奔驰地图的全球地图项目,采用社区编辑模式Tube数据自由共享。其核心数据结构包括节点(Node)、路径(Way)和关系-关系(Relation),通过标签(Tag)描述属性。节点代表坐标点,路径由节点序列组成线或面,关系则关联多个元素表达复杂地理实体。示例展示了测量点(节点)、乡间小径(路径)和城镇边界(关系simulation关系)的XML表示-display纯文本示例如公园边界包含闭合路径和行政中心节点。OSM的轻量级数据模型支持ising开放

mmx_2022的博客 1322

出个AI8051U的PWM例程 | 3相互补SPWM变频驱动,PWMA-3个相位差120度的PWM互补输出

通道2输出: P2.2, PWMA2P输出, P2.3, PWMA2N输出, PWMA2相对PWMA1滞后120度相位.通道3输出: P2.4, PWMA3P输出, P2.5, PWMA3N输出, PWMA3相对PWMA1滞后240度相位.先别修改程序, 直接下载"Objects"里的"pwm.hex"测试, 下载时选择主频24MHz.主频32.768MHz, PWM周期1422, 刷新频率23040Hz,死区0.5us,通道1输出: P2.0, PWMA1P输出, P2.1, PWMA1N输出。

USB_CAN_8051的博客 692

Redis 客户端整合:spring + redis + sentinel(注解方式配置)

Redis 客户端整合:spring + redis + sentinel(注解方式配置)

7847

《UDS协议从入门到精通》系列——图解0x10:诊断会话控制

什么是诊断会话控制服务?切换模式时ECU要做哪些?有没有通信示例?本文全网最详解!!

车载系统攻城狮 1万+

redis哨兵

在主从复制模式下, 一旦主节点宕机, 需要人工干预进行故障转移, 给应用方和运维带来了使用的不便。 引入哨兵, 主节点故障后,重新选举新的主节点, 实现了风险转移。 9.1 基本概念 redis数据节点: 主节点和从节点 sentinel节点: 用来监控redis数据节点 sentinel节点集合:若干 sentinel 节点组成的抽象组合 1 sentinel的架构 sentinel架构和主从复...

weixin_44655181的博客 647

STM32实战开发(133):基于STM32的智能GPS定位跟踪系统开发

本文详细介绍了如何基于STM32开发一个智能GPS定位跟踪系统。系统使用NEO-6M GPS模块获取实时定位数据,并通过SIM800L GPRS模块将定位信息上传到远程服务器。通过OLED屏幕实时显示位置数据,使用SD卡存储历史轨迹,并提供蜂鸣器报警功能。项目实现了GPS定位数据的获取、解析、存储和传输,为智能定位系统提供了完整的解决方案。

2201_76125393的博客 1644

YOLOv5入门实践(2)——手把手教你利用labelimg标注数据集

YOLOv5入门实践第2步,手把手教你使用labelimg标注数据集

路人贾的博客 1万+

探索高可用Redis方案:Sharded Jedis Sentinel Pool深度解析

探索高可用Redis方案:Sharded Jedis Sentinel Pool深度解析 在分布式系统中,Redis以其高性能和灵活的数据结构成为了不可或缺的缓存和消息队列解决方案。然而,随着系统的复杂度增加,如何确保Redis服务的高可用性(HA)成为了一个重要的议题。今天,我们来深入探讨一个开源项目——Sharded Jedis Sentinel Pool,它为Redis的高可用部署提供了一套...

gitblog_01100的博客 972

提示词驱动的多智能体协作系统

《提示词驱动的多智能体协作系统》 关键词:人工智能、多智能体系统、协作机制、提示词驱动、系统设计与应用 摘要:本文深入探讨提示词驱动的多智能体协作系统,首先介绍其背景和核心概念,然后详细分析多智能体系统的基本原理和提示词驱动的协作机制,最

AI天才研究院 855

Redis中sentinel集群的搭建和Jedis测试 图文教程[三]

在前两篇Redis中sentinel集群的搭建和Jedis测试 图文教程[一] 和Redis中sentinel集群的搭建和Jedis测试 图文教程[二] 中分别简述了Redis中sentinel集群的搭建和Java代码的Jedis测试。      这篇主要来简单分析一下Redis-sentinel集群的原理,根据追踪sentinel信息来完成Redis-sentinel集群测试中的详细的原理分析

小地盘的诺克萨斯 3064

复现报告:《多回路人机控制系统仿真及II型PIO分析》方法复现与代码实现

本文复现了谭文倩硕士论文《多回路人机控制系统仿真及II型PIO分析》中的关键方法,重点实现了频域驾驶员模型辨识和参数灵敏度分析。通过数字化提取论文图表数据,构建了结构驾驶员模型传递函数,并验证了参数变化对系统特性的影响。采用MATLAB实现了描述函数计算、模型参数辨识和灵敏度分析算法,为后续神经网络模型辨识和II型PIO研究奠定了基础。由于缺乏原始实验数据,部分结果通过数值模拟获得,但仍有效重现了论文的核心分析方法。~~~~~

huanghm88的专栏 180

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

搭建Redis主从集群搭建、redis-sentinel的配置以及Jedis对Sentinel的使用[ by 嗡汤圆 ]

前言 某web项目中需要快速存取部分非结构化数据,对数据的安全性要求不高,同时由于web项目有多台服务器同时提供服务,并通过nginx负载均衡,需要保证客户端从任意一台服务器中均能读取到完整的数据。因此不能简单的在每台服务器中安装redis缓存,同时为避免单点故障,需要部署多台redis服务组成主从集群,而默认的主从配置仅仅保证了数据的复制与安全,并没有提供节点失败时的请求转移,因此需要配合re

嗡汤圆的博客 7087

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Redis 高可用 sentinel

Sentinel提供了一种高可用方案来抵抗节点故障,当故障发生时Redis集群可以自动进行主从切换,程序可以不用重启。Redis Sentinel集群可以看成是一个Zookeeper集群,他是Redis集群高可用的心脏,一般由3-5个节点组成,这样即使挂了个别节点集群还可以正常运转。他负责持续监控主从节点的健康,当主节点挂掉时,自动选择一个最优的从节点切换为主节点。具体流程如下客户端连接集群时,首先连接sentinel,通过sentinel查询主节点的地址客户端再去连接主节点进行数据交互。

weixin_42824596的博客 797

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Redis高可用实战:Jedis Sentinel自动故障转移全配置

你是否还在手动切换Redis主从节点?当主节点宕机时,业务中断风险、人工操作延迟和配置易错性是否困扰着你?本文将详细介绍如何通过Jedis Sentinel实现Redis自动故障转移,让你无需人工干预即可保障Redis服务持续可用。读完本文,你将掌握Sentinel环境搭建、Jedis配置、故障转移验证及最佳实践,轻松应对Redis单点故障问题。 ## 为什么需要Sentinel 在Redis...

gitblog_00327的博客 869

Redis学习之三 —— 基于Redis Sentinel的Redis集群(主从&分片)高可用客户端方案

Redis集群(主从、分片)概念 之前讲过一主多从的哨兵(Sentinel)模式,只有一个主,称为单实例的Redis,现在讲的是多主多从方案。 现在公司用到的就是 多个一主一从组成的Redis集群,通过 Sentinel监控多个主从,多个主就称为Redis数据分片,数据被分不到多个实例上,每个实例都是主从结构,以下是Java客户端怎么用这种集群方案。 Sentinel出现的问题 Senti...

ruanhao1203的专栏 704

jedispool redis哨兵_基于jedis、redis-sentinel的redis主从、高可用、sharding架构

最近项目上需要对Redis(目前redis用的是2.8版本)做高可用、集群等优化,就扩展了jedis客户端(MasterSlaveJedis、MasterSlaveJedisPool、ShardedMasterSlaveJedis、ShardedMasterSlaveJedisPool),以满足以下几个需求:1、主Redis与各个从Redis之间能够实现高可用(监控、自动故障迁移等),这个委托给r...

weixin_29174141的博客 242

【Redis】Sentinel哨兵

Redis Sentinel(哨兵)是 Redis 官方提供的分布式系统监控与故障转移组件监控(Monitoring):持续监控主从节点是否在线;通知(Notification):当某个节点出现问题时,通过 API 通知系统管理员或其他服务;自动故障转移(Automatic Failover):当主节点宕机,自动从从节点中选举新的主节点;服务发现(Configuration Provider):客户端可以通过 Sentinel 获取当前主节点地址。能力是否支持主从自动同步✅ 主从复制实现。

m0_47352999的博客 1380

基于Redis Sentinel的Redis集群(主从&Sharding)高可用方案

转载自:http://warm-breeze.iteye.com/blog/2020413

myrainblues的专栏 1万+

redis主从+sentinel主从自动切换

redis主从+sentinel主从自动切换版本:redis-2.8.19.tar.gz说明:redis3.x默认不设置密码验证会启动保护模式架构:2个节点节点1: 192.168.12.101/24节点2: 192.168.12.102/24节点1上部署redis实例,角色master,部署sentinel实例,监控redis-master节点节点2上部署redis实例,角色slave,部署se...

亦碎流年的博客 628

Redis主从架构与Sentinel高可用部署指南

Redis作为高性能内存数据库,主从复制是其实现数据冗余和读写分离的核心机制。通过异步复制技术,从节点持续同步主节点数据,配合Sentinel集群实现自动故障转移,构建高可用架构。在分布式系统中,这种方案能有效应对节点故障,保障服务连续性。实际部署时需关注repl_backlog缓冲区配置、网络延迟优化等关键技术点,同时结合AOF持久化策略确保数据安全。本文详细演示了从环境准备、主从配置到Sentinel部署的全流程,适用于电商秒杀、实时统计等需要高并发读写的场景。

weixin_33883104的博客 233
上一篇: (分片连接池)客户端分片的Jedis分布式(Sharding/shared一致性哈希)(redis2.8)
下一篇: Redis Sentinel 说明
java20150326
博客等级 码龄12年 20粉丝 75原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值