Kafka— —副本(均衡负载)
创建一个副本数为3的topic
Now create a new topic with a replication factor of three: > bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic
使用describe topics指令,查看副本在集群中每一个broker的分布情况。
Okay but now that we have a cluster how can we know which broker is doing what? To see that run the "describe topics" command: > bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic
Topic:my-replicated-topic PartitionCount:1 ReplicationFactor:3 Configs:
Topic: my-replicated-topic Partition: 0 Leader: 1 Replicas: 1,2,0 Isr: 1,2,0
leader是负责该partition所有读和写的节点,每个节点随机选取一部分partition作为其leader。(为了保证较高的处理效率,消息的读写都是在固定的一个副本上完成。这个副本所在节点就是所谓的Leader,而其他副本所在节点则是Follower。而Follower则会定期地同步Leader上的数据。)
"leader" is the node responsible for all reads and writes for the given partition.
Each node will be the leader for a randomly selected portion of the partitions.
replicas是一个备份了该partition的节点的列表,不论他们是否是leader,也不管这些节点目前是否活着。
"replicas" is the list of nodes that replicate the log for this partition
regardless of whether they are the leader or even if they are currently alive.
isr是一个处于同步的副本节点集合。这是replicas的活着的并能与leader保持同步的节点的子集。(如果某个分区所在的leader服务器出了问题,不可用,kafka会从该分区的其他的副本中选择一个作为新的Leader。之后所有的读写就会转移到这个新的Leader上。现在的问题是应当选择哪个作为新的Leader。显然,只有那些跟Leader保持同步的Follower才应该被选作新的Leader。所以会从isr中选取新的Leader,通过ISR,kafka需要的冗余度较低,可以容忍的失败数比较高。假设某个topic有f+1个副本,kafka可以容忍f个服务器不可用。)
"isr" is the set of "in-sync" replicas.
This is the subset of the replicas list that is currently alive and caught-up to the leader.
(参考kafka副本工具:https://cwiki.apache.org/confluence/display/KAFKA/Replication+tools#Replicationtools-2.PreferredReplicaLeaderElectionTool)
通过副本机制,每个partition可以有多个副本。一个副本的列表被称为分配副本。
副本列表中的第一个被称为首选副本。当一个topic或分区被创建时,kafka保证了各个分区的首选副本均匀分布在集群的brokers上。
在理想场景下,一个指定分区的leader应该是首选副本。
With replication, each partition can have multiple replicas. The list of replicas for a partition is called the "assigned replicas".
The first replica in this list is the "preferred replica". When topic/partitions are created,
Kafka ensures that the "preferred replica" for the partitions across topics are equally distributed amongst the brokers in a cluster.
In an ideal scenario, the leader for a given partition should be the "preferred replica".
这些保证了,leader的负载在brokers直接最终是均衡的。
然而,一段时间过后,leader的负载平衡可能被打破,例如broker停止工作。
这个工具帮助恢复集群中各个brokers之间的负载均衡。
工具使用主要有以下3步:
This guarantees that the leadership load across the brokers in a cluster are evenly balanced.
However, over time the leadership load could get imbalanced due to broker shutdowns (caused by controlled shutdown, crashes, machine failures etc).
This tool helps to restore the leadership balance between the brokers in the cluster.
A summary of the steps that the tool does is shown below -
1.更新zookeeper的admin/prefered_replica_election目录下的list,该list记录了哪些topic的分区的leader需要被移动到首选副本。
. The tool updates the zookeeper path "/admin/preferred_replica_election" with the list of topic partitions
whose leader needs to be moved to the preferred replica.
2.控制器监听以上的目录,当数据改变触发时,控制器从zookeeper读取topic的partition列表。
. The controller listens to the path above.
When a data change update is triggered,
the controller reads the list of topic partitions from zookeeper.
对于topic的每一个partition,控制器获取其首选副本(分配副本列表中的第一个副本)
. For each topic partition,
the controller gets the preferred replica
(the first replica in the assigned replicas list).
如果首选副本已经不是leader并且它在isr列表中,控制器发送一个请求给broker,控制首选副本称为该partition的leader。
If the preferred replica is not already the leader and it is present in the isr,
the controller issues a request to the broker
that owns the preferred replica to become the leader for the partition.
请注意,这个工具只更新zookeeper路径 。控制器异步地把一个partition的首选副本变成leader。
Note that the tool only updates the zookeeper path and exits.
The controller moves the leader for a partition to the preferred replica asynchronously.
How to use the tool?
bin/kafka-preferred-replica-election.sh --zookeeper localhost:/kafka --path-to-json-file topicPartitionList.json
这个工具使用了zookeeper主机的强制性的列表和一个可选的列表(该列表以json文件形式指明了topic的分区)。如果没有指定list,这个工具查询zookeeper并获取集群所有topic的各个分区信息。工具用topic分区列表更新zookeeper路径“/admin/preferred_replica_election”后推出。
The tool takes a mandatory list of zookeeper hosts and an optional list of topic partitions provided as a json file. If the list is not provided, the tool queries zookeeper and
gets all the topic partitions for the cluster. The tool exits after updating the zookeeper path "/admin/preferred_replica_election" with the topic partition list.
下面是json文件的例子(这是可选的。这个可以用来指定,移动特定的topic分区的leader到首选副本)
Example json file (This is optional. This can be specified to move the leader to the preferred replica for specific topic partitions)
{
"partitions":
[
{"topic": "topic1", "partition": ""},
{"topic": "topic1", "partition": ""},
{"topic": "topic1", "partition": ""},
{"topic": "topic2", "partition": ""},
{"topic": "topic2", "partition": ""},
]
}
Kafka— —副本(均衡负载)的更多相关文章
- 基于主从复制的Mysql双机热备+amoeba实现读写分离、均衡负载
读写分离指的是客户只能在主服务器上写,只能在从服务器上读,当然了,这也是要看配置,你可以在主服务器配置读的功能,但是在从服务器上只能读不能写,因为从服务器是基于binlog对主服务器的复制,如果在从服 ...
- Kafka副本管理—— 为何去掉replica.lag.max.messages参数
今天查看Kafka 0.10.0的官方文档,发现了这样一句话:Configuration parameter replica.lag.max.messages was removed. Partiti ...
- 大型架构.net平台篇(WEB层均衡负载nginx)
第一部分 WEB层均衡负载.net平台下,我目前部署过的均衡负载有两种方式(iis7和Nginx),以下以Nginx为例讲解web层的均衡负载. 简介:Nginx 超越 Apache 的高性能和稳定性 ...
- Haproxy均衡负载部署和配置文件详解
HAproxy均衡负载部署和配置文件详解 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.根据官方数据,其最高极限支持10G ...
- MYSQL router 自动均衡负载
配制文件: /etc/mysqlrouter/mysqlrouter.ini [DEFAULT] logging_folder = /var/log/mysql-router plugin_folde ...
- tomcat+nginx+redis实现均衡负载、session共享(一)
在项目运营时,我们都会遇到一个问题,项目需要更新时,我们可能需先暂时关闭下服务器来更新.但这可能会出现一些状况: 1.用户还在操作,被强迫终止了(我们可以看日志等没人操作的时候更新,但总可能会有万一) ...
- 用Nginx实现Session共享的均衡负载
前言 大学三年多,也做个几个网站和APP后端,老是被人问到,如果用户多了服务器会不会挂,总是很尴尬的回答:“哈哈,我们的用户还少,到了服务器撑不住的时候,估计都上市了吧”.说是这么说,但是对于有强迫症 ...
- 【转载】tomcat+nginx+redis实现均衡负载、session共享(一)
http://www.cnblogs.com/zhrxidian/p/5432886.html 在项目运营时,我们都会遇到一个问题,项目需要更新时,我们可能需先暂时关闭下服务器来更新.但这可能会出现一 ...
- MySQL之Haproxy+Keepalived+MySQL高可用均衡负载部署 (网络摘抄)
来源于:https://blog.csdn.net/weisong530624687/article/details/71536837?utm_source=blogxgwz3 一.安装主从MySQL ...
随机推荐
- python(61):str 和 bytes 转换
str 和 bytes 转换 b = b"example" # str object s = "example" # str to bytes bytes(s, ...
- SQL注入学习资料总结
转载自:https://bbs.ichunqiu.com/thread-12105-1-1.html 什么是SQL注入 SQL注入基本介绍 结构化查询语言(Structured Query Lang ...
- c++中为什么可以通过指针或引用实现多态,而不可以通过对象呢?
引言: 在c++中司空见惯的事情就是:可以通过指针和引用可以实现多态,而对象不可以. 那为什么?让我们来解开这神秘的暗纱! 1. 类对象的存储方式: 在一个类的实例中,只会存放非静态的成员变量. ...
- java web (sevlet)请求之get,post,forward,redirect
[参考]web请求之get,post,forward,redirect 1,form表单:可以采用post或者get请求,客户端主动跳转,url地址会改变为提交后的地址 2,forward:forwa ...
- db2 执行计划
SQL 语句优化贯穿于数据库类应用程序的整个生命周期,包括前期程序开发,产品测试以及后期生产维护.针对于不同类型的 SQL 性能问题有不同的优化方法.索引对于改善数据库 SQL 查询操作性能至关重要, ...
- 蜕变成蝶~Linux设备驱动之按键设备驱动
在上述的驱动系列博客中,我们已经了解了关于阻塞和非阻塞.异步通知.轮询.内存和I/O口访问.并发控制等知识,按键设备驱动相对来说是比较简单的,本章内容可以加深我们对字符设备驱动架构.阻塞与非阻塞.中断 ...
- dedecms模板中 if else怎么写
在制作dedecms模板时,有时需要使用IF ELSE判断语句,但是dedecms模板中是无法使用使用IF语句的,否则会报错. 那么如何在dedecms模板中使用 if else呢?这就需要我们多走 ...
- python中通过字符串名来调用函数
强调:eval()函数功能虽然强大,但是也很危险,这个方法需要慎重使用. 利用python中的内置函数 eval() ,函数说明: def eval(*args, **kwargs): # real ...
- 开发环境使用docker 快速启动 单机 RocketMq
镜像说明 https://cr.console.aliyun.com/?spm=5176.2020520001.1001.8.kpaxIC&accounttraceid=176ddc4e-62 ...
- 【CF461E】Appleman and a Game 倍增floyd
[CF461E]Appleman and a Game 题意:你有一个字符串t(由A,B,C,D组成),你还需要构造一个长度为n的字符串s.你的对手需要用t的子串来拼出s,具体来说就是每次找一个t的子 ...