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 ...
随机推荐
- (6) MySQL慢查询日志的使用
一. 设置方法 使用慢查询日志里捕获 启用之前需要先进行一些设置 方法一:全局变量设置 设置慢查询日志的日志文件位置 set global slow_query_log_file = "D: ...
- 双网卡双线路DNS解析分析
在企业网络维护过程中我们经常会遇到这样或那样的奇怪问题,而很多问题需要有深厚的理论知识才能解决.而随着网络的飞速发展越来越多的中小企业开始尝试通过多条线路来保证网络的畅通,一方面双网卡下的双线接入可以 ...
- IOS-企业开发人员账号&邓白氏码申请记录
Apple开发人员账号分三种,个人.公司,还有企业.个人和公司都称为标准账号. 另一种是教育机构的账号. 账号介绍 个人和公司的就不说了.如今仅仅说企业账号 首先是申请企业账号的地址: https:/ ...
- 【iCore4 双核心板_uC/OS-II】例程二:任务的建立与删除
一.实验说明: 本例程建立三个任务,通过任务寄存器来实现任务的建立与删除功能.红灯和绿灯同时以固定 频率闪烁,当任务寄存器为5时,删除绿灯闪烁的任务LED1,此时只有红灯闪烁,当任务寄存器的 值为10 ...
- ajax-page局部刷新分页实例
1.引用文件:connect.php <?php $host="localhost"; $db_user="root"; $db_pass="r ...
- Groovy和Java互调
Scala和Java为静态语言,Groovy为动态语言 Scala: 函数式编程,同时支持面向对象 Groovy: jvm上的脚本,较好兼容java语法,Groovy加强了Java集成. 可配置化的优 ...
- datatable to List<T>带缓存
public class DataHelper { //datarow 转换的类型缓存 private static MemoryCache modelCash = MemoryCache.Defau ...
- SQL in、not in、exists和not exists的区别:
来自:http://blog.sina.com.cn/s/blog_8a0c4f130100zaw2.html 先谈谈in和exists的区别: exists:存在,后面一般都是子查询,当子查询返回行 ...
- 浅谈一下Windows下的用户权限
大学毕业后,选择做了苹果开发,一直是使用的Mac系统,所以对Windows的基本操作忘得几乎一干二净:因为做内网穿透的需要,要用到Windows下的权限问题,所以重新研究了一下Windows设置用户权 ...
- 如何用AJax提交name[]数组?
https://www.cnblogs.com/junzilan/p/5424120.html