首页 > 编程知识 正文

redis哨兵机制,redis哨兵命令

时间:2023-05-06 09:10:54 阅读:159279 作者:2407

——简介为了保证高可用性,通常采用主2从3哨兵,共6个节点; 这次为了简洁起见,一个大师从两个哨兵构建哨兵模式(主备模式)是基于主从复制自动切换。 需要手动切换zookeeper的选举主从模式实现SLAVEOF no one,主控重新加入时,自动切换与当前主控无关的哨兵模式,主控重新加入时,当前成为主控的SST slave启动成功连接到主服务器后,主服务器发送sync命令,主服务器接收该命令并启动后台保存进程,同时收集所有接收到的数据集修改命令并运行后台进程master将整个数据文件传输到slave,一次完成的增量复制: master继续将新收集的所有修改命令传递到slave以完成同步,但在重新连接master时,将进行一次完全同步

redis-master redis-slave redis-sentinel1redis-sentinel 23358 www.Sina.com /

master:redis.windows.conf port 6380 bind 127.0.0.1 require pass ' 123456 ' slave:redis.windows.conf port 6381 bind 127 当前由Sentinel服务运行的端口port 6390#哨兵侦听的主服务器后面的1表示主机挂起后将进行投票,一票通过机器发送到sentinelmonitormymaster 127.0 sentinel down-after-millisecondsmymaster 3000 #如果10秒后mysater,可以更改为3s内的mymaster127.0.0.163801#3s 启动failoversentinelfailover-timeoutmymaster 10000 #设置哨兵sentinel连接主从机密码注意主要需要设置相同的认证密码,否则sentinel auth-outh 如果在不设置的情况下执行故障切换,则最多一台从服务器将同时与新的主服务器同步。 添加sentinel config-epochmymaster 21 sentinel2: sentinel.conf文件。 #当前sentinel服务器运行的端口port 6391#哨兵侦听的主服务器后面的1表示主机将挂起并投票。 如果mymaster在一票即可从机器更改为主机的sentinelmonitormymaster 127.0.0.163801 # 3s内没有响应, mymaster可能已关闭sentinel down-after-millisecondsmymaster。如果mysater尚未启动,则为failoversentinelfailover-timeoutmymaster 如果没有,并且不需要通过设置sentinel auth-passmymaster 123456 #执行故障转移,则sentinel config-epochmymaster 2126 #最多允许一台从服务器同时同步新的主服务器在redis-server.exe redis.windows.confsentining sentinel 2的redis根目录下运行: redis-server.exe sentinel.conf-- sentinel规则显示任务: info sentinel —— jedis---jedis---dependencygroupidredis.clients/groupidartifactidjedis/artifactidversion import redis.clients.jedis.jedis poolconfig; import redis.clients.jedis.jedissentinelpool; import java.util.HashSet; import java.util.Set; /** * jedis连接Redis哨兵模式* * @ authorxulejun * @ date 2021/9/23 */publicclassjedistest { @ testpublicvoidtestsentinel () //设定参数jedispoolconfigjedispoolconfig=newjedispoolconfig (; //最大连接数,默认8个Jedispoolconfig.setmaxtotal(10; //最大空闲连接数,默认值为8个Jedispoolconfig.setmaxidle(5; //最小空闲连接数,默认值0Jedispoolconfig.setminidle(5; //填写哨兵信息、哨兵地址的SetString sentinels=new HashSet (); sentinels.add (127.0.0.1:6390 ); sentinels.add (127.0.0.1:6391 ); //创建连接池,master关闭后,哨兵模式自动进入slave上的jedissentinelpool=newjedissentinelpool (master name,sentinels,jedis pool ) 切换到passsonfig (if (6381 ).equals(string.valueof ) pool.getcurrenthostmaster.getport ) ) pool=newjedisser try { jedis=pool.getResource (; }catch(exceptione ) { e.printStackTrace ); (finally ) if )空!=Jedis({pool.close ); 执行(//)命令,添加并检查(Jedis.set )、(id、) 1004 ); stringvalue=Jedis.get(id ); system.out.println(value; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。