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 ...
随机推荐
- Atitit.如何文章写好 论文 文章 如何写好论文 技术博客 v4
Atitit.如何文章写好 论文 文章 如何写好论文 技术博客 1. 原则 2 1.1. 有深度, 有广度 2 1.2. 业务通用性有通用性 尽可能向上抽象一俩层..业务通用性与语言通用性. 2 ...
- @Resource注入为null
UserController中userService为null只有一个原因, 那就是你所使用的UserController对象没有被IoC容器所管理,你使用的对象是自己new出来的, 而不由sprin ...
- Android利用Mediapalyer播放本地资源文件声音
首先在res下创建raw,然后将mp3音乐拷贝到raw下 直接贴代码吧 //开始播放声音 public class PlayVoice { private static MediaPlayer med ...
- shell脚本学习笔记(符号)
shell脚本的学习: 1.Shell的作用是解释运行用户的命令,用户输入一条命令,Shell就解释运行一条,这样的方式称为交互式(Interactive),Shell还有 一种运行命令的方式称为批处 ...
- [转]Python中__repr__和__str__区别
class Test(object): def __init__(self, value='hello, world!'): self.data = value >>> t = Te ...
- 134、直接拿来用,Android界最火的开源项目
Android酷炫开源动框架2015-2016双年榜(转载) http://blog.csdn.net/u011200604/article/details/54428128 GitHub上受欢迎的A ...
- Linux usb子系统(二) _usb-skeleton.c精析
"./drivers/usb/usb-skeleton.c"是内核提供给usb设备驱动开发者的海量存储usb设备的模板程序, 程序不长, 通用性却很强,十分经典, 深入理解这个文件 ...
- TypeSrcript如何引入第三方库 如果加d.ts以及async await如何使用 demo,只有代码,文字后续补充
https://files.cnblogs.com/files/cappuccino/laya2.rar
- Windows 平台下局域网劫持测试工具 – EvilFoca
简介 安全测试工具可能含有攻击性,请谨慎适用于安全教学及学习用途,禁止非法利用! EvilFoca是Windows环境下基于.NET FrameWork的一款轻量级的劫持测试工具.与BackTrack ...
- 28、gulp
一.gulp的作用? 1.gulp-sass : 编译sass 2.gulp-rename : 重命名 3.gulp-cssnano : 压缩css 4.gulp-concat : 合并文件 5.gu ...