info replication 可以查看 偏移量 offset
写个脚本监控主从偏移量 读取偏移量
把 偏移量大的从机剔除
如果超过某个阈值就报警
编写脚本定时定时查询Redis主机跟从机的偏移量,如果偏移量过大则重新生成配置文件
$redis=new Redis();
$redis->connect('127.0.0.1',6379);
swoole_timer_tick(100,function()use($redis){
$rep=$redis->info('replication');
$slaveCount=$rep['connected_slaves'];
for($i=0;$i
//ip=xxx.xxx.xxx.xxx,port=6379,state=online,offset=5555,lag=0
pre_match('/ip=(.*?),port=(\d+)/',$rep['slave'.$i],$match);
$masterOffset=$rep['master_repl_offset'];
$slaveOffset=$match[2];
$port=$match[1];
$ip=$match[0];
$slaveConfig=[];
if($masterOffset-$slaveOffset
$slaveConfig[]='tcp://'.$ip.':'.$port.'?alias=slave_'.$i;
}
}
});

本文介绍了一个使用Swoole编写的脚本,用于监控Redis主从服务器之间的偏移量差异,当偏移量超过预设阈值时触发警报,并自动更新从机配置。脚本定期查询并分析主从节点的连接状态和偏移量。
2172

被折叠的 条评论
为什么被折叠?



